Skip to content

Add markdown-solidity-license lint - #167

Open
cats2101 wants to merge 1 commit into
ethereum:masterfrom
cats2101:solidity-license-cc0-lint
Open

Add markdown-solidity-license lint#167
cats2101 wants to merge 1 commit into
ethereum:masterfrom
cats2101:solidity-license-cc0-lint

Conversation

@cats2101

Copy link
Copy Markdown
Contributor

Closes #11.

Adds a new markdown-solidity-license lint that flags Solidity code blocks
inside an EIP whose SPDX-License-Identifier is not the expected
CC0-1.0. Blocks without an SPDX line aren't reported — only ones that
explicitly pick a license other than the configured one. Other languages
are skipped.

Configurable via language and license; the default lint set is
registered as language: "solidity", license: "CC0-1.0", matching the
license requirement from EIP-1.

Test plan

  • cargo test -p eipw-lint --test lint_markdown_code_block_license (6 tests)
  • cargo test -p eipw-lint (full suite green)
  • cargo fmt --check -p eipw-lint
  • cargo clippy -p eipw-lint --tests (no new warnings)

…ocks

Closes ethereum#11.

Solidity snippets in EIPs that declare an SPDX-License-Identifier must use
CC0-1.0, the same license required for the EIP itself. The new lint visits
each fenced code block whose info string starts with the configured
language and reports any block whose declared SPDX identifier doesn't
match. Blocks without an SPDX line are not flagged.
@cats2101

cats2101 commented May 3, 2026

Copy link
Copy Markdown
Contributor Author

Gentle ping — anything else needed here?

static RE: OnceLock<TextRegex> = OnceLock::new();
RE.get_or_init(|| {
TextRegex::new(
r"(?m)^\s*(?://|#|/\*+|\*)\s*SPDX-License-Identifier\s*:\s*(.+?)\s*(?:\*/)?\s*$",

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it'd be fine to only match on SPDX-License-Identifier (and not worry about being in a comment block). The cases where you wouldn't be in one (a string or SPDX [minus] License [minus] Identifier) are really weird and unlikely to appear in a legitimate proposal.

#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
#[cfg_attr(feature = "schema-version", derive(schemars::JsonSchema))]
pub struct CodeBlockLicense<S> {
pub language: S,

@SamWilsn SamWilsn May 8, 2026

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We shouldn't check the code block language. If someone includes Python or Ruby with a license identifier, it should be flagged too.

use std::sync::OnceLock;

fn spdx_regex() -> &'static TextRegex {
static RE: OnceLock<TextRegex> = OnceLock::new();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have lazy_static as a dependency already, might as well use it. Unless there's a reason not to?

#[cfg_attr(feature = "schema-version", derive(schemars::JsonSchema))]
pub struct CodeBlockLicense<S> {
pub language: S,
pub license: S,

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this support multiple allowed licenses? I don't feel strongly one way or the other, so whatever you like here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Markdown lint to ensure inline solidity with a SPDX-License-Identifier has a license of CC0.

2 participants