Skip to main content

nocomment-linter

nocomment-linter bans comments in Python code and is designed for coding agents: compact, stable, one-line-per-violation output, safe autofix.

What it does

  • checks only *.py files (never .pyi);
  • reports regular Python comments; #!, coding cookies, # noqa, # type: ignore, # pragma: no cover, # fmt: off/on, # ruff: noqa, # pyright: ignore are preserved (tooling comments);
  • optionally bans and removes docstrings (module, class, function, async function) — detected via AST, exactly what Python treats as a docstring;
  • --fix removes violations in place and never writes a file that would not compile;
  • configured through pyproject.toml; no .gitignore support.

Installation

pip install nocomment-linter
uv add nocomment-linter --dev

Requires Python 3.11+. For the flake8 plugin, flake8 itself must also be installed (pip install flake8).

From source (development):

uv sync

Check

nocomment-linter .
nocomment-linter src tests

Autofix

nocomment-linter --fix .

Exit codes: 0 — no violations (with --fix: everything fixed), 1 — violations found or unfixable violations remain, 2 — execution error (file read, configuration, tokenizing or parsing).

Configuration

[tool.nocomment-linter]
check-docstrings = false
exclude = [
    "migrations/**",
    "generated/**",
]
  • check-docstrings (default false): true also enables the DOC001-DOC004 docstring rules.
  • exclude: glob patterns (fnmatch semantics) relative to the directory containing pyproject.toml. A pattern containing / is matched against the whole relative path (migrations/**); a pattern without / matches any path component, so generated excludes the generated/ directory.
  • The config is the first pyproject.toml with a [tool.nocomment-linter] section found walking up from the first PATH argument, then from the current directory; with no configuration anywhere, defaults apply.

Always skipped directories: .vscode/, .idea/, .git/, .venv/, venv/, __pycache__/, .mypy_cache/, .pytest_cache/, .ruff_cache/, build/, dist/.

Rule codes

Code Violation
CMT001 standalone comment (only whitespace before #)
CMT002 inline comment (code before # on the same line)
DOC001 module docstring
DOC002 class docstring
DOC003 function docstring
DOC004 async function docstring

Flake8 plugin

Installed from PyPI, the package also registers a flake8 extension, so the same checks run inside flake8 (comments on by default; docstrings only with --nocomment-check-docstrings):

flake8 src tests
flake8 --nocomment-check-docstrings src tests

Code mapping (flake8 requires its own code prefix): CMT001 → NOC001, CMT002 → NOC002, DOC001 → NOC101, DOC002 → NOC102, DOC003 → NOC103, DOC004 → NOC104. Per-line # noqa: NOC001 works as usual; the plugin has no autofix — use nocomment-linter --fix for that.

Output format

One self-sufficient line per violation:

<path>:<start-line>:<start-column>-<end-line>:<end-column> <RULE> <FIX> "<content>"

Coordinates are 1-based; the range is half-open: start points at the first character of the violation, end points one past its last character. <FIX> is delete-line (whole physical line) or delete-range (the violation span). <content> is the exact source text, escaped (\n, \t, \", \\).

src/foo.py:10:5-10:23 CMT001 delete-line "# explanation"
src/foo.py:17:20-17:31 CMT002 delete-range "# legacy"
SUMMARY violations=2 files=1

With no violations:

OK violations=0 files=27

After --fix (all violations fixed):

FIXED violations=4 files=2

files counts the files successfully checked; files with read/parse errors are reported as <path>: error: <message> lines and make the run exit 2. Unfixable violations (autofix would break the file) are printed as ordinary violation lines, the file is left untouched, and the run exits 1.

Metadata

Release files for nocomment-linter 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for nocomment-linter 1.1.0
File Size Uploaded Provenance
nocomment_linter-1.1.0.tar.gz 15.2 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for nocomment-linter 1.1.0
File Interpreter ABI Platform
nocomment_linter-1.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 28.1 kB

Release files / nocomment_linter-1.1.0.tar.gz

Download URL nocomment_linter-1.1.0.tar.gz
Size 15.2 kB
Tags Source
SHA-256 checksum
How to use checksums
239e1b39feb3061d254952796bd35d1a78e446f2d668375417b1fe18cf7618df
BLAKE2b-256 checksum
How to use checksums
6b20c309650a6ad7117c523cd683c599cc694af4c6108076c0385797d9562163
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.11 {"installer":{"name":"uv","version":"0.12.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / nocomment_linter-1.1.0-py3-none-any.whl

Download URL nocomment_linter-1.1.0-py3-none-any.whl
Size 12.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
febc5198345088fd3ae5f8f9daeb86a2b16c5d6ca91d7492b7b297daa6811779
BLAKE2b-256 checksum
How to use checksums
f1b22718fc09545b25451eefa0ba164e5d4ef026b18ac633d41ba1fe8ba6c671
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.11 {"installer":{"name":"uv","version":"0.12.11","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for nocomment-linter 1.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page