Add markdown-solidity-license lint - #167
Conversation
…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.
|
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*$", |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
Should this support multiple allowed licenses? I don't feel strongly one way or the other, so whatever you like here.
Closes #11.
Adds a new
markdown-solidity-licenselint that flags Solidity code blocksinside an EIP whose
SPDX-License-Identifieris not the expectedCC0-1.0. Blocks without an SPDX line aren't reported — only ones thatexplicitly pick a license other than the configured one. Other languages
are skipped.
Configurable via
languageandlicense; the default lint set isregistered as
language: "solidity",license: "CC0-1.0", matching thelicense 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-lintcargo clippy -p eipw-lint --tests(no new warnings)