Skip to content

Suppressing violations

# noqa comments

from os.path import join   # noqa: KIS001   exact rule
from os.path import join   # noqa: KIS       whole category
from os.path import join   # noqa           everything on this line
  • Multiple codes are comma-separated: # noqa: KIS001, KPT010.
  • Empty entries are ignored; # noqa: with no codes behaves like a bare # noqa.
  • Only real comments count: # noqa inside a string literal suppresses nothing.
  • --ignore-noqa reports every violation regardless. Text after the codes is a free-form explanation and never changes what is suppressed: # noqa: KIS001 # re-exported for plugins suppresses KIS001 only. KNQ001 can require that explanation, and KNQ002 wants it in its own # ... comment. KNQ003 flags (and removes) codes that no longer suppress anything.

Adding noqa automatically

$ konform check --add-noqa src/

Appends # noqa: CODE to each violating line. Codes merge into an existing list (sorted, deduplicated); a bare # noqa is left untouched. A line that can't take a comment (it ends inside a multi-line string, or after a \ continuation) is left alone with a warning naming it, since the text would otherwise end up inside the string.

Baselining with --add-noqa

konform check --add-noqa appends # noqa: CODE to every line with a violation (merging into an existing # noqa: ...; a blanket # noqa is left as is). Pass --noqa-reason to record why, once, for the whole baseline:

$ konform check --add-noqa --noqa-reason "legacy, tracked in ABC-123" src/
# from os.path import join  # noqa: KIS001  # legacy, tracked in ABC-123

With --extend-select KNQ001, the reason also fills in existing # noqa comments that lack one. A reason that is already there is never overwritten. The flag requires --add-noqa.

Config-level suppression

[tool.konform.lint]
ignore = ["KIS002"]

[tool.konform.lint.per-file-ignores]
"tests/**" = ["KIS001", "KPT"]

Aliasing noqa codes

When a rule code changes, or you migrate from another linter's codes, aliases keep old comments working:

[tool.konform.lint.noqa-aliases]
IS001 = "KIS001"
IS    = "KIS"
from os.path import join   # noqa: IS001   suppresses KIS001 via the alias