
Security News
/Company News
Securing the Financial Frontier: How Capital One Uses Socket for Open Source Security
Capital One is partnering with Socket to proactively secure its open source supply chain.
eslint-plugin-ban-comments
Advanced tools
ESLint plugin to disallow comments in JavaScript and TypeScript files
An ESLint plugin that disallows comments in JavaScript and TypeScript files, with configurable exceptions for specific patterns and directives.
This plugin is useful in scenarios where you want to enforce a strict "self-documenting code" approach:
Note: This approach works best for teams that prioritize clean, self-explanatory code. It may not be suitable for all projects, especially those requiring extensive documentation or complex business logic explanations.
npm install eslint-plugin-ban-comments --save-dev
Or with other package managers:
# Using Yarn
yarn add eslint-plugin-ban-comments --dev
# Using pnpm
pnpm add eslint-plugin-ban-comments --save-dev
# Using Bun
bun add eslint-plugin-ban-comments --dev
Add ban-comments to the plugins section of your .eslintrc configuration file:
{
"plugins": ["ban-comments"]
}
Then configure the rule under the rules section:
{
"rules": {
"ban-comments/ban-comments": "error"
}
}
This rule disallows comments in your code. By default, it allows ESLint directive comments (like eslint-disable) and TypeScript directive comments (like @ts-ignore).
Examples of incorrect code for this rule:
// This is a regular comment
const x = 1;
/*
* This is a block comment
*/
const y = 2;
const z = 3; // Inline comment
Examples of correct code for this rule (with default options):
// eslint-disable-next-line no-console
console.log('Hello');
/* eslint-disable */
const allowedCode = true;
/* eslint-enable */
// @ts-ignore
const tsCode: any = something;
/**
* This is a JSDoc comment describing the function
* @param {string} name - The name parameter
* @returns {string} A greeting message
*/
function greet(name) {
return `Hello, ${name}!`;
}
The rule accepts an options object with the following properties:
allowedPatternsAn array of regex patterns for comments that should be allowed.
{
"ban-comments/ban-comments": [
"error",
{
"allowedPatterns": ["^TODO:", "^FIXME:"]
}
]
}
With this configuration, these comments would be allowed:
// TODO: Implement this feature
// FIXME: Bug in calculation
allowedPrefixesAn array of prefixes for comments that should be allowed.
{
"ban-comments/ban-comments": [
"error",
{
"allowedPrefixes": ["DEBUG:", "NOTE:"]
}
]
}
With this configuration, these comments would be allowed:
// DEBUG: This is a debug comment
// NOTE: Important information
allowEslintDirectivesBoolean flag to allow ESLint directive comments. Default: true.
{
"ban-comments/ban-comments": [
"error",
{
"allowEslintDirectives": false
}
]
}
allowTypeScriptDirectivesBoolean flag to allow TypeScript directive comments. Default: true.
{
"ban-comments/ban-comments": [
"error",
{
"allowTypeScriptDirectives": false
}
]
}
allowJSDocBoolean flag to allow JSDoc comments (/** ... */). Default: false.
{
"ban-comments/ban-comments": [
"error",
{
"allowJSDoc": true
}
]
}
With allowJSDoc: true, these comments are allowed:
/**
* Calculate the sum of two numbers
* @param {number} a - First number
* @param {number} b - Second number
* @returns {number} The sum
*/
function add(a, b) {
return a + b;
}
But regular block comments are still disallowed:
/* This is not allowed */
const x = 1;
{
"plugins": ["ban-comments"],
"rules": {
"ban-comments/ban-comments": [
"error",
{
"allowedPatterns": ["^TODO:", "^FIXME:", "^NOTE:"],
"allowedPrefixes": ["DEBUG:", "HACK:"],
"allowEslintDirectives": true,
"allowTypeScriptDirectives": true,
"allowJSDoc": false
}
]
}
}
This rule supports auto-fixing. When run with the --fix flag, ESLint will automatically remove disallowed comments from your code.
eslint --fix your-file.js
MIT © ggofri
FAQs
ESLint plugin to disallow comments in JavaScript and TypeScript files
The npm package eslint-plugin-ban-comments receives a total of 121 weekly downloads. As such, eslint-plugin-ban-comments popularity was classified as not popular.
We found that eslint-plugin-ban-comments demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.

Security News
/Company News
Capital One is partnering with Socket to proactively secure its open source supply chain.

Security News
Socket CTO Ahmad Nassri discusses how to keep AI agents from bypassing package blocks, limit credential access, and monitor their actions.

Security News
GPT-6 Astra tried to plant malicious code in simulated open source projects using fake GitHub accounts and deceptive PRs during an assigned CTF challenge.