Work · hdrcheck

How the header check works

Same idea in the browser and in the CLI. Read a little, decide three ways, don’t get clever.

  1. Take the first 20 lines of the file. That’s enough for a header and short enough to stay cheap.
  2. Look for SPDX-License-Identifier:. If the id matches what you asked for, it’s ok. If it names another id, it’s different.
  3. No SPDX line? If the leading comments already talk about copyright or a license, treat that as different and leave it alone.
  4. Otherwise the header is missing. Check mode reports it. Write mode adds one line and only then.

What write mode will not touch

A file that already has a different SPDX id. A file whose first comments look like an old license or copyright block. That’s the point — it should never stomp a header it doesn’t understand.

Languages

.py, .js, .ts, .go, .rs, .java. Python headers use #. The others use //. On write, a shebang and a coding cookie stay on top.

CLI

The command-line tool is a small Python 3 package with no third-party dependencies. It can scan a tree, exit 1 for CI, or write missing headers.

python3 -m hdrcheck --root path/to/project --check
python3 -m hdrcheck --root path/to/project --license-id Apache-2.0 --write

The CLI lives on the workbench. The browser checker below is the public piece.

Open the in-browser checker Back to work