rust-lang / rust-lang/rust-clippy

Cargo: check license is valid SPDX license expression

Open
#5,974 3 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-lint E-medium T-cargo
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

What it does

If a license field is defined in Cargo.toml, checks the contents to be a valid SPDX 2.1 license expression.

https://doc.rust-lang.org/cargo/reference/manifest.html#the-license-and-license-file-fields
https://spdx.org/spdx-specification-21-web-version#h.jxpfx0ykyb60 (Appendix IV: SPDX License Expressions)
https://github.com/spdx/license-list-data/tree/v3.6

idstring              = 1*(ALPHA / DIGIT / “-” / “.” )

license-id            = <short form license identifier in Appendix I.1>

license-exception-id  = <short form license exception identifier in Appendix I.2>

license-ref           = [“DocumentRef-“1*(idstring)”:”]”LicenseRef-“1*(idstring)

simple-expression = license-id / license-id”+” / license-ref

compound-expression =  1*1(simple-expression /
                 simple-expression “WITH” license-exception-id /
                 compound-expression “AND” compound-expression /
                 compound-expression “OR” compound-expression ) /
                     “(“ compound-expression “)“ )
license-expression =  1*1(simple-expression / compound-expression)
Categories (optional)
  • Kind: clippy::cargo

I'm not actually sure, it might be that crates.io check the license field to be a valid expression. Even if that's the case, then it would still be nice to catch this sort of mistake earlier.

The lint should probably also deny specifying multiple licenses with /, which according to the documentation (see link above) is still accepted but not recommended:

Previously multiple licenses could be separated with a /, but that usage is deprecated.

Drawbacks

None that I can think of.

Example

E.g. MIT OR XD would be denied, since the XD license is not known. MIT/Apache-2.0 would get denied due to the deprecated slash syntax. An empty string would also get denied.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Cargo.toml license field and the SPDX 2.1 license-expression grammar and license-list-data links provided in the issue. Define the lint's accepted syntax and verify that unknown or empty expressions, and deprecated slash-separated licenses, are rejected.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.