eslint-plugin-no-comments
raw JSON → 1.2.1 verified Sat Apr 25 auth: no javascript
An ESLint plugin that disallows comment blocks in source code to prevent shipping notes, old code, or sensitive information to production. Current stable version is 1.2.1, released with support for ESLint 9 and 10 via flat config format. Requires Node.js >= 20.19.0. Key differentiator: automatically ignores comments starting with 'global' or 'eslint' to preserve ESLint directives, and allows a customizable allow list. Unlike general comment-stripping tools, it integrates directly with ESLint's rule system.
Common errors
error Error [ERR_REQUIRE_ESM]: require() of ES Module /path/to/node_modules/eslint-plugin-no-comments/index.js from /path/to/.eslintrc.js not supported. ↓
cause Using CommonJS require() to load the plugin, but v1.2.0+ is an ESM-only package.
fix
Switch to import syntax and flat config: import noComments from 'eslint-plugin-no-comments'; in eslint.config.js.
error ESLint couldn't find the plugin "eslint-plugin-no-comments". This is most likely an issue with the plugin resolution. ↓
cause Incorrect plugin configuration in flat config (e.g., missing 'plugins' object or wrong key name).
fix
In eslint.config.js, export an array with an object containing plugins: { 'no-comments': noComments }.
error Configuration for rule "no-comments/disallowComments" is invalid. Value "error" should be object or array. ↓
cause Setting the rule to a string severity without specifying options when options are required.
fix
Use array syntax: 'no-comments/disallowComments': ['error', { allow: [...] }]
Warnings
breaking v1.2.0 drops support for .eslintrc (Legacy ESLint config format) and requires flat config (eslint.config.js). ↓
fix Migrate to eslint.config.js using the flat config pattern shown in the quickstart. See https://eslint.org/docs/latest/use/configure/configuration-files-new
breaking v1.2.0 requires Node.js >= 20.19.0. Older Node versions cause crashes. ↓
fix Update Node.js to v20.19.0 or higher. Run: nvm install 20.19.0 (or use your version manager).
deprecated v1.1.x and earlier used .eslintrc configuration and CommonJS require(). They are deprecated and may break in future ESLint versions. ↓
fix Upgrade to v1.2.0+ and migrate to flat config. The old versions are no longer maintained.
gotcha If you specify an `allow` array, it **replaces** the default allowed comments ('global' and 'eslint') entirely. Not including 'eslint' will cause directive comments like '// eslint-disable-next-line' to be flagged as errors. ↓
fix Always include 'eslint' and 'global' in the `allow` array if you want those comments to be allowed. See the README example with 'global', 'eslint', 'TODO', 'FIXME'.
gotcha Single-line comments (//) and block comments (/* */) are both disallowed unless they start with a string in the allow list. Comments without a leading word after the comment marker may also trigger errors. ↓
fix Ensure all allowed comments start with one of the strings in the `allow` array (or the defaults). For example, '// TODO' works but '//TODO' without space may not be recognized if the pattern is strict.
Install
npm install eslint-plugin-no-comments yarn add eslint-plugin-no-comments pnpm add eslint-plugin-no-comments Imports
- default wrong
const noComments = require('eslint-plugin-no-comments')correctimport noComments from 'eslint-plugin-no-comments' - noComments (as plugin) wrong
import { noComments } from 'eslint-plugin-no-comments'correctimport noComments from 'eslint-plugin-no-comments' - rules (if accessing directly) wrong
import { rules } from 'eslint-plugin-no-comments'correctimport noComments from 'eslint-plugin-no-comments'; const rules = noComments.rules; - plugin for flat config wrong
module.exports = { plugins: { 'no-comments': noComments }, rules: { ... } }correctimport noComments from 'eslint-plugin-no-comments'; export default [{ plugins: { 'no-comments': noComments }, rules: { 'no-comments/disallowComments': 'error' } }]
Quickstart
// Install: npm install eslint-plugin-no-comments --save-dev
// eslint.config.js
import noComments from 'eslint-plugin-no-comments';
export default [
{
plugins: {
'no-comments': noComments
},
rules: {
'no-comments/disallowComments': [
'error',
{
allow: ['global', 'eslint', 'TODO', 'FIXME']
}
]
}
}
];