Skip to content

ci(lint): require an SPDX license header in Rust files - #132

Merged
stewartadam merged 2 commits into
mainfrom
ci/spdx-license-headers
Nov 29, 2026
Merged

stewartadam merged 2 commits into
mainfrom
ci/spdx-license-headers

Conversation

@stewartadam

@stewartadam stewartadam commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

What

  • New prek hook, insert-license (MIT licensed), that checks every Rust file starts with // SPDX-License-Identifier: MIT OR Apache-2.0, matching license = "MIT OR Apache-2.0" in Cargo.toml. The header text lives in .license-header.txt. When a file is missing it, the hook adds the line and fails so the change can be reviewed and staged.
  • The header has to be on line 1 (--detect-license-in-X-top-lines=1). The hook normally skips leading #! lines as shebangs, which would put the header below a file's inner attributes (such as warn(missing_docs)). --insert-license-after-regex=(?!) (a regex that never matches) makes it insert at the very top.
  • CI: the lint job now also runs insert-license, and a new headers path filter (**/*.rs, .license-header.txt, .pre-commit-config.yaml) triggers it. No new uses: lines, so actions.lock is unchanged.
  • Added the header to all 21 existing Rust files, including the fuzz target under further testing/, and removed the long-form Copyright 2020 sacn Developers / Licensed under the Apache License... blocks it replaces. Each file's note on its origin (the St Andrews dissertation project) is kept.
  • CONTRIBUTING.md describes the hook and the new CI trigger.

Testing

  • prek run insert-license --all-files passes on this branch.
  • On new files, one starting with an inner attribute and one without, the hook put the header on line 1 and passed on the next run.
  • rustfmt, Clippy (-D warnings), rumdl and actionlint all pass.

Shell scripts and other non-Rust files are out of scope here. They could get a #-style header from a second hook entry if wanted.


Generated by Claude Code

@stewartadam stewartadam self-assigned this Nov 27, 2026
@stewartadam
stewartadam force-pushed the ci/spdx-license-headers branch from 0e57e6a to 24b954f Compare November 29, 2026 06:42
@stewartadam
stewartadam enabled auto-merge (squash) November 29, 2026 06:43
@stewartadam
stewartadam force-pushed the ci/spdx-license-headers branch 2 times, most recently from dfc46a5 to 850e3d7 Compare November 29, 2026 06:53
Add the insert-license prek hook, which checks that every Rust file
starts with `// SPDX-License-Identifier: MIT OR Apache-2.0` and adds the
line where it is missing. CI's lint job now runs it whenever a Rust file
or the header config changes.

Add the header to the existing Rust files.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The SPDX identifier on line 1 now states each file's license, so remove the
repeated copyright and license prose. The notes on each file's origin stay.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@stewartadam
stewartadam force-pushed the ci/spdx-license-headers branch from 850e3d7 to 699a846 Compare November 29, 2026 06:56
@stewartadam
stewartadam merged commit 049139a into main Nov 29, 2026
13 checks passed
@stewartadam
stewartadam deleted the ci/spdx-license-headers branch November 29, 2026 06:58
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.

2 participants