clean-comment-mining
Classify every comment as compliant or non-compliant and record path and line in metrics
# clean-comment-mining
Read-only miner for comment policy. It scans **every comment in the file**. It does not look at a diff, so a comment far from an edit is still classified.
The file is left unchanged. Each comment block emits one `comment_block` metric.
The workflow first walks the working directory and records which languages are present. A later step runs only when that walk found at least one file for its language. Start the workflow from the repository you want scanned, so the walk and the later scan see the same tree.
JSON is included. Its grammar has no comments, so that step records nothing when JSON files exist.
## Metric
**Name:** `comment_block`
| Cardinality | Values |
| ------------ | ----------------------------------------------------------------------------------- |
| `compliance` | `compliant`, `non-compliant` |
| `kind` | `reference`, `directive`, `keep`, `comment-removal`, `malformed-keep`, `narration` |
| `file_path` | path relative to the scan root |
| `line` | 1-based start line of the comment |
Blocks that start on the same line and share `compliance` and `kind` increment `count` instead of opening a second row.
## Languages
| Language | Files | Compliant `keep` | Compliant directives |
| --- | --- | --- | --- |
| TypeScript, TSX, JSX, JavaScript | `.ts` `.mts` `.cts` `.tsx` `.jsx` `.js` `.mjs` `.cjs` | `// keep: <edit> — <what breaks>` | `/// <reference …>`, oxlint/eslint disable and enable, `@ts-expect-error`, `@ts-nocheck`, `@ts-ignore` |
| Go, Rust, Java, Kotlin, Scala, C, C++, C# | `.go` `.rs` `.java` `.kt` `.kts` `.scala` `.sc` `.c` `.h` `.cc` `.cpp` `.cxx` `.hpp` `.hh` `.hxx` `.cs` | same `// keep:` line | `nolint`, `go:generate`-style directives, `noinspection`, `NOSONAR`, `checkstyle:`, `scalastyle:`, `wartremover:`, `NOLINT`, `clang-format`, `ReSharper`, `<auto-generated`. Rust has no directive form |
| Python, Ruby, Elixir, YAML, TOML | `.py` `.pyi` `.rb` `.ex` `.exs` `.yaml` `.yml` `.toml` | `# keep: <edit> — <what breaks>` | `noqa`, `type: ignore`, `pyright:`, `pylint:`, `mypy:`, `ruff:`, `rubocop:`, `frozen_string_literal:`, `credo:`, `yaml-language-server:`, `yamllint`. TOML has no directive form |
| PHP | `.php` | a `// keep:` or `# keep:` line | `phpcs:`, `phpstan-`, `psalm-`, `@phpstan`, `@psalm` |
| CSS | `.css` | `/* keep: <edit> — <what breaks> */` | `stylelint-`, `prettier-ignore` |
| HTML, Angular templates, XML | `.html` `.htm` `.component.html` `.xml` | `<!-- keep: <edit> — <what breaks> -->` | `eslint-`, `stylelint-` on HTML and Angular. XML has no directive form |
| JSON | `.json` | none | none |
`--` is accepted in place of the em dash. `.h` is C. A `*.component.html` file is an Angular template. The HTML step skips those files, and the Angular step parses them as HTML, which is the grammar that contains their comments. A template is counted once.
Strings and regex literals that contain comment markers are not comments.
## What counts as non-compliant
- A `keep` whose edit is "removing this comment" or "deleting the comment" (`kind: comment-removal`)
- A `keep` that does not name both an edit and what breaks (`kind: malformed-keep`)
- Everything else (`kind: narration`): narration, TODOs, banners, and doc comments. In JavaScript and TypeScript a `keep` written as `/* */` is narration. In PHP a `keep` written as `/* */` is narration.
## What it skips
- Paths under `node_modules/`, `dist/`, `build/`, `generated/`, `coverage/`, `vendor/`, or `.git/`
- `payload-types.ts`
- Files whose extension is not in the table above