Utilities for ESLint rule fixers and suggestions. π§βπ§
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.
Version of removeArrayElement
that can be passed directly as a fix
property.
import { fixRemoveArrayElement } from "eslint-fix-utils";
// ...
export function report(node: ESTree.ArrayExpression) {
context.report({
fix: fixRemoveArrayElement(context, node, node.elements.length - 1),
messageId,
node,
});
}
Version of removeObjectProperty
that can be passed directly as a fix
property.
import { fixRemoveObjectProperty } from "eslint-fix-utils";
// ...
export function report(node: ESTree.ArrayExpression) {
context.report({
fix: fixRemoveObjectProperty(context, node, node.elements.length - 1),
messageId,
node,
});
}
Removes an element from an array expression, along with any commas that are no longer necessary.
Parameters:
context
fixer
elementOrIndex
: the child expression, spread element, or a numeric index of the childparentOrElements
: the array expression node, or its.elements
array
import { removeArrayElement } from "eslint-fix-utils";
// ...
export function report(node: ESTree.ArrayExpression) {
context.report({
fix(fixer) {
// Removes the last element of the array:
return removeArrayElement(context, fixer, node, node.elements.length - 1);
},
messageId,
node,
});
}
[
'a',
- 'b',
- 'c'
+ 'b'
]
Trailing commas are removed so that the fixed code will work regardless of whether the language and location allows them.
Removes a property from an object expression, along with any commas that are no longer necessary.
Parameters:
context
fixer
property
: the property node
import { removeObjectProperty } from "eslint-fix-utils";
// ...
export function report(node: ESTree.ObjectExpression) {
context.report({
fix(fixer) {
// Removes the last property of the object:
return removeObjectProperty(context, fixer, node.properties.length - 1);
},
messageId,
node,
});
}
{
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.
See .github/CONTRIBUTING.md
, then .github/DEVELOPMENT.md
.
Thanks! π
Josh Goldberg β¨ π» π π π€ π π§ π |
michael faith π» π π π€ π π§ π |
π This package was templated with
create-typescript-app
using thecreate
engine.