Lint ships with some universal project-agnostic checks.
To use them, import lint/checks in your config.
header
The checks: let header check validates that the source files start with a configured string.
Use it to enforce a common file header, such as a copyright or license notice.
The test config declares:
check header:
severity = hint
settings:
header = """# Copyright 2026 Example Authors
# SPDX-License-Identifier: MIT
"""
findingMsg = "missing or incorrect license header"
This is an ordinary check, not a semCheck, so it does not require --semantic.
Settings
| Setting | Type | Default | Description |
|---|---|---|---|
| header | string | - | The exact prefix expected at the start of the file. |
| findingMsg | string | "missing or incorrect header" | The message reported when the prefix does not match. Override it to describe your project's header policy, or omit it to use the default. |
patterns
The checks: let patterns check reports source text that matches a forbidden regular expression, unless an allowed expression matches the entire forbidden match.
Use it for simple textual rules, such as banning particular calls. This is an ordinary check and does not require --semantic.
The test config declares:
check patterns:
severity = error
settings:
forbidden =
[r"\bPeerId\.random\([^)]*\)", r"\.withTimeout\(\d+\.\w+\)", "regex fixture"]
allowed = [r"PeerId\.random\(\s*(?:-?\d+)?\s*\)", "PeerId"]
findingMsg = "Forbidden: $forbiddenMatch (pattern: $forbiddenPattern)"
This reports PeerId.random(seed) and PeerId.random(42 + 1), but permits PeerId.random(), PeerId.random(42), and PeerId.random(-7).
Patterns use the syntax supported by the regex package. Use Nim raw string literals (r"...") so backslashes reach the regex compiler unchanged.
Settings
| Setting | Type | Default | Description |
|---|---|---|---|
| forbidden | seq[string] | @[] | Patterns to search for. Each match produces a finding unless an allowed pattern exempts it. |
| allowed | seq[string] | @[] | Exceptions matched against the entire text of each forbidden match, not against the surrounding line. An empty list means no exceptions. |
| findingMsg | string | $forbiddenMatch matches $forbiddenPattern | Message template. $forbiddenMatch is replaced with the matched text and $forbiddenPattern with the original forbidden pattern. Use $$ for a literal dollar sign. |
Matching behavior
- Source is searched one line at a time; patterns cannot match across line breaks. Anchors such as ^ and $ apply to each line.
- Matching uses raw source, including comments and string literals. It does not interpret Nim syntax or resolve types.
- All matches on a line are checked, not just the first. Forbidden patterns are independent, so overlapping patterns can report the same source text more than once.
- An allowed expression exempts only the current forbidden match. Matching some other text on the line does not suppress a finding.
- Findings point to the start of the match. The runner applies the usual #nolint suppression and requested line ranges.