noqa-style (KNQ002)¶
noqa style
Fix is available.
What it does¶
Requires the reason on a # noqa comment to start its own # comment. Opt-in: the rule is not run by default; enable it with extend-select = ["KNQ002"] in [tool.konform.lint] (or --extend-select KNQ002), or select = ["KNQ"] for both KNQ rules.
Why is this bad?¶
A reason glued onto the directive is read differently by different tools (mypy, for one, rejects stray text after # type: ignore[...]). A second # comment is understood the same way everywhere.
Example¶
from os.path import join # noqa: KIS001 re-exported for plugins
value = compute() # noqa: KPT010 - generated code
Use instead:
from os.path import join # noqa: KIS001 # re-exported for plugins
value = compute() # noqa: KPT010 # generated code
Fix behavior¶
konform check --fix rewrites it. The fix is safe: it only moves existing text behind a #, and the suppressed codes do not change. Comments without a reason are KNQ001's concern, and # noqa: kis001 (lowercase, so not a code and possibly a typo) is left alone.
Suppressing¶
Like KNQ001 this rule cannot be suppressed with # noqa (a bare one would silence it) and --ignore-noqa does not affect it. Turn it off with ignore or per-file-ignores.
Options¶
Configured in [tool.konform.lint.noqa-style].
| Option | Type | Default | Description |
|---|---|---|---|
level |
"warning" \| "error" |
"error" |
Severity of violations. |