Practices and Specific ES Features > no-comments
Prevents leaking comments into production if bundler is not used and stops developers from commenting out old lines of code.
eslint-plugin-no-comments
Prevents leaving comment blocks in the file. This plugin will ignore all comments starting from string global or eslint in order to keep eslint local settings safe.
Why?
If the source code is not being processed by a bundler or any other tool, there is a risk of shipping some notes, old code blocks or sensitive information to production environment.
Installation
npm install eslint-plugin-no-comments --save-dev
Configuration
// 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"],
}
]
}
}
];
How to add JSDoc to allowlist?
If allow is not specified, all comments are disallowed except those starting with eslint or global.
Note: providing
allowreplaces the defaults entirely. If you want to keepeslintandglobalcomments allowed alongside your own entries, include them explicitly in the array (as shown in the example above).
Rule details
Fail
// import {Text} from 'react-native'
const {Text, Image} = require('react-native')
/* var price1 = 5;
* var price2 = 6;
var total = price1 + price2;
*/
const {Text, Image} = require('cool-package') // TO-DO fix vulnerability
Pass
/* global MyClass */
// eslint-disable-next-line no-unused-vars
var price1 = 5;
var price2 = 6;
var total = price1 + price2;
if allow is specified, e.g.: ["global", "eslint", "TODO", "FIXME"]
/* global MyClass */
// eslint-disable-next-line no-unused-vars
const {Text, Image} = require('cool-package') // TODO fix vulnerability
Changelog
1.2.0
- Added support for ESLint 9 and ESLint 10
- Migrated to flat config format (
eslint.config.js) - Added
schemato rule meta for proper options validation - Requires Node.js >= 20.19.0