npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

eslint-plugin-ban-comments

v1.0.3

Published

ESLint plugin to disallow comments in JavaScript and TypeScript files

Readme

eslint-plugin-ban-comments

An ESLint plugin that disallows comments in JavaScript and TypeScript files, with configurable exceptions for specific patterns and directives.

Why Use This Plugin?

This plugin is useful in scenarios where you want to enforce a strict "self-documenting code" approach:

  • Code clarity: Forces developers to write code that is inherently readable without relying on comments
  • Prevents outdated comments: Eliminates the risk of comments becoming stale or misleading as code evolves
  • Consistent codebase: Ensures a uniform approach to code documentation across your project
  • Forces better naming: Encourages more descriptive variable and function names instead of explanatory comments
  • Minimal codebases: Useful for libraries or modules where you want to keep the code as clean and minimal as possible

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.

Installation

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

Usage

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"
  }
}

Rule Details

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}!`;
}

Options

The rule accepts an options object with the following properties:

allowedPatterns

An 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

allowedPrefixes

An 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

allowEslintDirectives

Boolean flag to allow ESLint directive comments. Default: true.

{
  "ban-comments/ban-comments": [
    "error",
    {
      "allowEslintDirectives": false
    }
  ]
}

allowTypeScriptDirectives

Boolean flag to allow TypeScript directive comments. Default: true.

{
  "ban-comments/ban-comments": [
    "error",
    {
      "allowTypeScriptDirectives": false
    }
  ]
}

allowJSDoc

Boolean 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;

Complete Example

{
  "plugins": ["ban-comments"],
  "rules": {
    "ban-comments/ban-comments": [
      "error",
      {
        "allowedPatterns": ["^TODO:", "^FIXME:", "^NOTE:"],
        "allowedPrefixes": ["DEBUG:", "HACK:"],
        "allowEslintDirectives": true,
        "allowTypeScriptDirectives": true,
        "allowJSDoc": false
      }
    ]
  }
}

Auto-fixing

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

Requirements

  • ESLint >= 6.0.0
  • JavaScript runtime (Node.js >= 10.0.0, Bun, etc.)

License

MIT © ggofri