eslint-plugin-command

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

ESLint plugin that does nothing by default but provides comment-driven micro-codemod transformations. Current stable version is 3.5.2. It is actively maintained by Anthony Fu with regular releases. Key differentiators: unlike traditional ESLint rules that enforce code style, this plugin triggers on-demand transforms via special comments (e.g., `/// to-function`, `/// to-promise-all`, `/// reverse-if-else`), leveraging ESLint's fix infrastructure. It is ESM-only since v3, requires ESLint 9+ flat config, and ships TypeScript types. Peer dependencies include @typescript-eslint/utils and eslint.

error Error [ERR_REQUIRE_ESM]: require() of ES Module
cause Using require() to import an ESM-only package.
fix
Use import command from 'eslint-plugin-command' and ensure your project is ESM (e.g., set "type": "module" in package.json).
error Failed to load plugin 'command': Cannot find module 'eslint-plugin-command'
cause Plugin not installed or not properly referenced in ESLint config.
fix
Run npm install eslint-plugin-command and add import command from 'eslint-plugin-command' to your flat config.
error Rule 'command/to-function' is not defined
cause Using a command rule without registering the plugin in ESLint config.
fix
Add plugins: { command } and use 'command/to-function': 'warn'.
breaking v3.0.0 dropped CJS support; now ESM-only.
fix Use ESM imports (e.g., `import command from 'eslint-plugin-command'`). If you need CJS, stick to v2.x or use dynamic import().
gotcha The plugin does nothing unless you enable specific command rules. By default, no rules are active.
fix Add rule configurations like `'command/to-function': 'warn'` to your ESLint config.
gotcha Commands are triggered only on files with the special comment (e.g., `/// to-function`). They do not run on all files.
fix Add the comment exactly as documented. Ensure the comment is at the top of the code block.
deprecated The `command/keep-sorted` command is deprecated in favor of `command/keep-sorted-by-keys`.
fix Use `command/keep-sorted-by-keys` instead.
npm install eslint-plugin-command
yarn add eslint-plugin-command
pnpm add eslint-plugin-command

Shows how to set up the plugin using ESLint flat config with two commands enabled.

// eslint.config.js (flat config)
import command from 'eslint-plugin-command'

export default [
  command(),
  {
    plugins: { command },
    rules: {
      'command/to-function': 'warn',
      'command/to-promise-all': 'warn',
    },
  },
]