ESLint Plugin No Commented Code

raw JSON →
1.0.10 verified Sat Apr 25 auth: no javascript

An ESLint plugin that disallows commented-out code in JavaScript and TypeScript files. Version 1.0.10 is the current stable release with no active development cadence. It differentiates valid comments from commented-out code by detecting code patterns (e.g., imports, function definitions, expressions) within comments. Works as a standalone rule without additional configuration, making it lightweight. Primarily maintained by a single contributor with infrequent updates.

error Error: Failed to load plugin 'no-commented-code'
cause ESLint cannot find the plugin because it is not installed or the plugin name is incorrect.
fix
Ensure eslint-plugin-no-commented-code is installed via npm, and in ESLint config use 'no-commented-code' (without prefix).
error Configuration for rule 'no-commented-code' is invalid: Unknown rule.
cause Referencing the rule without the plugin namespace.
fix
Use 'no-commented-code/no-commented-code' as the rule name in ESLint config.
error Definition for rule 'no-commented-code/no-commented-code' was not found.
cause The plugin is not loaded in ESLint config; missing 'plugins' section.
fix
Add 'no-commented-code' to the plugins array in ESLint config.
gotcha The rule may flag comments containing code-like strings that are not actually executable code, such as JSON examples or pseudocode.
fix Use ESLint disable comments for false positives or adjust the rule severity to 'warn'.
gotcha When using eslint-disable comments to bypass the rule, ensure they are placed correctly; the rule's disable comment uses 'no-commented-code/no-commented-code' (not 'no-commented-code').
fix Use // eslint-disable-next-line no-commented-code/no-commented-code or /* eslint-disable no-commented-code/no-commented-code */.
gotcha The rule is applied globally; you cannot configure it to allow certain patterns (e.g., commented-out test code).
fix Disable the rule per line or use a different ESLint rule if more granularity is needed.
npm install eslint-plugin-no-commented-code
yarn add eslint-plugin-no-commented-code
pnpm add eslint-plugin-no-commented-code

Shows how to configure ESLint with the plugin to error on commented-out code.

// Install: npm install eslint eslint-plugin-no-commented-code --save-dev
// .eslintrc.js
module.exports = {
  plugins: ['no-commented-code'],
  rules: {
    'no-commented-code/no-commented-code': 'error'
  }
};