π§ A lightweight, fast CLI tool that checks whether your variable declarations are properly commented before committing code. Ensure code readability and consistency across your team with one simple command.
πγζ₯ι δΈζζζ‘£θ―·ηΉε»θΏιγ
Modern projects often enforce strict code style rules β yet comment standards are easy to overlook.
code-comment-check solves exactly that problem:
- β Automatically detects missing comments for each variable declaration
- β Prevents committing code with missing comments
- β By default, only checks changed lines in the current commit β fast and efficient
- β
Supports a
--strictmode to inspect all declarations in changed files - π« Ignores test files by default (
__tests__,.test.ts,.spec.tsx, etc.)
Use it in your local workflow or CI pipeline to enforce consistent documentation standards across your team.
# Recommended
pnpm add -D code-comment-check
# Or using npm / yarn
npm install -D code-comment-check
# or
yarn add -D code-comment-checkAfter installation, the CLI command is automatically registered:
comment-checkpnpm comment-checkDefault behavior:
- Only checks changed lines in the committed files
- Automatically ignores test files
- Displays missing comment entries in a formatted table (file, line, declaration)
- Returns a non-zero exit code if issues are found, blocking the commit
pnpm comment-check --strictIn strict mode, the tool scans all declarations in changed files, making it ideal for code review or CI environments.
In your .husky/pre-commit file, add the following:
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"
pnpm comment-checkEffect:
- β If all checks pass β the commit proceeds
- β If any declaration lacks a comment β a table of missing comments is printed, and the commit is blocked
π Checking annotation comments...
β οΈ Missing annotation comments:
ββββββββββββββββββββββββββββββββββββββββββ¬βββββββββ¬βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β File β Line β Declaration β
ββββββββββββββββββββββββββββββββββββββββββΌβββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β test/test2.ts β 1 β const test = '123' β
ββββββββββββββββββββββββββββββββββββββββββΌβββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β test/test2.ts β 2 β let test1 = '123' β
ββββββββββββββββββββββββββββββββββββββββββΌβββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β test/test2.ts β 3 β var test2 = '123' β
ββββββββββββββββββββββββββββββββββββββββββΌβββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β test/test2.ts β 4 β export const test3 = '123' β
ββββββββββββββββββββββββββββββββββββββββββΌβββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β test/test2.ts β 5 β export let test4 = '123' β
ββββββββββββββββββββββββββββββββββββββββββΌβββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β test/test2.ts β 6 β export var test5 = '123' β
ββββββββββββββββββββββββββββββββββββββββββΌβββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β test/test2.ts β 8 β interface Type { β
ββββββββββββββββββββββββββββββββββββββββββΌβββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β test/test2.ts β 12 β type UserType = 'admin' | 'user' β
ββββββββββββββββββββββββββββββββββββββββββΌβββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β test/test2.ts β 14 β export interface User { β
ββββββββββββββββββββββββββββββββββββββββββΌβββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β test/test2.ts β 20 β export type UserWithType = User & { β
ββββββββββββββββββββββββββββββββββββββββββΌβββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β test/test2.ts β 24 β const bb = '123' β
ββββββββββββββββββββββββββββββββββββββββββΌβββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β test/test2.ts β 25 β const cc = '123' β
ββββββββββββββββββββββββββββββββββββββββββΌβββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β test/test2.ts β 26 β const dd = '123' β
ββββββββββββββββββββββββββββββββββββββββββΌβββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β test/test2.ts β 28 β function fn() { β
ββββββββββββββββββββββββββββββββββββββββββΌβββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β test/test2.ts β 32 β class Test { β
ββββββββββββββββββββββββββββββββββββββββββΌβββββββββΌβββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β test/test2.ts β 38 β enum TestEnum { β
ββββββββββββββββββββββββββββββββββββββββββ΄βββββββββ΄βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Please add comments before committing your code.
| Feature | Description |
|---|---|
| β‘οΈ High performance | Built on the SWC compiler β much faster than Babel |
| π§© Zero configuration | Works out of the box, automatically registers the CLI |
| π¬ Clear output | Displays missing comment details in a table |
| π§ Smart parsing | Supports Javascript / TypeScript / JSX / TSX syntax |
| πͺΆ Lightweight | Non-intrusive β analyzes AST without modifying code |
| π§ Extensible | Supports the --strict flag for broader checks |
- Enforcing code documentation standards
- Pre-commit comment validation
- Automated CI code inspection
- Integration in internal dev tools or monorepo setups
MIT Β© 2025 β maintained by laoer536