Detalhes do pacote

eslint-fix-utils

JoshuaKGoldberg271.4kMIT0.2.1

Utilities for ESLint rule fixers and suggestions. 🧑‍🔧

readme (leia-me)

ESLint Fix Utils

Utilities for ESLint rule fixers and suggestions. 🧑‍🔧

👪 All Contributors: 2 🤝 Code of Conduct: Kept 🧪 Coverage 📝 License: MIT 📦 npm version 💪 TypeScript: Strict

Usage

If you're working on an ESLint plugin, install this as a dependency:

npm i eslint-fix-utils

You'll then be able to use any of its exported utilities in your rules.

Fixer APIs

fixRemoveArrayElement

Version of removeArrayElement that can be passed directly as a fix property.

import { fixRemoveArrayElement } from "eslint-fix-utils";

// ...

export function report(index: number, node: ESTree.ArrayExpression) {
    context.report({
        fix: fixRemoveArrayElement(context, index, node.elements),
        messageId,
        node: node.elements[index],
    });
}

fixRemoveObjectProperty

Version of removeObjectProperty that can be passed directly as a fix property.

import { fixRemoveObjectProperty } from "eslint-fix-utils";

// ...

export function report(index: number, node: ESTree.ObjectExpression) {
    context.report({
        fix: fixRemoveObjectProperty(context, node.properties[index]),
        messageId,
        node: node.properties[index],
    });
}

Full APIs

removeArrayElement

Removes an element from an array expression, along with any commas that are no longer necessary.

Parameters:

  1. context
  2. fixer
  3. elementOrIndex: the child expression, spread element, or a numeric index of the child
  4. parentOrElements: the array expression node, or its .elements array
import { removeArrayElement } from "eslint-fix-utils";

// ...

export function report(index: number, node: ESTree.ArrayExpression) {
    context.report({
        fix(fixer) {
            // Removes the last element of the array:
            return removeArrayElement(context, fixer, index, node.elements);
        },
        messageId,
        node: node.elements[index],
    });
}
[
     'a',
-    'b',
-    'c'
+    'b'
]

Trailing commas are removed so that the fixed code will work regardless of whether the language and location allows them.

removeObjectProperty

Removes a property from an object expression, along with any commas that are no longer necessary.

Parameters:

  1. context
  2. fixer
  3. property: the property node
import { removeObjectProperty } from "eslint-fix-utils";

// ...

export function report(index: number, node: ESTree.ObjectExpression) {
    context.report({
        fix(fixer) {
            // Removes the last property of the object:
            return removeObjectProperty(context, fixer, node.properties[index]);
        },
        messageId,
        node: node.properties[index],
    });
}
{
     a: 1,
-    b: 2,
-    c: 3,
+    b: 2
}

Trailing commas are removed so that the fixed code will work regardless of whether the language and location allows them.

Development

See .github/CONTRIBUTING.md, then .github/DEVELOPMENT.md. Thanks! 💖

Contributors

Josh Goldberg ✨
Josh Goldberg ✨

💻 🖋 📖 🤔 🚇 🚧 📆 ⚠️ 🔧 🐛
michael faith
michael faith

💻 🖋 📖 🤔 🚇 🚧 📆 ⚠️ 🔧

💝 This package was templated with create-typescript-app using the create engine.

changelog (log de mudanças)

Changelog

0.2.0 (2025-01-23)

Features

  • empty commit to trigger 0.2.0 (1658b2d)

0.1.0 (2025-01-19)

Features