eslint-fix-utils

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

A library of utilities for ESLint rule fixers and suggestions, providing functions to safely manipulate AST nodes (e.g., add/remove object properties, array elements) while handling commas and formatting. Current stable version is 0.4.2. Released under MIT, actively maintained. Key differentiator: offers both higher-level fixer helpers (fixAddObjectProperty, fixRemoveArrayElement) and full APIs (addObjectProperty, removeArrayElement) for custom fix logic. Requires ESLint >=8 and @types/estree >=1. ESM-only since v0.4.0.

error ERR_REQUIRE_ESM: require() of ES Module /path/to/eslint-fix-utils/index.js from /path/to/your-file.js not supported.
cause Package is ESM-only since v0.4.0, but required with require().
fix
Switch to import syntax or use dynamic import().
error TypeError: fixer is not a function
cause When using the full API functions, the fixer argument must be provided as a separate parameter.
fix
Ensure you call the function with the correct signature: addObjectProperty(context, fixer, node, key, value).
error Cannot find module '@types/estree' or its corresponding type declarations.
cause @types/estree is a peer dependency and not installed automatically.
fix
Run npm install --save-dev @types/estree or add it to your devDependencies.
breaking v0.4.0 drops support for Node 18 and switches to ESM-only with bundled exports.
fix Update Node to ^20.19.0 || ^22.12.0 || >=24.0.0. Use native ESM or a bundler that handles ESM.
breaking v0.3.0 removed support for Node 18.
fix Upgrade Node to >=20 or stick with v0.2.x.
deprecated All 'fix' prefixed functions are wrappers; consider using the full API variants directly for more control.
fix Use addObjectProperty, removeArrayElement, etc., instead of fixAddObjectProperty if you need custom fix logic.
npm install eslint-fix-utils
yarn add eslint-fix-utils
pnpm add eslint-fix-utils

Shows how to use addObjectProperty in an ESLint rule to add a property to an object expression. Demonstrates named imports and the fix function pattern.

import { addObjectProperty, removeArrayElement } from 'eslint-fix-utils';

export default {
  create(context) {
    return {
      ObjectExpression(node) {
        context.report({
          node,
          messageId: 'addProperty',
          fix: (fixer) => {
            return addObjectProperty(context, fixer, node, 'type', 'module');
          },
        });
      },
    };
  },
};