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-remove-comments

v2.3.10

Published

ESLint plugin to remove comments from code while preserving eslint-disable and TypeScript directives

Readme

eslint-plugin-remove-comments

An ESLint plugin to automatically remove comments from your code while preserving important directives like eslint-disable, TypeScript directives, JSDoc, and more.

Features

  • Reliable auto-fix - Removes comments automatically with ESLint's --fix option
  • Selective preservation - Keep important comments like:
    • ESLint directives (eslint-disable, eslint-enable, etc.)
    • TypeScript directives (@ts-ignore, @ts-expect-error, etc.)
    • Triple-slash references (/// <reference ... />)
    • JSDoc comments (optional)
    • TODO/FIXME/NOTE markers (optional)
    • Empty catch block comments
    • Custom patterns via regex
  • JSX support - Works with React/JSX files
  • TypeScript support - Full TypeScript type definitions included
  • Zero dependencies - Lightweight and fast
  • Fully tested - 119 comprehensive tests across 6 test suites

Installation

npm install --save-dev eslint-plugin-remove-comments

Usage

Basic Setup

Add to your ESLint config:

// eslint.config.js (ESLint 9+)
import removeComments from 'eslint-plugin-remove-comments';

export default [
  {
    plugins: {
      'remove-comments': removeComments
    },
    rules: {
      'remove-comments/remove-all': 'error'
    }
  }
];

Or for ESLint 8:

// .eslintrc.js
module.exports = {
  plugins: ['remove-comments'],
  rules: {
    'remove-comments/remove-all': 'error'
  }
};

Run ESLint with Auto-fix

npx eslint --fix .

Options

preserveJSDoc

Preserve JSDoc comments (comments starting with /**).

{
  rules: {
    'remove-comments/remove-all': ['error', {
      preserveJSDoc: true
    }]
  }
}

Example:

// Before
/**
 * Calculates the sum of two numbers
 * @param {number} a - First number
 * @param {number} b - Second number
 * @returns {number} The sum
 */
function add(a, b) {
  // This comment will be removed
  return a + b;
}

// After (with preserveJSDoc: true)
/**
 * Calculates 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;
}

preserveTodos

Preserve TODO, FIXME, NOTE, HACK, and XXX comments (case-insensitive, requires colon).

{
  rules: {
    'remove-comments/remove-all': ['error', {
      preserveTodos: true
    }]
  }
}

Example:

// Before
// TODO: implement error handling
// FIXME: memory leak here
// NOTE: this is important
// Just a regular comment
function process() {
  // ...
}

// After (with preserveTodos: true)
// TODO: implement error handling
// FIXME: memory leak here
// NOTE: this is important
function process() {
  // ...
}

preservePatterns

Preserve comments matching custom regex patterns.

{
  rules: {
    'remove-comments/remove-all': ['error', {
      preservePatterns: [
        '^KEEP:',           // Keep comments starting with "KEEP:"
        '@license',         // Keep license comments
        'prettier-ignore'   // Keep Prettier directives
      ]
    }]
  }
}

Combining Options

You can combine multiple options:

{
  rules: {
    'remove-comments/remove-all': ['error', {
      preserveJSDoc: true,
      preserveTodos: true,
      preservePatterns: ['^KEEP:', '@license']
    }]
  }
}

Always Preserved

These comments are always preserved regardless of options:

  • ESLint directives: // eslint-disable, /* eslint-enable */, etc.
  • TypeScript directives: // @ts-ignore, // @ts-expect-error, // @ts-nocheck, // @ts-check
  • Triple-slash references: /// <reference path="..." />
  • Empty catch blocks: Comments in empty catch blocks (e.g., catch (e) { /* ignore */ })

Examples

Remove All Comments

// Input
function calculate() {
  // Calculate the result
  const x = 1; // Initialize x
  /* Block comment */
  return x * 2;
}

// Output
function calculate() {
  const x = 1;
  return x * 2;
}

Preserve ESLint Directives

// Input & Output (no change)
// eslint-disable-next-line no-console
console.log('Debug info');

Preserve TypeScript Directives

// Input & Output (no change)
// @ts-ignore
const value = unknownApi();

JSX Support

// Input
function Component() {
  // Component logic
  return (
    <div>
      {/* JSX comment */}
      <p>Hello World</p>
    </div>
  );
}

// Output
function Component() {
  return (
    <div>
      <p>Hello World</p>
    </div>
  );
}

Use Cases

  • Minification: Remove comments before production builds
  • Code cleanup: Remove outdated or unnecessary comments
  • Consistency: Enforce a no-comments policy in certain files
  • Pre-processing: Clean code before further transformations

License

MIT