eslint-fix-utils 0.2.0 โ 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -7
- package/lib/index.cjs +81 -77
- package/lib/index.d.cts +60 -54
- package/lib/index.d.cts.map +1 -0
- package/lib/index.d.ts +60 -54
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +77 -46
- package/lib/index.js.map +1 -1
- package/package.json +36 -30
- package/lib/index.cjs.map +0 -1
package/README.md
CHANGED
|
@@ -8,13 +8,13 @@
|
|
|
8
8
|
<p align="center">
|
|
9
9
|
<!-- prettier-ignore-start -->
|
|
10
10
|
<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
|
|
11
|
-
<a href="#contributors" target="_blank"><img alt="๐ช All Contributors:
|
|
11
|
+
<a href="#contributors" target="_blank"><img alt="๐ช All Contributors: 3" src="https://img.shields.io/badge/%F0%9F%91%AA_all_contributors-3-21bb42.svg" /></a>
|
|
12
12
|
<!-- ALL-CONTRIBUTORS-BADGE:END -->
|
|
13
13
|
<!-- prettier-ignore-end -->
|
|
14
14
|
<a href="https://github.com/JoshuaKGoldberg/eslint-fix-utils/blob/main/.github/CODE_OF_CONDUCT.md" target="_blank"><img alt="๐ค Code of Conduct: Kept" src="https://img.shields.io/badge/%F0%9F%A4%9D_code_of_conduct-kept-21bb42" /></a>
|
|
15
15
|
<a href="https://codecov.io/gh/JoshuaKGoldberg/eslint-fix-utils" target="_blank"><img alt="๐งช Coverage" src="https://img.shields.io/codecov/c/github/JoshuaKGoldberg/eslint-fix-utils?label=%F0%9F%A7%AA%20coverage" /></a>
|
|
16
|
-
<a href="https://github.com/JoshuaKGoldberg/eslint-fix-utils/blob/main/LICENSE.md" target="_blank"><img alt="๐ License: MIT" src="https://img.shields.io/badge/%F0%9F%93%9D_license-MIT-21bb42.svg"
|
|
17
|
-
<a href="http://npmjs.com/package/eslint-fix-utils"><img alt="๐ฆ npm version" src="https://img.shields.io/npm/v/eslint-fix-utils?color=21bb42&label=%F0%9F%93%A6%20npm" /></a>
|
|
16
|
+
<a href="https://github.com/JoshuaKGoldberg/eslint-fix-utils/blob/main/LICENSE.md" target="_blank"><img alt="๐ License: MIT" src="https://img.shields.io/badge/%F0%9F%93%9D_license-MIT-21bb42.svg" /></a>
|
|
17
|
+
<a href="http://npmjs.com/package/eslint-fix-utils" target="_blank"><img alt="๐ฆ npm version" src="https://img.shields.io/npm/v/eslint-fix-utils?color=21bb42&label=%F0%9F%93%A6%20npm" /></a>
|
|
18
18
|
<img alt="๐ช TypeScript: Strict" src="https://img.shields.io/badge/%F0%9F%92%AA_typescript-strict-21bb42.svg" />
|
|
19
19
|
</p>
|
|
20
20
|
|
|
@@ -148,7 +148,7 @@ Trailing commas are removed so that the fixed code will work regardless of wheth
|
|
|
148
148
|
## Development
|
|
149
149
|
|
|
150
150
|
See [`.github/CONTRIBUTING.md`](./.github/CONTRIBUTING.md), then [`.github/DEVELOPMENT.md`](./.github/DEVELOPMENT.md).
|
|
151
|
-
Thanks!
|
|
151
|
+
Thanks! ๐ง
|
|
152
152
|
|
|
153
153
|
## Contributors
|
|
154
154
|
|
|
@@ -159,6 +159,7 @@ Thanks! ๐
|
|
|
159
159
|
<table>
|
|
160
160
|
<tbody>
|
|
161
161
|
<tr>
|
|
162
|
+
<td align="center" valign="top" width="14.28%"><a href="http://azat.io"><img src="https://avatars.githubusercontent.com/u/5698350?v=4?s=100" width="100px;" alt="Azat S."/><br /><sub><b>Azat S.</b></sub></a><br /><a href="#ideas-azat-io" title="Ideas, Planning, & Feedback">๐ค</a></td>
|
|
162
163
|
<td align="center" valign="top" width="14.28%"><a href="http://www.joshuakgoldberg.com/"><img src="https://avatars.githubusercontent.com/u/3335181?v=4?s=100" width="100px;" alt="Josh Goldberg โจ"/><br /><sub><b>Josh Goldberg โจ</b></sub></a><br /><a href="https://github.com/JoshuaKGoldberg/eslint-fix-utils/commits?author=JoshuaKGoldberg" title="Code">๐ป</a> <a href="#content-JoshuaKGoldberg" title="Content">๐</a> <a href="https://github.com/JoshuaKGoldberg/eslint-fix-utils/commits?author=JoshuaKGoldberg" title="Documentation">๐</a> <a href="#ideas-JoshuaKGoldberg" title="Ideas, Planning, & Feedback">๐ค</a> <a href="#infra-JoshuaKGoldberg" title="Infrastructure (Hosting, Build-Tools, etc)">๐</a> <a href="#maintenance-JoshuaKGoldberg" title="Maintenance">๐ง</a> <a href="#projectManagement-JoshuaKGoldberg" title="Project Management">๐</a> <a href="https://github.com/JoshuaKGoldberg/eslint-fix-utils/commits?author=JoshuaKGoldberg" title="Tests">โ ๏ธ</a> <a href="#tool-JoshuaKGoldberg" title="Tools">๐ง</a> <a href="https://github.com/JoshuaKGoldberg/eslint-fix-utils/issues?q=author%3AJoshuaKGoldberg" title="Bug reports">๐</a></td>
|
|
163
164
|
<td align="center" valign="top" width="14.28%"><a href="https://github.com/michaelfaith"><img src="https://avatars.githubusercontent.com/u/8071845?v=4?s=100" width="100px;" alt="michael faith"/><br /><sub><b>michael faith</b></sub></a><br /><a href="https://github.com/JoshuaKGoldberg/eslint-fix-utils/commits?author=michaelfaith" title="Code">๐ป</a> <a href="#content-michaelfaith" title="Content">๐</a> <a href="https://github.com/JoshuaKGoldberg/eslint-fix-utils/commits?author=michaelfaith" title="Documentation">๐</a> <a href="#ideas-michaelfaith" title="Ideas, Planning, & Feedback">๐ค</a> <a href="#infra-michaelfaith" title="Infrastructure (Hosting, Build-Tools, etc)">๐</a> <a href="#maintenance-michaelfaith" title="Maintenance">๐ง</a> <a href="#projectManagement-michaelfaith" title="Project Management">๐</a> <a href="https://github.com/JoshuaKGoldberg/eslint-fix-utils/commits?author=michaelfaith" title="Tests">โ ๏ธ</a> <a href="#tool-michaelfaith" title="Tools">๐ง</a></td>
|
|
164
165
|
</tr>
|
|
@@ -171,6 +172,4 @@ Thanks! ๐
|
|
|
171
172
|
<!-- ALL-CONTRIBUTORS-LIST:END -->
|
|
172
173
|
<!-- spellchecker: enable -->
|
|
173
174
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
> ๐ This package was templated with [`create-typescript-app`](https://github.com/JoshuaKGoldberg/create-typescript-app) using the [`create` engine](https://create.bingo).
|
|
175
|
+
> ๐ This package was templated with [`create-typescript-app`](https://github.com/JoshuaKGoldberg/create-typescript-app) using the [Bingo engine](https://create.bingo).
|
package/lib/index.cjs
CHANGED
|
@@ -1,87 +1,91 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
1
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
2
|
+
//#region src/removeArrayElement.ts
|
|
3
|
+
/**
|
|
4
|
+
* Given an ArrayExpression or the list of elements an ArrayExpression has,
|
|
5
|
+
* the index or node within that array that you want to remove, and a rule fixer,
|
|
6
|
+
* this function yields removals for the node itself, as well as any trailing
|
|
7
|
+
* commas that are no longer necessary.
|
|
8
|
+
* @param context ESLint Rule Context
|
|
9
|
+
* @param fixer Rule fixer
|
|
10
|
+
* @param elementOrIndex The child expression, spread element, or a numeric
|
|
11
|
+
* index of the child
|
|
12
|
+
* @param parentOrElements The array expression node, or its `.elements` array
|
|
13
|
+
* @yields fixer removals for the node itself, as well as any trailing commas
|
|
14
|
+
* that are no longer necessary.
|
|
15
|
+
*/
|
|
31
16
|
function* removeArrayElement(context, fixer, elementOrIndex, parentOrElements) {
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
yield fixer.remove(tokenBefore);
|
|
41
|
-
}
|
|
42
|
-
yield fixer.remove(element);
|
|
43
|
-
if (tokenAfter?.value === ",") {
|
|
44
|
-
yield fixer.remove(tokenAfter);
|
|
45
|
-
}
|
|
17
|
+
const elements = Array.isArray(parentOrElements) ? parentOrElements : parentOrElements.elements;
|
|
18
|
+
const [element, index] = getElementAndIndex(elements, elementOrIndex);
|
|
19
|
+
if (!element) throw new Error("Cannot remove a null (blank) array element.");
|
|
20
|
+
const tokenAfter = context.sourceCode.getTokenAfter(element);
|
|
21
|
+
const tokenBefore = context.sourceCode.getTokenBefore(element);
|
|
22
|
+
if (index > 0 && tokenAfter?.value !== "," && tokenBefore?.value === ",") yield fixer.remove(tokenBefore);
|
|
23
|
+
yield fixer.remove(element);
|
|
24
|
+
if (tokenAfter?.value === ",") yield fixer.remove(tokenAfter);
|
|
46
25
|
}
|
|
47
26
|
function getElementAndIndex(elements, elementOrIndex) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
if (index === -1) {
|
|
53
|
-
throw new Error("Node is not a child of the parent array.");
|
|
54
|
-
}
|
|
55
|
-
return [elements[index], index];
|
|
27
|
+
if (typeof elementOrIndex === "number") return [elements[elementOrIndex], elementOrIndex];
|
|
28
|
+
const index = elements.indexOf(elementOrIndex);
|
|
29
|
+
if (index === -1) throw new Error("Node is not a child of the parent array.");
|
|
30
|
+
return [elements[index], index];
|
|
56
31
|
}
|
|
57
32
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
33
|
+
//#endregion
|
|
34
|
+
//#region src/fixRemoveArrayElement.ts
|
|
35
|
+
/**
|
|
36
|
+
* Given an ArrayExpression or the list of elements an ArrayExpression has, and
|
|
37
|
+
* the index or node within that array that you want to remove, this function
|
|
38
|
+
* returns a fixer function that you can provide to a report descriptor that
|
|
39
|
+
* will remove that node along with any trailing comma.
|
|
40
|
+
* @param context ESLint Rule Context
|
|
41
|
+
* @param elementOrIndex The child expression, spread element, or a numeric
|
|
42
|
+
* index of the child
|
|
43
|
+
* @param parentOrElements The array expression node, or its `.elements` array
|
|
44
|
+
* @returns a fixer function that you can provide to a report descriptor, that
|
|
45
|
+
* removes an element from an array expression, along with any commas that are
|
|
46
|
+
* no longer necessary.
|
|
47
|
+
*/
|
|
48
|
+
const fixRemoveArrayElement = (context, elementOrIndex, parentOrElements) => {
|
|
49
|
+
return (fixer) => removeArrayElement(context, fixer, elementOrIndex, parentOrElements);
|
|
50
|
+
};
|
|
62
51
|
|
|
63
|
-
|
|
52
|
+
//#endregion
|
|
53
|
+
//#region src/removeObjectProperty.ts
|
|
54
|
+
/**
|
|
55
|
+
* Given an ObjectProperty, and a rule fixer, this function yields removals for
|
|
56
|
+
* the node itself, as well as any trailing commas that are no longer necessary.
|
|
57
|
+
* @param context ESLint Rule Context
|
|
58
|
+
* @param fixer Rule fixer
|
|
59
|
+
* @param property The property node
|
|
60
|
+
* @yields fixer removals for the node itself, as well as any trailing commas
|
|
61
|
+
* that are no longer necessary.
|
|
62
|
+
*/
|
|
64
63
|
function* removeObjectProperty(context, fixer, property) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
yield fixer.remove(property);
|
|
71
|
-
if (tokenAfter?.value === ",") {
|
|
72
|
-
yield fixer.remove(tokenAfter);
|
|
73
|
-
}
|
|
64
|
+
const tokenAfter = context.sourceCode.getTokenAfter(property);
|
|
65
|
+
const tokenBefore = context.sourceCode.getTokenBefore(property);
|
|
66
|
+
if (tokenAfter?.value !== "," && tokenBefore?.value === ",") yield fixer.remove(tokenBefore);
|
|
67
|
+
yield fixer.remove(property);
|
|
68
|
+
if (tokenAfter?.value === ",") yield fixer.remove(tokenAfter);
|
|
74
69
|
}
|
|
75
70
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region src/fixRemoveObjectProperty.ts
|
|
73
|
+
/**
|
|
74
|
+
* Given an ObjectProperty, this function returns a fixer function that you can
|
|
75
|
+
* provide to a report descriptor that will remove that node along with any
|
|
76
|
+
* trailing comma.
|
|
77
|
+
* @param context ESLint Rule Context
|
|
78
|
+
* @param property The property node
|
|
79
|
+
* @returns a fixer function that you can provide to a report descriptor, that
|
|
80
|
+
* removes a property from an object expression, along with any commas that
|
|
81
|
+
* are no longer necessary.
|
|
82
|
+
*/
|
|
83
|
+
const fixRemoveObjectProperty = (context, property) => {
|
|
84
|
+
return (fixer) => removeObjectProperty(context, fixer, property);
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
//#endregion
|
|
88
|
+
exports.fixRemoveArrayElement = fixRemoveArrayElement;
|
|
89
|
+
exports.fixRemoveObjectProperty = fixRemoveObjectProperty;
|
|
90
|
+
exports.removeArrayElement = removeArrayElement;
|
|
91
|
+
exports.removeObjectProperty = removeObjectProperty;
|
package/lib/index.d.cts
CHANGED
|
@@ -1,60 +1,66 @@
|
|
|
1
|
-
import { Rule } from
|
|
2
|
-
import * as ESTree from
|
|
1
|
+
import { Rule } from "eslint";
|
|
2
|
+
import * as ESTree$1 from "estree";
|
|
3
|
+
import * as ESTree from "estree";
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
type
|
|
5
|
+
//#region src/removeArrayElement.d.ts
|
|
6
|
+
type ArrayElement = ESTree$1.Expression | ESTree$1.SpreadElement;
|
|
7
|
+
type ArrayElementsOrParent = ESTree$1.ArrayExpression | ESTree$1.ArrayExpression["elements"];
|
|
6
8
|
/**
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
declare function removeArrayElement(context: Rule.RuleContext, fixer: Rule.RuleFixer, elementOrIndex: ArrayElement | number, parentOrElements: ArrayElementsOrParent): Generator<Rule.Fix, void
|
|
20
|
-
|
|
9
|
+
* Given an ArrayExpression or the list of elements an ArrayExpression has,
|
|
10
|
+
* the index or node within that array that you want to remove, and a rule fixer,
|
|
11
|
+
* this function yields removals for the node itself, as well as any trailing
|
|
12
|
+
* commas that are no longer necessary.
|
|
13
|
+
* @param context ESLint Rule Context
|
|
14
|
+
* @param fixer Rule fixer
|
|
15
|
+
* @param elementOrIndex The child expression, spread element, or a numeric
|
|
16
|
+
* index of the child
|
|
17
|
+
* @param parentOrElements The array expression node, or its `.elements` array
|
|
18
|
+
* @yields fixer removals for the node itself, as well as any trailing commas
|
|
19
|
+
* that are no longer necessary.
|
|
20
|
+
*/
|
|
21
|
+
declare function removeArrayElement(context: Rule.RuleContext, fixer: Rule.RuleFixer, elementOrIndex: ArrayElement | number, parentOrElements: ArrayElementsOrParent): Generator<Rule.Fix, void>;
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region src/fixRemoveArrayElement.d.ts
|
|
21
24
|
/**
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
declare
|
|
35
|
-
|
|
25
|
+
* Given an ArrayExpression or the list of elements an ArrayExpression has, and
|
|
26
|
+
* the index or node within that array that you want to remove, this function
|
|
27
|
+
* returns a fixer function that you can provide to a report descriptor that
|
|
28
|
+
* will remove that node along with any trailing comma.
|
|
29
|
+
* @param context ESLint Rule Context
|
|
30
|
+
* @param elementOrIndex The child expression, spread element, or a numeric
|
|
31
|
+
* index of the child
|
|
32
|
+
* @param parentOrElements The array expression node, or its `.elements` array
|
|
33
|
+
* @returns a fixer function that you can provide to a report descriptor, that
|
|
34
|
+
* removes an element from an array expression, along with any commas that are
|
|
35
|
+
* no longer necessary.
|
|
36
|
+
*/
|
|
37
|
+
declare const fixRemoveArrayElement: (context: Rule.RuleContext, elementOrIndex: ArrayElement | number, parentOrElements: ArrayElementsOrParent) => ((fixer: Rule.RuleFixer) => Generator<Rule.Fix, void>);
|
|
38
|
+
//#endregion
|
|
39
|
+
//#region src/removeObjectProperty.d.ts
|
|
36
40
|
type ObjectProperty = ESTree.Property | ESTree.SpreadElement;
|
|
37
41
|
/**
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
declare function removeObjectProperty(context: Rule.RuleContext, fixer: Rule.RuleFixer, property: ObjectProperty): Generator<Rule.Fix, void
|
|
47
|
-
|
|
42
|
+
* Given an ObjectProperty, and a rule fixer, this function yields removals for
|
|
43
|
+
* the node itself, as well as any trailing commas that are no longer necessary.
|
|
44
|
+
* @param context ESLint Rule Context
|
|
45
|
+
* @param fixer Rule fixer
|
|
46
|
+
* @param property The property node
|
|
47
|
+
* @yields fixer removals for the node itself, as well as any trailing commas
|
|
48
|
+
* that are no longer necessary.
|
|
49
|
+
*/
|
|
50
|
+
declare function removeObjectProperty(context: Rule.RuleContext, fixer: Rule.RuleFixer, property: ObjectProperty): Generator<Rule.Fix, void>;
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region src/fixRemoveObjectProperty.d.ts
|
|
48
53
|
/**
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
declare
|
|
59
|
-
|
|
60
|
-
export {
|
|
54
|
+
* Given an ObjectProperty, this function returns a fixer function that you can
|
|
55
|
+
* provide to a report descriptor that will remove that node along with any
|
|
56
|
+
* trailing comma.
|
|
57
|
+
* @param context ESLint Rule Context
|
|
58
|
+
* @param property The property node
|
|
59
|
+
* @returns a fixer function that you can provide to a report descriptor, that
|
|
60
|
+
* removes a property from an object expression, along with any commas that
|
|
61
|
+
* are no longer necessary.
|
|
62
|
+
*/
|
|
63
|
+
declare const fixRemoveObjectProperty: (context: Rule.RuleContext, property: ObjectProperty) => ((fixer: Rule.RuleFixer) => Generator<Rule.Fix, void>);
|
|
64
|
+
//#endregion
|
|
65
|
+
export { ArrayElement, ArrayElementsOrParent, ObjectProperty, fixRemoveArrayElement, fixRemoveObjectProperty, removeArrayElement, removeObjectProperty };
|
|
66
|
+
//# sourceMappingURL=index.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":["context: Rule.RuleContext","fixer: Rule.RuleFixer","elementOrIndex: ArrayElement | number","parentOrElements: ArrayElementsOrParent","context: Rule.RuleContext","elementOrIndex: ArrayElement | number","parentOrElements: ArrayElementsOrParent","fixer: Rule.RuleFixer","context: Rule.RuleContext","fixer: Rule.RuleFixer","property: ObjectProperty","context: Rule.RuleContext","property: ObjectProperty","fixer: Rule.RuleFixer"],"sources":["../src/removeArrayElement.ts","../src/fixRemoveArrayElement.ts","../src/removeObjectProperty.ts","../src/fixRemoveObjectProperty.ts"],"sourcesContent":[],"mappings":";;;;;KAGY,YAAA,GAAe,QAAA,CAAO,aAAa,QAAA,CAAO;KAE1C,qBAAA,GACT,QAAA,CAAO,kBACP,QAAA,CAAO;;AAJV;;;;AAAsD;AAEtD;;;;AAEU;AAeV;;AACU,iBADO,kBAAA,CACF,OAAA,EAAL,IAAA,CAAK,WAAA,EAAA,KAAA,EACP,IAAA,CAAK,SADE,EAAA,cAAA,EAEE,YAFF,GAAA,MAAA,EAAA,gBAAA,EAGI,qBAHJ,CAAA,EAIZ,SAJY,CAIF,IAAA,CAAK,GAJH,EAAA,IAAA,CAAA;;;;;;AApBf;;;;AAAsD;AAEtD;;;;AAEU;AAeO,cCDJ,qBDCI,EAAA,CAAA,OAAA,ECAP,IAAA,CAAK,WDAE,EAAA,cAAA,ECCA,YDDA,GAAA,MAAA,EAAA,gBAAA,ECEE,qBDFF,EAAA,GAAA,CAAA,CAAA,KAAA,ECGL,IAAA,CAAK,SDHA,EAAA,GCGc,SDHd,CCGwB,IAAA,CAAK,GDH7B,EAAA,IAAA,CAAA,CAAA;;;KEnBL,cAAA,GAAiB,MAAA,CAAO,WAAW,MAAA,CAAO;;;AFAtD;;;;AAAsD;AAEtD;;AACG,iBEQc,oBAAA,CFRP,OAAA,EESA,IAAA,CAAK,WFTL,EAAA,KAAA,EEUF,IAAA,CAAK,SFVH,EAAA,QAAA,EEWC,cFXD,CAAA,EEYP,SFZO,CEYG,IAAA,CAAK,GFZR,EAAA,IAAA,CAAA;;;;;;AAHV;;;;AAAsD;AAEtD;;AACG,cGWU,uBHXH,EAAA,CAAA,OAAA,EGYA,IAAA,CAAK,WHZL,EAAA,QAAA,EGaC,cHbD,EAAA,GAAA,CAAA,CAAA,KAAA,EGcE,IAAA,CAAK,SHdP,EAAA,GGcqB,SHdrB,CGc+B,IAAA,CAAK,GHdpC,EAAA,IAAA,CAAA,CAAA"}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,60 +1,66 @@
|
|
|
1
|
-
import { Rule } from
|
|
2
|
-
import * as ESTree from
|
|
1
|
+
import { Rule } from "eslint";
|
|
2
|
+
import * as ESTree$1 from "estree";
|
|
3
|
+
import * as ESTree from "estree";
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
type
|
|
5
|
+
//#region src/removeArrayElement.d.ts
|
|
6
|
+
type ArrayElement = ESTree$1.Expression | ESTree$1.SpreadElement;
|
|
7
|
+
type ArrayElementsOrParent = ESTree$1.ArrayExpression | ESTree$1.ArrayExpression["elements"];
|
|
6
8
|
/**
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
declare function removeArrayElement(context: Rule.RuleContext, fixer: Rule.RuleFixer, elementOrIndex: ArrayElement | number, parentOrElements: ArrayElementsOrParent): Generator<Rule.Fix, void
|
|
20
|
-
|
|
9
|
+
* Given an ArrayExpression or the list of elements an ArrayExpression has,
|
|
10
|
+
* the index or node within that array that you want to remove, and a rule fixer,
|
|
11
|
+
* this function yields removals for the node itself, as well as any trailing
|
|
12
|
+
* commas that are no longer necessary.
|
|
13
|
+
* @param context ESLint Rule Context
|
|
14
|
+
* @param fixer Rule fixer
|
|
15
|
+
* @param elementOrIndex The child expression, spread element, or a numeric
|
|
16
|
+
* index of the child
|
|
17
|
+
* @param parentOrElements The array expression node, or its `.elements` array
|
|
18
|
+
* @yields fixer removals for the node itself, as well as any trailing commas
|
|
19
|
+
* that are no longer necessary.
|
|
20
|
+
*/
|
|
21
|
+
declare function removeArrayElement(context: Rule.RuleContext, fixer: Rule.RuleFixer, elementOrIndex: ArrayElement | number, parentOrElements: ArrayElementsOrParent): Generator<Rule.Fix, void>;
|
|
22
|
+
//#endregion
|
|
23
|
+
//#region src/fixRemoveArrayElement.d.ts
|
|
21
24
|
/**
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
declare
|
|
35
|
-
|
|
25
|
+
* Given an ArrayExpression or the list of elements an ArrayExpression has, and
|
|
26
|
+
* the index or node within that array that you want to remove, this function
|
|
27
|
+
* returns a fixer function that you can provide to a report descriptor that
|
|
28
|
+
* will remove that node along with any trailing comma.
|
|
29
|
+
* @param context ESLint Rule Context
|
|
30
|
+
* @param elementOrIndex The child expression, spread element, or a numeric
|
|
31
|
+
* index of the child
|
|
32
|
+
* @param parentOrElements The array expression node, or its `.elements` array
|
|
33
|
+
* @returns a fixer function that you can provide to a report descriptor, that
|
|
34
|
+
* removes an element from an array expression, along with any commas that are
|
|
35
|
+
* no longer necessary.
|
|
36
|
+
*/
|
|
37
|
+
declare const fixRemoveArrayElement: (context: Rule.RuleContext, elementOrIndex: ArrayElement | number, parentOrElements: ArrayElementsOrParent) => ((fixer: Rule.RuleFixer) => Generator<Rule.Fix, void>);
|
|
38
|
+
//#endregion
|
|
39
|
+
//#region src/removeObjectProperty.d.ts
|
|
36
40
|
type ObjectProperty = ESTree.Property | ESTree.SpreadElement;
|
|
37
41
|
/**
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
declare function removeObjectProperty(context: Rule.RuleContext, fixer: Rule.RuleFixer, property: ObjectProperty): Generator<Rule.Fix, void
|
|
47
|
-
|
|
42
|
+
* Given an ObjectProperty, and a rule fixer, this function yields removals for
|
|
43
|
+
* the node itself, as well as any trailing commas that are no longer necessary.
|
|
44
|
+
* @param context ESLint Rule Context
|
|
45
|
+
* @param fixer Rule fixer
|
|
46
|
+
* @param property The property node
|
|
47
|
+
* @yields fixer removals for the node itself, as well as any trailing commas
|
|
48
|
+
* that are no longer necessary.
|
|
49
|
+
*/
|
|
50
|
+
declare function removeObjectProperty(context: Rule.RuleContext, fixer: Rule.RuleFixer, property: ObjectProperty): Generator<Rule.Fix, void>;
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region src/fixRemoveObjectProperty.d.ts
|
|
48
53
|
/**
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
declare
|
|
59
|
-
|
|
60
|
-
export {
|
|
54
|
+
* Given an ObjectProperty, this function returns a fixer function that you can
|
|
55
|
+
* provide to a report descriptor that will remove that node along with any
|
|
56
|
+
* trailing comma.
|
|
57
|
+
* @param context ESLint Rule Context
|
|
58
|
+
* @param property The property node
|
|
59
|
+
* @returns a fixer function that you can provide to a report descriptor, that
|
|
60
|
+
* removes a property from an object expression, along with any commas that
|
|
61
|
+
* are no longer necessary.
|
|
62
|
+
*/
|
|
63
|
+
declare const fixRemoveObjectProperty: (context: Rule.RuleContext, property: ObjectProperty) => ((fixer: Rule.RuleFixer) => Generator<Rule.Fix, void>);
|
|
64
|
+
//#endregion
|
|
65
|
+
export { ArrayElement, ArrayElementsOrParent, ObjectProperty, fixRemoveArrayElement, fixRemoveObjectProperty, removeArrayElement, removeObjectProperty };
|
|
66
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":["context: Rule.RuleContext","fixer: Rule.RuleFixer","elementOrIndex: ArrayElement | number","parentOrElements: ArrayElementsOrParent","context: Rule.RuleContext","elementOrIndex: ArrayElement | number","parentOrElements: ArrayElementsOrParent","fixer: Rule.RuleFixer","context: Rule.RuleContext","fixer: Rule.RuleFixer","property: ObjectProperty","context: Rule.RuleContext","property: ObjectProperty","fixer: Rule.RuleFixer"],"sources":["../src/removeArrayElement.ts","../src/fixRemoveArrayElement.ts","../src/removeObjectProperty.ts","../src/fixRemoveObjectProperty.ts"],"sourcesContent":[],"mappings":";;;;;KAGY,YAAA,GAAe,QAAA,CAAO,aAAa,QAAA,CAAO;KAE1C,qBAAA,GACT,QAAA,CAAO,kBACP,QAAA,CAAO;;AAJV;;;;AAAsD;AAEtD;;;;AAEU;AAeV;;AACU,iBADO,kBAAA,CACF,OAAA,EAAL,IAAA,CAAK,WAAA,EAAA,KAAA,EACP,IAAA,CAAK,SADE,EAAA,cAAA,EAEE,YAFF,GAAA,MAAA,EAAA,gBAAA,EAGI,qBAHJ,CAAA,EAIZ,SAJY,CAIF,IAAA,CAAK,GAJH,EAAA,IAAA,CAAA;;;;;;AApBf;;;;AAAsD;AAEtD;;;;AAEU;AAeO,cCDJ,qBDCI,EAAA,CAAA,OAAA,ECAP,IAAA,CAAK,WDAE,EAAA,cAAA,ECCA,YDDA,GAAA,MAAA,EAAA,gBAAA,ECEE,qBDFF,EAAA,GAAA,CAAA,CAAA,KAAA,ECGL,IAAA,CAAK,SDHA,EAAA,GCGc,SDHd,CCGwB,IAAA,CAAK,GDH7B,EAAA,IAAA,CAAA,CAAA;;;KEnBL,cAAA,GAAiB,MAAA,CAAO,WAAW,MAAA,CAAO;;;AFAtD;;;;AAAsD;AAEtD;;AACG,iBEQc,oBAAA,CFRP,OAAA,EESA,IAAA,CAAK,WFTL,EAAA,KAAA,EEUF,IAAA,CAAK,SFVH,EAAA,QAAA,EEWC,cFXD,CAAA,EEYP,SFZO,CEYG,IAAA,CAAK,GFZR,EAAA,IAAA,CAAA;;;;;;AAHV;;;;AAAsD;AAEtD;;AACG,cGWU,uBHXH,EAAA,CAAA,OAAA,EGYA,IAAA,CAAK,WHZL,EAAA,QAAA,EGaC,cHbD,EAAA,GAAA,CAAA,CAAA,KAAA,EGcE,IAAA,CAAK,SHdP,EAAA,GGcqB,SHdrB,CGc+B,IAAA,CAAK,GHdpC,EAAA,IAAA,CAAA,CAAA"}
|
package/lib/index.js
CHANGED
|
@@ -1,57 +1,88 @@
|
|
|
1
|
-
|
|
1
|
+
//#region src/removeArrayElement.ts
|
|
2
|
+
/**
|
|
3
|
+
* Given an ArrayExpression or the list of elements an ArrayExpression has,
|
|
4
|
+
* the index or node within that array that you want to remove, and a rule fixer,
|
|
5
|
+
* this function yields removals for the node itself, as well as any trailing
|
|
6
|
+
* commas that are no longer necessary.
|
|
7
|
+
* @param context ESLint Rule Context
|
|
8
|
+
* @param fixer Rule fixer
|
|
9
|
+
* @param elementOrIndex The child expression, spread element, or a numeric
|
|
10
|
+
* index of the child
|
|
11
|
+
* @param parentOrElements The array expression node, or its `.elements` array
|
|
12
|
+
* @yields fixer removals for the node itself, as well as any trailing commas
|
|
13
|
+
* that are no longer necessary.
|
|
14
|
+
*/
|
|
2
15
|
function* removeArrayElement(context, fixer, elementOrIndex, parentOrElements) {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
yield fixer.remove(tokenBefore);
|
|
12
|
-
}
|
|
13
|
-
yield fixer.remove(element);
|
|
14
|
-
if (tokenAfter?.value === ",") {
|
|
15
|
-
yield fixer.remove(tokenAfter);
|
|
16
|
-
}
|
|
16
|
+
const elements = Array.isArray(parentOrElements) ? parentOrElements : parentOrElements.elements;
|
|
17
|
+
const [element, index] = getElementAndIndex(elements, elementOrIndex);
|
|
18
|
+
if (!element) throw new Error("Cannot remove a null (blank) array element.");
|
|
19
|
+
const tokenAfter = context.sourceCode.getTokenAfter(element);
|
|
20
|
+
const tokenBefore = context.sourceCode.getTokenBefore(element);
|
|
21
|
+
if (index > 0 && tokenAfter?.value !== "," && tokenBefore?.value === ",") yield fixer.remove(tokenBefore);
|
|
22
|
+
yield fixer.remove(element);
|
|
23
|
+
if (tokenAfter?.value === ",") yield fixer.remove(tokenAfter);
|
|
17
24
|
}
|
|
18
25
|
function getElementAndIndex(elements, elementOrIndex) {
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
if (index === -1) {
|
|
24
|
-
throw new Error("Node is not a child of the parent array.");
|
|
25
|
-
}
|
|
26
|
-
return [elements[index], index];
|
|
26
|
+
if (typeof elementOrIndex === "number") return [elements[elementOrIndex], elementOrIndex];
|
|
27
|
+
const index = elements.indexOf(elementOrIndex);
|
|
28
|
+
if (index === -1) throw new Error("Node is not a child of the parent array.");
|
|
29
|
+
return [elements[index], index];
|
|
27
30
|
}
|
|
28
31
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
32
|
+
//#endregion
|
|
33
|
+
//#region src/fixRemoveArrayElement.ts
|
|
34
|
+
/**
|
|
35
|
+
* Given an ArrayExpression or the list of elements an ArrayExpression has, and
|
|
36
|
+
* the index or node within that array that you want to remove, this function
|
|
37
|
+
* returns a fixer function that you can provide to a report descriptor that
|
|
38
|
+
* will remove that node along with any trailing comma.
|
|
39
|
+
* @param context ESLint Rule Context
|
|
40
|
+
* @param elementOrIndex The child expression, spread element, or a numeric
|
|
41
|
+
* index of the child
|
|
42
|
+
* @param parentOrElements The array expression node, or its `.elements` array
|
|
43
|
+
* @returns a fixer function that you can provide to a report descriptor, that
|
|
44
|
+
* removes an element from an array expression, along with any commas that are
|
|
45
|
+
* no longer necessary.
|
|
46
|
+
*/
|
|
47
|
+
const fixRemoveArrayElement = (context, elementOrIndex, parentOrElements) => {
|
|
48
|
+
return (fixer) => removeArrayElement(context, fixer, elementOrIndex, parentOrElements);
|
|
49
|
+
};
|
|
33
50
|
|
|
34
|
-
|
|
51
|
+
//#endregion
|
|
52
|
+
//#region src/removeObjectProperty.ts
|
|
53
|
+
/**
|
|
54
|
+
* Given an ObjectProperty, and a rule fixer, this function yields removals for
|
|
55
|
+
* the node itself, as well as any trailing commas that are no longer necessary.
|
|
56
|
+
* @param context ESLint Rule Context
|
|
57
|
+
* @param fixer Rule fixer
|
|
58
|
+
* @param property The property node
|
|
59
|
+
* @yields fixer removals for the node itself, as well as any trailing commas
|
|
60
|
+
* that are no longer necessary.
|
|
61
|
+
*/
|
|
35
62
|
function* removeObjectProperty(context, fixer, property) {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
yield fixer.remove(property);
|
|
42
|
-
if (tokenAfter?.value === ",") {
|
|
43
|
-
yield fixer.remove(tokenAfter);
|
|
44
|
-
}
|
|
63
|
+
const tokenAfter = context.sourceCode.getTokenAfter(property);
|
|
64
|
+
const tokenBefore = context.sourceCode.getTokenBefore(property);
|
|
65
|
+
if (tokenAfter?.value !== "," && tokenBefore?.value === ",") yield fixer.remove(tokenBefore);
|
|
66
|
+
yield fixer.remove(property);
|
|
67
|
+
if (tokenAfter?.value === ",") yield fixer.remove(tokenAfter);
|
|
45
68
|
}
|
|
46
69
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
70
|
+
//#endregion
|
|
71
|
+
//#region src/fixRemoveObjectProperty.ts
|
|
72
|
+
/**
|
|
73
|
+
* Given an ObjectProperty, this function returns a fixer function that you can
|
|
74
|
+
* provide to a report descriptor that will remove that node along with any
|
|
75
|
+
* trailing comma.
|
|
76
|
+
* @param context ESLint Rule Context
|
|
77
|
+
* @param property The property node
|
|
78
|
+
* @returns a fixer function that you can provide to a report descriptor, that
|
|
79
|
+
* removes a property from an object expression, along with any commas that
|
|
80
|
+
* are no longer necessary.
|
|
81
|
+
*/
|
|
82
|
+
const fixRemoveObjectProperty = (context, property) => {
|
|
83
|
+
return (fixer) => removeObjectProperty(context, fixer, property);
|
|
56
84
|
};
|
|
85
|
+
|
|
86
|
+
//#endregion
|
|
87
|
+
export { fixRemoveArrayElement, fixRemoveObjectProperty, removeArrayElement, removeObjectProperty };
|
|
57
88
|
//# sourceMappingURL=index.js.map
|
package/lib/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/removeArrayElement.ts","../src/fixRemoveArrayElement.ts","../src/removeObjectProperty.ts","../src/fixRemoveObjectProperty.ts"],"sourcesContent":["import { Rule } from \"eslint\";\nimport * as ESTree from \"estree\";\n\nexport type ArrayElement = ESTree.Expression | ESTree.SpreadElement;\n\nexport type ArrayElementsOrParent =\n\t| ESTree.ArrayExpression\n\t| ESTree.ArrayExpression[\"elements\"];\n\n/**\n * Given an ArrayExpression or the list of elements an ArrayExpression has,\n * the index or node within that array that you want to remove, and a rule fixer,\n * this function yields removals for the node itself, as well as any trailing\n * commas that are no longer necessary.\n * @param context ESLint Rule Context\n * @param fixer Rule fixer\n * @param elementOrIndex The child expression, spread element, or a numeric\n * index of the child\n * @param parentOrElements The array expression node, or its `.elements` array\n * @yields fixer removals for the node itself, as well as any trailing commas\n * that are no longer necessary.\n */\nexport function* removeArrayElement(\n\tcontext: Rule.RuleContext,\n\tfixer: Rule.RuleFixer,\n\telementOrIndex: ArrayElement | number,\n\tparentOrElements: ArrayElementsOrParent,\n) {\n\tconst elements = Array.isArray(parentOrElements)\n\t\t? parentOrElements\n\t\t: parentOrElements.elements;\n\tconst [element, index] = getElementAndIndex(elements, elementOrIndex);\n\n\tif (!element) {\n\t\tthrow new Error(\"Cannot remove a null (blank) array element.\");\n\t}\n\n\tconst tokenAfter = context.sourceCode.getTokenAfter(element);\n\tconst tokenBefore = context.sourceCode.getTokenBefore(element);\n\n\t// If this is the last line and it's not the only entry, then the line above this one\n\t// will become the last line, and should not have a trailing comma.\n\tif (index > 0 && tokenAfter?.value !== \",\" && tokenBefore?.value === \",\") {\n\t\tyield fixer.remove(tokenBefore);\n\t}\n\n\tyield fixer.remove(element);\n\n\t// If this is not the last entry, then we need to remove the comma from this line.\n\tif (tokenAfter?.value === \",\") {\n\t\tyield fixer.remove(tokenAfter);\n\t}\n}\n\nfunction getElementAndIndex(\n\telements: (ArrayElement | null)[],\n\telementOrIndex: ArrayElement | number,\n) {\n\tif (typeof elementOrIndex === \"number\") {\n\t\treturn [elements[elementOrIndex], elementOrIndex] as const;\n\t}\n\n\tconst index = elements.indexOf(elementOrIndex);\n\n\tif (index === -1) {\n\t\tthrow new Error(\"Node is not a child of the parent array.\");\n\t}\n\n\treturn [elements[index], index] as const;\n}\n","import { Rule } from \"eslint\";\n\nimport {\n\
|
|
1
|
+
{"version":3,"file":"index.js","names":["context: Rule.RuleContext","fixer: Rule.RuleFixer","elementOrIndex: ArrayElement | number","parentOrElements: ArrayElementsOrParent","elements: (ArrayElement | null)[]","context: Rule.RuleContext","elementOrIndex: ArrayElement | number","parentOrElements: ArrayElementsOrParent","fixer: Rule.RuleFixer","context: Rule.RuleContext","fixer: Rule.RuleFixer","property: ObjectProperty","context: Rule.RuleContext","property: ObjectProperty","fixer: Rule.RuleFixer"],"sources":["../src/removeArrayElement.ts","../src/fixRemoveArrayElement.ts","../src/removeObjectProperty.ts","../src/fixRemoveObjectProperty.ts"],"sourcesContent":["import type { Rule } from \"eslint\";\nimport type * as ESTree from \"estree\";\n\nexport type ArrayElement = ESTree.Expression | ESTree.SpreadElement;\n\nexport type ArrayElementsOrParent =\n\t| ESTree.ArrayExpression\n\t| ESTree.ArrayExpression[\"elements\"];\n\n/**\n * Given an ArrayExpression or the list of elements an ArrayExpression has,\n * the index or node within that array that you want to remove, and a rule fixer,\n * this function yields removals for the node itself, as well as any trailing\n * commas that are no longer necessary.\n * @param context ESLint Rule Context\n * @param fixer Rule fixer\n * @param elementOrIndex The child expression, spread element, or a numeric\n * index of the child\n * @param parentOrElements The array expression node, or its `.elements` array\n * @yields fixer removals for the node itself, as well as any trailing commas\n * that are no longer necessary.\n */\nexport function* removeArrayElement(\n\tcontext: Rule.RuleContext,\n\tfixer: Rule.RuleFixer,\n\telementOrIndex: ArrayElement | number,\n\tparentOrElements: ArrayElementsOrParent,\n): Generator<Rule.Fix, void> {\n\tconst elements = Array.isArray(parentOrElements)\n\t\t? parentOrElements\n\t\t: parentOrElements.elements;\n\tconst [element, index] = getElementAndIndex(elements, elementOrIndex);\n\n\tif (!element) {\n\t\tthrow new Error(\"Cannot remove a null (blank) array element.\");\n\t}\n\n\tconst tokenAfter = context.sourceCode.getTokenAfter(element);\n\tconst tokenBefore = context.sourceCode.getTokenBefore(element);\n\n\t// If this is the last line and it's not the only entry, then the line above this one\n\t// will become the last line, and should not have a trailing comma.\n\tif (index > 0 && tokenAfter?.value !== \",\" && tokenBefore?.value === \",\") {\n\t\tyield fixer.remove(tokenBefore);\n\t}\n\n\tyield fixer.remove(element);\n\n\t// If this is not the last entry, then we need to remove the comma from this line.\n\tif (tokenAfter?.value === \",\") {\n\t\tyield fixer.remove(tokenAfter);\n\t}\n}\n\nfunction getElementAndIndex(\n\telements: (ArrayElement | null)[],\n\telementOrIndex: ArrayElement | number,\n) {\n\tif (typeof elementOrIndex === \"number\") {\n\t\treturn [elements[elementOrIndex], elementOrIndex] as const;\n\t}\n\n\tconst index = elements.indexOf(elementOrIndex);\n\n\tif (index === -1) {\n\t\tthrow new Error(\"Node is not a child of the parent array.\");\n\t}\n\n\treturn [elements[index], index] as const;\n}\n","import type { Rule } from \"eslint\";\n\nimport {\n\ttype ArrayElement,\n\ttype ArrayElementsOrParent,\n\tremoveArrayElement,\n} from \"./removeArrayElement\";\n\n/**\n * Given an ArrayExpression or the list of elements an ArrayExpression has, and\n * the index or node within that array that you want to remove, this function\n * returns a fixer function that you can provide to a report descriptor that\n * will remove that node along with any trailing comma.\n * @param context ESLint Rule Context\n * @param elementOrIndex The child expression, spread element, or a numeric\n * index of the child\n * @param parentOrElements The array expression node, or its `.elements` array\n * @returns a fixer function that you can provide to a report descriptor, that\n * removes an element from an array expression, along with any commas that are\n * no longer necessary.\n */\nexport const fixRemoveArrayElement = (\n\tcontext: Rule.RuleContext,\n\telementOrIndex: ArrayElement | number,\n\tparentOrElements: ArrayElementsOrParent,\n): ((fixer: Rule.RuleFixer) => Generator<Rule.Fix, void>) => {\n\treturn (fixer: Rule.RuleFixer) =>\n\t\tremoveArrayElement(context, fixer, elementOrIndex, parentOrElements);\n};\n","import type { Rule } from \"eslint\";\nimport type * as ESTree from \"estree\";\n\nexport type ObjectProperty = ESTree.Property | ESTree.SpreadElement;\n\n/**\n * Given an ObjectProperty, and a rule fixer, this function yields removals for\n * the node itself, as well as any trailing commas that are no longer necessary.\n * @param context ESLint Rule Context\n * @param fixer Rule fixer\n * @param property The property node\n * @yields fixer removals for the node itself, as well as any trailing commas\n * that are no longer necessary.\n */\nexport function* removeObjectProperty(\n\tcontext: Rule.RuleContext,\n\tfixer: Rule.RuleFixer,\n\tproperty: ObjectProperty,\n): Generator<Rule.Fix, void> {\n\tconst tokenAfter = context.sourceCode.getTokenAfter(property);\n\tconst tokenBefore = context.sourceCode.getTokenBefore(property);\n\n\t// If this is not the only entry, then the line above this one\n\t// will become the last line, and should not have a trailing comma.\n\tif (tokenAfter?.value !== \",\" && tokenBefore?.value === \",\") {\n\t\tyield fixer.remove(tokenBefore);\n\t}\n\n\tyield fixer.remove(property);\n\n\t// If this is not the last entry, then we need to remove the comma from this line.\n\tif (tokenAfter?.value === \",\") {\n\t\tyield fixer.remove(tokenAfter);\n\t}\n}\n","import type { Rule } from \"eslint\";\n\nimport {\n\ttype ObjectProperty,\n\tremoveObjectProperty,\n} from \"./removeObjectProperty\";\n\n/**\n * Given an ObjectProperty, this function returns a fixer function that you can\n * provide to a report descriptor that will remove that node along with any\n * trailing comma.\n * @param context ESLint Rule Context\n * @param property The property node\n * @returns a fixer function that you can provide to a report descriptor, that\n * removes a property from an object expression, along with any commas that\n * are no longer necessary.\n */\nexport const fixRemoveObjectProperty = (\n\tcontext: Rule.RuleContext,\n\tproperty: ObjectProperty,\n): ((fixer: Rule.RuleFixer) => Generator<Rule.Fix, void>) => {\n\treturn (fixer: Rule.RuleFixer) =>\n\t\tremoveObjectProperty(context, fixer, property);\n};\n"],"mappings":";;;;;;;;;;;;;;AAsBA,UAAiB,mBAChBA,SACAC,OACAC,gBACAC,kBAC4B;CAC5B,MAAM,WAAW,MAAM,QAAQ,iBAAiB,GAC7C,mBACA,iBAAiB;CACpB,MAAM,CAAC,SAAS,MAAM,GAAG,mBAAmB,UAAU,eAAe;AAErE,MAAK,QACJ,OAAM,IAAI,MAAM;CAGjB,MAAM,aAAa,QAAQ,WAAW,cAAc,QAAQ;CAC5D,MAAM,cAAc,QAAQ,WAAW,eAAe,QAAQ;AAI9D,KAAI,QAAQ,KAAK,YAAY,UAAU,OAAO,aAAa,UAAU,IACpE,OAAM,MAAM,OAAO,YAAY;AAGhC,OAAM,MAAM,OAAO,QAAQ;AAG3B,KAAI,YAAY,UAAU,IACzB,OAAM,MAAM,OAAO,WAAW;AAE/B;AAED,SAAS,mBACRC,UACAF,gBACC;AACD,YAAW,mBAAmB,SAC7B,QAAO,CAAC,SAAS,iBAAiB,cAAe;CAGlD,MAAM,QAAQ,SAAS,QAAQ,eAAe;AAE9C,KAAI,UAAU,GACb,OAAM,IAAI,MAAM;AAGjB,QAAO,CAAC,SAAS,QAAQ,KAAM;AAC/B;;;;;;;;;;;;;;;;;AChDD,MAAa,wBAAwB,CACpCG,SACAC,gBACAC,qBAC4D;AAC5D,QAAO,CAACC,UACP,mBAAmB,SAAS,OAAO,gBAAgB,iBAAiB;AACrE;;;;;;;;;;;;;ACdD,UAAiB,qBAChBC,SACAC,OACAC,UAC4B;CAC5B,MAAM,aAAa,QAAQ,WAAW,cAAc,SAAS;CAC7D,MAAM,cAAc,QAAQ,WAAW,eAAe,SAAS;AAI/D,KAAI,YAAY,UAAU,OAAO,aAAa,UAAU,IACvD,OAAM,MAAM,OAAO,YAAY;AAGhC,OAAM,MAAM,OAAO,SAAS;AAG5B,KAAI,YAAY,UAAU,IACzB,OAAM,MAAM,OAAO,WAAW;AAE/B;;;;;;;;;;;;;;ACjBD,MAAa,0BAA0B,CACtCC,SACAC,aAC4D;AAC5D,QAAO,CAACC,UACP,qBAAqB,SAAS,OAAO,SAAS;AAC/C"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-fix-utils",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Utilities for ESLint rule fixers and suggestions. ๐งโ๐ง",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
"package.json"
|
|
33
33
|
],
|
|
34
34
|
"scripts": {
|
|
35
|
-
"build": "
|
|
35
|
+
"build": "tsdown",
|
|
36
36
|
"format": "prettier .",
|
|
37
37
|
"lint": "eslint . --max-warnings 0",
|
|
38
38
|
"lint:knip": "knip",
|
|
@@ -47,48 +47,54 @@
|
|
|
47
47
|
"*": "prettier --ignore-unknown --write"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"@eslint-community/eslint-plugin-eslint-comments": "4.
|
|
51
|
-
"@eslint/js": "9.
|
|
50
|
+
"@eslint-community/eslint-plugin-eslint-comments": "4.5.0",
|
|
51
|
+
"@eslint/js": "9.28.0",
|
|
52
52
|
"@release-it/conventional-changelog": "10.0.0",
|
|
53
53
|
"@types/eslint-plugin-markdown": "2.0.2",
|
|
54
54
|
"@types/estree": "1.0.6",
|
|
55
|
-
"@types/node": "22.
|
|
56
|
-
"@vitest/coverage-v8": "2.
|
|
57
|
-
"@vitest/eslint-plugin": "1.
|
|
55
|
+
"@types/node": "22.15.0",
|
|
56
|
+
"@vitest/coverage-v8": "3.2.0",
|
|
57
|
+
"@vitest/eslint-plugin": "1.2.0",
|
|
58
58
|
"console-fail-test": "0.5.0",
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"eslint
|
|
62
|
-
"eslint-plugin-
|
|
59
|
+
"create-typescript-app": "2.42.0",
|
|
60
|
+
"cspell": "9.0.0",
|
|
61
|
+
"eslint": "9.28.0",
|
|
62
|
+
"eslint-plugin-jsdoc": "50.7.0",
|
|
63
|
+
"eslint-plugin-jsonc": "2.20.0",
|
|
63
64
|
"eslint-plugin-markdown": "5.1.0",
|
|
64
|
-
"eslint-plugin-n": "17.
|
|
65
|
-
"eslint-plugin-package-json": "0.
|
|
66
|
-
"eslint-plugin-perfectionist": "4.
|
|
67
|
-
"eslint-plugin-regexp": "2.
|
|
68
|
-
"eslint-plugin-yml": "1.
|
|
65
|
+
"eslint-plugin-n": "17.16.2",
|
|
66
|
+
"eslint-plugin-package-json": "0.33.0",
|
|
67
|
+
"eslint-plugin-perfectionist": "4.14.0",
|
|
68
|
+
"eslint-plugin-regexp": "2.8.0",
|
|
69
|
+
"eslint-plugin-yml": "1.18.0",
|
|
69
70
|
"husky": "9.1.7",
|
|
70
|
-
"knip": "5.
|
|
71
|
-
"lint-staged": "
|
|
72
|
-
"markdownlint": "0.
|
|
73
|
-
"markdownlint-cli": "0.
|
|
74
|
-
"prettier": "3.
|
|
71
|
+
"knip": "5.59.0",
|
|
72
|
+
"lint-staged": "16.1.0",
|
|
73
|
+
"markdownlint": "0.38.0",
|
|
74
|
+
"markdownlint-cli": "0.45.0",
|
|
75
|
+
"prettier": "3.5.3",
|
|
75
76
|
"prettier-plugin-curly": "0.3.1",
|
|
76
|
-
"prettier-plugin-packagejson": "2.5.
|
|
77
|
-
"prettier-plugin-sh": "0.
|
|
78
|
-
"release-it": "
|
|
77
|
+
"prettier-plugin-packagejson": "2.5.10",
|
|
78
|
+
"prettier-plugin-sh": "0.17.0",
|
|
79
|
+
"release-it": "19.0.1",
|
|
79
80
|
"sentences-per-line": "0.3.0",
|
|
80
|
-
"
|
|
81
|
-
"typescript": "5.
|
|
82
|
-
"typescript-eslint": "8.
|
|
83
|
-
"vitest": "2.
|
|
81
|
+
"tsdown": "0.12.0",
|
|
82
|
+
"typescript": "5.8.2",
|
|
83
|
+
"typescript-eslint": "8.33.0",
|
|
84
|
+
"vitest": "3.2.0"
|
|
84
85
|
},
|
|
85
86
|
"peerDependencies": {
|
|
86
87
|
"@types/estree": ">=1",
|
|
87
88
|
"eslint": ">=8"
|
|
88
89
|
},
|
|
89
|
-
"
|
|
90
|
+
"peerDependenciesMeta": {
|
|
91
|
+
"@types/estree": {
|
|
92
|
+
"optional": true
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
"packageManager": "pnpm@10.11.0",
|
|
90
96
|
"engines": {
|
|
91
|
-
"node": ">=
|
|
97
|
+
"node": "^20.19.0 || >=22.12.0"
|
|
92
98
|
},
|
|
93
99
|
"publishConfig": {
|
|
94
100
|
"provenance": true
|
package/lib/index.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/removeArrayElement.ts","../src/fixRemoveArrayElement.ts","../src/removeObjectProperty.ts","../src/fixRemoveObjectProperty.ts"],"sourcesContent":["export * from \"./fixRemoveArrayElement\";\nexport * from \"./fixRemoveObjectProperty\";\nexport * from \"./removeArrayElement\";\nexport * from \"./removeObjectProperty\";\n","import { Rule } from \"eslint\";\nimport * as ESTree from \"estree\";\n\nexport type ArrayElement = ESTree.Expression | ESTree.SpreadElement;\n\nexport type ArrayElementsOrParent =\n\t| ESTree.ArrayExpression\n\t| ESTree.ArrayExpression[\"elements\"];\n\n/**\n * Given an ArrayExpression or the list of elements an ArrayExpression has,\n * the index or node within that array that you want to remove, and a rule fixer,\n * this function yields removals for the node itself, as well as any trailing\n * commas that are no longer necessary.\n * @param context ESLint Rule Context\n * @param fixer Rule fixer\n * @param elementOrIndex The child expression, spread element, or a numeric\n * index of the child\n * @param parentOrElements The array expression node, or its `.elements` array\n * @yields fixer removals for the node itself, as well as any trailing commas\n * that are no longer necessary.\n */\nexport function* removeArrayElement(\n\tcontext: Rule.RuleContext,\n\tfixer: Rule.RuleFixer,\n\telementOrIndex: ArrayElement | number,\n\tparentOrElements: ArrayElementsOrParent,\n) {\n\tconst elements = Array.isArray(parentOrElements)\n\t\t? parentOrElements\n\t\t: parentOrElements.elements;\n\tconst [element, index] = getElementAndIndex(elements, elementOrIndex);\n\n\tif (!element) {\n\t\tthrow new Error(\"Cannot remove a null (blank) array element.\");\n\t}\n\n\tconst tokenAfter = context.sourceCode.getTokenAfter(element);\n\tconst tokenBefore = context.sourceCode.getTokenBefore(element);\n\n\t// If this is the last line and it's not the only entry, then the line above this one\n\t// will become the last line, and should not have a trailing comma.\n\tif (index > 0 && tokenAfter?.value !== \",\" && tokenBefore?.value === \",\") {\n\t\tyield fixer.remove(tokenBefore);\n\t}\n\n\tyield fixer.remove(element);\n\n\t// If this is not the last entry, then we need to remove the comma from this line.\n\tif (tokenAfter?.value === \",\") {\n\t\tyield fixer.remove(tokenAfter);\n\t}\n}\n\nfunction getElementAndIndex(\n\telements: (ArrayElement | null)[],\n\telementOrIndex: ArrayElement | number,\n) {\n\tif (typeof elementOrIndex === \"number\") {\n\t\treturn [elements[elementOrIndex], elementOrIndex] as const;\n\t}\n\n\tconst index = elements.indexOf(elementOrIndex);\n\n\tif (index === -1) {\n\t\tthrow new Error(\"Node is not a child of the parent array.\");\n\t}\n\n\treturn [elements[index], index] as const;\n}\n","import { Rule } from \"eslint\";\n\nimport {\n\tArrayElement,\n\tArrayElementsOrParent,\n\tremoveArrayElement,\n} from \"./removeArrayElement\";\n\n/**\n * Given an ArrayExpression or the list of elements an ArrayExpression has, and\n * the index or node within that array that you want to remove, this function\n * returns a fixer function that you can provide to a report descriptor that\n * will remove that node along with any trailing comma.\n * @param context ESLint Rule Context\n * @param elementOrIndex The child expression, spread element, or a numeric\n * index of the child\n * @param parentOrElements The array expression node, or its `.elements` array\n * @returns a fixer function that you can provide to a report descriptor, that\n * removes an element from an array expression, along with any commas that are\n * no longer necessary.\n */\nexport function fixRemoveArrayElement(\n\tcontext: Rule.RuleContext,\n\telementOrIndex: ArrayElement | number,\n\tparentOrElements: ArrayElementsOrParent,\n) {\n\treturn (fixer: Rule.RuleFixer) =>\n\t\tremoveArrayElement(context, fixer, elementOrIndex, parentOrElements);\n}\n","import { Rule } from \"eslint\";\nimport * as ESTree from \"estree\";\n\nexport type ObjectProperty = ESTree.Property | ESTree.SpreadElement;\n\n/**\n * Given an ObjectProperty, and a rule fixer, this function yields removals for\n * the node itself, as well as any trailing commas that are no longer necessary.\n * @param context ESLint Rule Context\n * @param fixer Rule fixer\n * @param property The property node\n * @yields fixer removals for the node itself, as well as any trailing commas\n * that are no longer necessary.\n */\nexport function* removeObjectProperty(\n\tcontext: Rule.RuleContext,\n\tfixer: Rule.RuleFixer,\n\tproperty: ObjectProperty,\n) {\n\tconst tokenAfter = context.sourceCode.getTokenAfter(property);\n\tconst tokenBefore = context.sourceCode.getTokenBefore(property);\n\n\t// If this is not the only entry, then the line above this one\n\t// will become the last line, and should not have a trailing comma.\n\tif (tokenAfter?.value !== \",\" && tokenBefore?.value === \",\") {\n\t\tyield fixer.remove(tokenBefore);\n\t}\n\n\tyield fixer.remove(property);\n\n\t// If this is not the last entry, then we need to remove the comma from this line.\n\tif (tokenAfter?.value === \",\") {\n\t\tyield fixer.remove(tokenAfter);\n\t}\n}\n","import { Rule } from \"eslint\";\n\nimport { ObjectProperty, removeObjectProperty } from \"./removeObjectProperty\";\n\n/**\n * Given an ObjectProperty, this function returns a fixer function that you can\n * provide to a report descriptor that will remove that node along with any\n * trailing comma.\n * @param context ESLint Rule Context\n * @param property The property node\n * @returns a fixer function that you can provide to a report descriptor, that\n * removes a property from an object expression, along with any commas that\n * are no longer necessary.\n */\nexport function fixRemoveObjectProperty(\n\tcontext: Rule.RuleContext,\n\tproperty: ObjectProperty,\n) {\n\treturn (fixer: Rule.RuleFixer) =>\n\t\tremoveObjectProperty(context, fixer, property);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACsBO,UAAU,mBAChB,SACA,OACA,gBACA,kBACC;AACD,QAAM,WAAW,MAAM,QAAQ,gBAAgB,IAC5C,mBACA,iBAAiB;AACpB,QAAM,CAAC,SAAS,KAAK,IAAI,mBAAmB,UAAU,cAAc;AAEpE,MAAI,CAAC,SAAS;AACb,UAAM,IAAI,MAAM,6CAA6C;AAAA,EAC9D;AAEA,QAAM,aAAa,QAAQ,WAAW,cAAc,OAAO;AAC3D,QAAM,cAAc,QAAQ,WAAW,eAAe,OAAO;AAI7D,MAAI,QAAQ,KAAK,YAAY,UAAU,OAAO,aAAa,UAAU,KAAK;AACzE,UAAM,MAAM,OAAO,WAAW;AAAA,EAC/B;AAEA,QAAM,MAAM,OAAO,OAAO;AAG1B,MAAI,YAAY,UAAU,KAAK;AAC9B,UAAM,MAAM,OAAO,UAAU;AAAA,EAC9B;AACD;AAEA,SAAS,mBACR,UACA,gBACC;AACD,MAAI,OAAO,mBAAmB,UAAU;AACvC,WAAO,CAAC,SAAS,cAAc,GAAG,cAAc;AAAA,EACjD;AAEA,QAAM,QAAQ,SAAS,QAAQ,cAAc;AAE7C,MAAI,UAAU,IAAI;AACjB,UAAM,IAAI,MAAM,0CAA0C;AAAA,EAC3D;AAEA,SAAO,CAAC,SAAS,KAAK,GAAG,KAAK;AAC/B;;;AChDO,SAAS,sBACf,SACA,gBACA,kBACC;AACD,SAAO,CAAC,UACP,mBAAmB,SAAS,OAAO,gBAAgB,gBAAgB;AACrE;;;ACdO,UAAU,qBAChB,SACA,OACA,UACC;AACD,QAAM,aAAa,QAAQ,WAAW,cAAc,QAAQ;AAC5D,QAAM,cAAc,QAAQ,WAAW,eAAe,QAAQ;AAI9D,MAAI,YAAY,UAAU,OAAO,aAAa,UAAU,KAAK;AAC5D,UAAM,MAAM,OAAO,WAAW;AAAA,EAC/B;AAEA,QAAM,MAAM,OAAO,QAAQ;AAG3B,MAAI,YAAY,UAAU,KAAK;AAC9B,UAAM,MAAM,OAAO,UAAU;AAAA,EAC9B;AACD;;;ACpBO,SAAS,wBACf,SACA,UACC;AACD,SAAO,CAAC,UACP,qBAAqB,SAAS,OAAO,QAAQ;AAC/C;","names":[]}
|