eslint-fix-utils 0.4.0 → 0.4.2

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/CHANGELOG.md CHANGED
@@ -1,37 +1,50 @@
1
1
  # Changelog
2
2
 
3
- # [0.4.0](https://github.com/JoshuaKGoldberg/eslint-fix-utils/compare/0.3.0...0.4.0) (2025-06-12)
3
+ # [0.4.0](https://github.com/michaelfaith/eslint-fix-utils/compare/0.3.0...0.4.0) (2025-06-12)
4
4
 
5
+ ### Features
6
+
7
+ - bundle esm-only ([#170](https://github.com/michaelfaith/eslint-fix-utils/issues/170)) ([62e4938](https://github.com/michaelfaith/eslint-fix-utils/commit/62e4938aa6e67db31611e59b6fe19692069a56de)), closes [#167](https://github.com/michaelfaith/eslint-fix-utils/issues/167)
8
+
9
+ # [0.3.0](https://github.com/michaelfaith/eslint-fix-utils/compare/0.2.1...0.3.0) (2025-06-11)
10
+
11
+ ### Bug Fixes
12
+
13
+ - bump to create-typescript-app@2 with transitions action ([#79](https://github.com/michaelfaith/eslint-fix-utils/issues/79)) ([0bb023f](https://github.com/michaelfaith/eslint-fix-utils/commit/0bb023f96c18632b1c688d3210ae2567cee4b8e0)), closes [#75](https://github.com/michaelfaith/eslint-fix-utils/issues/75)
5
14
 
6
15
  ### Features
7
16
 
8
- * bundle esm-only ([#170](https://github.com/JoshuaKGoldberg/eslint-fix-utils/issues/170)) ([62e4938](https://github.com/JoshuaKGoldberg/eslint-fix-utils/commit/62e4938aa6e67db31611e59b6fe19692069a56de)), closes [#167](https://github.com/JoshuaKGoldberg/eslint-fix-utils/issues/167)
17
+ - remove support for node 18 ([#169](https://github.com/michaelfaith/eslint-fix-utils/issues/169)) ([1b076be](https://github.com/michaelfaith/eslint-fix-utils/commit/1b076be4533fc4e91e6c7af430ea2c597eb6d87b)), closes [#166](https://github.com/michaelfaith/eslint-fix-utils/issues/166)
18
+
19
+ ## [0.4.2](https://github.com/michaelfaith/eslint-fix-utils/compare/v0.4.1...v0.4.2) (2026-03-01)
9
20
 
10
- # [0.3.0](https://github.com/JoshuaKGoldberg/eslint-fix-utils/compare/0.2.1...0.3.0) (2025-06-11)
11
21
 
12
22
  ### Bug Fixes
13
23
 
14
- - bump to create-typescript-app@2 with transitions action ([#79](https://github.com/JoshuaKGoldberg/eslint-fix-utils/issues/79)) ([0bb023f](https://github.com/JoshuaKGoldberg/eslint-fix-utils/commit/0bb023f96c18632b1c688d3210ae2567cee4b8e0)), closes [#75](https://github.com/JoshuaKGoldberg/eslint-fix-utils/issues/75)
24
+ * update repo references ([#430](https://github.com/michaelfaith/eslint-fix-utils/issues/430)) ([60ee8aa](https://github.com/michaelfaith/eslint-fix-utils/commit/60ee8aab7989ab4f904c7fe98e9169061530de5d))
25
+
26
+ ## [0.4.1](https://github.com/michaelfaith/eslint-fix-utils/compare/0.4.0...v0.4.1) (2026-02-01)
27
+
15
28
 
16
29
  ### Features
17
30
 
18
- - remove support for node 18 ([#169](https://github.com/JoshuaKGoldberg/eslint-fix-utils/issues/169)) ([1b076be](https://github.com/JoshuaKGoldberg/eslint-fix-utils/commit/1b076be4533fc4e91e6c7af430ea2c597eb6d87b)), closes [#166](https://github.com/JoshuaKGoldberg/eslint-fix-utils/issues/166)
31
+ * add functions for adding a new property to an object ([#399](https://github.com/michaelfaith/eslint-fix-utils/issues/399)) ([47daa1b](https://github.com/michaelfaith/eslint-fix-utils/commit/47daa1be7da85f7939573057c6a649aa35cfdd77))
19
32
 
20
- ## [0.2.1](https://github.com/JoshuaKGoldberg/eslint-fix-utils/compare/0.2.0...0.2.1) (2025-01-28)
33
+ ## [0.2.1](https://github.com/michaelfaith/eslint-fix-utils/compare/0.2.0...0.2.1) (2025-01-28)
21
34
 
22
35
  ### Bug Fixes
23
36
 
24
- - make `@types/estree` peer dependency optional ([#25](https://github.com/JoshuaKGoldberg/eslint-fix-utils/issues/25)) ([f6ddd9d](https://github.com/JoshuaKGoldberg/eslint-fix-utils/commit/f6ddd9d20de032992202d9287be3c7abee4f0d15)), closes [#24](https://github.com/JoshuaKGoldberg/eslint-fix-utils/issues/24)
37
+ - make `@types/estree` peer dependency optional ([#25](https://github.com/michaelfaith/eslint-fix-utils/issues/25)) ([f6ddd9d](https://github.com/michaelfaith/eslint-fix-utils/commit/f6ddd9d20de032992202d9287be3c7abee4f0d15)), closes [#24](https://github.com/michaelfaith/eslint-fix-utils/issues/24)
25
38
 
26
- # [0.2.0](https://github.com/JoshuaKGoldberg/eslint-fix-utils/compare/0.1.0...0.2.0) (2025-01-23)
39
+ # [0.2.0](https://github.com/michaelfaith/eslint-fix-utils/compare/0.1.0...0.2.0) (2025-01-23)
27
40
 
28
41
  ### Features
29
42
 
30
- - empty commit to trigger 0.2.0 ([1658b2d](https://github.com/JoshuaKGoldberg/eslint-fix-utils/commit/1658b2d849fe9f636f24f154831ad8eeecb5721c))
43
+ - empty commit to trigger 0.2.0 ([1658b2d](https://github.com/michaelfaith/eslint-fix-utils/commit/1658b2d849fe9f636f24f154831ad8eeecb5721c))
31
44
 
32
45
  # 0.1.0 (2025-01-19)
33
46
 
34
47
  ### Features
35
48
 
36
- - initial functionality ✨ ([6bf5c33](https://github.com/JoshuaKGoldberg/eslint-fix-utils/commit/6bf5c3329eb47c43d38128328fd4501277b3c8ad))
37
- - initialized repo ✨ ([31c7630](https://github.com/JoshuaKGoldberg/eslint-fix-utils/commit/31c7630c769a8a57b9be85247c6546baceae82f2))
49
+ - initial functionality ✨ ([6bf5c33](https://github.com/michaelfaith/eslint-fix-utils/commit/6bf5c3329eb47c43d38128328fd4501277b3c8ad))
50
+ - initialized repo ✨ ([31c7630](https://github.com/michaelfaith/eslint-fix-utils/commit/31c7630c769a8a57b9be85247c6546baceae82f2))
package/README.md CHANGED
@@ -11,9 +11,9 @@
11
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
- <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
- <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" /></a>
14
+ <a href="https://github.com/michaelfaith/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
+ <a href="https://codecov.io/gh/michaelfaith/eslint-fix-utils" target="_blank"><img alt="🧪 Coverage" src="https://img.shields.io/codecov/c/github/michaelfaith/eslint-fix-utils?label=%F0%9F%A7%AA%20coverage" /></a>
16
+ <a href="https://github.com/michaelfaith/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
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>
@@ -23,13 +23,35 @@
23
23
  If you're working on an ESLint plugin, install this as a dependency:
24
24
 
25
25
  ```shell
26
- npm i eslint-fix-utils
26
+ pnpm add eslint-fix-utils
27
27
  ```
28
28
 
29
29
  You'll then be able to use any of its exported utilities in your rules.
30
30
 
31
31
  ### Fixer APIs
32
32
 
33
+ ### `fixAddObjectProperty`
34
+
35
+ Version of [`addObjectProperty`](#addobjectproperty) that can be passed directly as a `fix` property.
36
+
37
+ ```ts
38
+ import { fixAddObjectProperty } from "eslint-fix-utils";
39
+
40
+ // ...
41
+
42
+ export function report(
43
+ node: ESTree.ObjectExpression,
44
+ propertyKey: string,
45
+ propertyValue: string,
46
+ ) {
47
+ context.report({
48
+ fix: fixAddObjectProperty(context, node, propertyKey, propertyValue),
49
+ messageId,
50
+ node,
51
+ });
52
+ }
53
+ ```
54
+
33
55
  ### `fixRemoveArrayElement`
34
56
 
35
57
  Version of [`removeArrayElement`](#removearrayelement) that can be passed directly as a `fix` property.
@@ -68,6 +90,46 @@ export function report(index: number, node: ESTree.ObjectExpression) {
68
90
 
69
91
  ### Full APIs
70
92
 
93
+ #### `addObjectProperty`
94
+
95
+ Adds a new property to an object expression, along with any necessary commas.
96
+
97
+ Parameters:
98
+
99
+ 1. `context: Rule.Context`
100
+ 2. `fixer: Rule.RuleFixer`
101
+ 3. `objectExpression: ESTree.ObjectExpression`: the object node
102
+ 4. `propertyKey: string`: the value for the new property's key
103
+ 5. `propertyValue: unknown`: the value for the new property's value
104
+
105
+ ```ts
106
+ import { addObjectProperty } from "eslint-fix-utils";
107
+
108
+ // ...
109
+
110
+ export function report(index: number, node: ESTree.ObjectExpression) {
111
+ context.report({
112
+ fix: (fixer) {
113
+ // Adds a new property to the end of an Object:
114
+ return addObjectProperty(context, fixer, node, "type", "module");
115
+ },
116
+ messageId,
117
+ node,
118
+ });
119
+ }
120
+ ```
121
+
122
+ ```diff
123
+ {
124
+ name: "my-package",
125
+ - version: "1.2.3"
126
+ + version: "1.2.3",
127
+ + type: "module"
128
+ }
129
+ ```
130
+
131
+ Trailing commas are omitted so that the fixed code will work regardless of whether the language allows them.
132
+
71
133
  #### `removeArrayElement`
72
134
 
73
135
  Removes an element from an array expression, along with any commas that are no longer necessary.
@@ -160,8 +222,8 @@ Thanks! 🔧
160
222
  <tbody>
161
223
  <tr>
162
224
  <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>
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>
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>
225
+ <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/michaelfaith/eslint-fix-utils/commits?author=JoshuaKGoldberg" title="Code">💻</a> <a href="#content-JoshuaKGoldberg" title="Content">🖋</a> <a href="https://github.com/michaelfaith/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/michaelfaith/eslint-fix-utils/commits?author=JoshuaKGoldberg" title="Tests">⚠️</a> <a href="#tool-JoshuaKGoldberg" title="Tools">🔧</a> <a href="https://github.com/michaelfaith/eslint-fix-utils/issues?q=author%3AJoshuaKGoldberg" title="Bug reports">🐛</a></td>
226
+ <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/michaelfaith/eslint-fix-utils/commits?author=michaelfaith" title="Code">💻</a> <a href="#content-michaelfaith" title="Content">🖋</a> <a href="https://github.com/michaelfaith/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/michaelfaith/eslint-fix-utils/commits?author=michaelfaith" title="Tests">⚠️</a> <a href="#tool-michaelfaith" title="Tools">🔧</a></td>
165
227
  </tr>
166
228
  </tbody>
167
229
  </table>
@@ -171,5 +233,3 @@ Thanks! 🔧
171
233
 
172
234
  <!-- ALL-CONTRIBUTORS-LIST:END -->
173
235
  <!-- spellchecker: enable -->
174
-
175
- > 💝 This package was templated with [`create-typescript-app`](https://github.com/JoshuaKGoldberg/create-typescript-app) using the [Bingo engine](https://create.bingo).
@@ -0,0 +1,528 @@
1
+ import { Rule } from "eslint";
2
+
3
+ //#region node_modules/.pnpm/@types+estree@1.0.6/node_modules/@types/estree/index.d.ts
4
+ // This definition file follows a somewhat unusual format. ESTree allows
5
+ // runtime type checks based on the `type` parameter. In order to explain this
6
+ // to typescript we want to use discriminated union types:
7
+ // https://github.com/Microsoft/TypeScript/pull/9163
8
+ //
9
+ // For ESTree this is a bit tricky because the high level interfaces like
10
+ // Node or Function are pulling double duty. We want to pass common fields down
11
+ // to the interfaces that extend them (like Identifier or
12
+ // ArrowFunctionExpression), but you can't extend a type union or enforce
13
+ // common fields on them. So we've split the high level interfaces into two
14
+ // types, a base type which passes down inherited fields, and a type union of
15
+ // all types which extend the base type. Only the type union is exported, and
16
+ // the union is how other types refer to the collection of inheriting types.
17
+ //
18
+ // This makes the definitions file here somewhat more difficult to maintain,
19
+ // but it has the notable advantage of making ESTree much easier to use as
20
+ // an end user.
21
+ interface BaseNodeWithoutComments {
22
+ // Every leaf interface that extends BaseNode must specify a type property.
23
+ // The type property should be a string literal. For example, Identifier
24
+ // has: `type: "Identifier"`
25
+ type: string;
26
+ loc?: SourceLocation | null | undefined;
27
+ range?: [number, number] | undefined;
28
+ }
29
+ interface BaseNode extends BaseNodeWithoutComments {
30
+ leadingComments?: Comment[] | undefined;
31
+ trailingComments?: Comment[] | undefined;
32
+ }
33
+ interface Comment extends BaseNodeWithoutComments {
34
+ type: "Line" | "Block";
35
+ value: string;
36
+ }
37
+ interface SourceLocation {
38
+ source?: string | null | undefined;
39
+ start: Position;
40
+ end: Position;
41
+ }
42
+ interface Position {
43
+ /** >= 1 */
44
+ line: number;
45
+ /** >= 0 */
46
+ column: number;
47
+ }
48
+ interface BaseFunction extends BaseNode {
49
+ params: Pattern[];
50
+ generator?: boolean | undefined;
51
+ async?: boolean | undefined; // The body is either BlockStatement or Expression because arrow functions
52
+ // can have a body that's either. FunctionDeclarations and
53
+ // FunctionExpressions have only BlockStatement bodies.
54
+ body: BlockStatement | Expression;
55
+ }
56
+ type Statement = ExpressionStatement | BlockStatement | StaticBlock | EmptyStatement | DebuggerStatement | WithStatement | ReturnStatement | LabeledStatement | BreakStatement | ContinueStatement | IfStatement | SwitchStatement | ThrowStatement | TryStatement | WhileStatement | DoWhileStatement | ForStatement | ForInStatement | ForOfStatement | Declaration;
57
+ interface BaseStatement extends BaseNode {}
58
+ interface EmptyStatement extends BaseStatement {
59
+ type: "EmptyStatement";
60
+ }
61
+ interface BlockStatement extends BaseStatement {
62
+ type: "BlockStatement";
63
+ body: Statement[];
64
+ innerComments?: Comment[] | undefined;
65
+ }
66
+ interface StaticBlock extends Omit<BlockStatement, "type"> {
67
+ type: "StaticBlock";
68
+ }
69
+ interface ExpressionStatement extends BaseStatement {
70
+ type: "ExpressionStatement";
71
+ expression: Expression;
72
+ }
73
+ interface IfStatement extends BaseStatement {
74
+ type: "IfStatement";
75
+ test: Expression;
76
+ consequent: Statement;
77
+ alternate?: Statement | null | undefined;
78
+ }
79
+ interface LabeledStatement extends BaseStatement {
80
+ type: "LabeledStatement";
81
+ label: Identifier;
82
+ body: Statement;
83
+ }
84
+ interface BreakStatement extends BaseStatement {
85
+ type: "BreakStatement";
86
+ label?: Identifier | null | undefined;
87
+ }
88
+ interface ContinueStatement extends BaseStatement {
89
+ type: "ContinueStatement";
90
+ label?: Identifier | null | undefined;
91
+ }
92
+ interface WithStatement extends BaseStatement {
93
+ type: "WithStatement";
94
+ object: Expression;
95
+ body: Statement;
96
+ }
97
+ interface SwitchStatement extends BaseStatement {
98
+ type: "SwitchStatement";
99
+ discriminant: Expression;
100
+ cases: SwitchCase[];
101
+ }
102
+ interface ReturnStatement extends BaseStatement {
103
+ type: "ReturnStatement";
104
+ argument?: Expression | null | undefined;
105
+ }
106
+ interface ThrowStatement extends BaseStatement {
107
+ type: "ThrowStatement";
108
+ argument: Expression;
109
+ }
110
+ interface TryStatement extends BaseStatement {
111
+ type: "TryStatement";
112
+ block: BlockStatement;
113
+ handler?: CatchClause | null | undefined;
114
+ finalizer?: BlockStatement | null | undefined;
115
+ }
116
+ interface WhileStatement extends BaseStatement {
117
+ type: "WhileStatement";
118
+ test: Expression;
119
+ body: Statement;
120
+ }
121
+ interface DoWhileStatement extends BaseStatement {
122
+ type: "DoWhileStatement";
123
+ body: Statement;
124
+ test: Expression;
125
+ }
126
+ interface ForStatement extends BaseStatement {
127
+ type: "ForStatement";
128
+ init?: VariableDeclaration | Expression | null | undefined;
129
+ test?: Expression | null | undefined;
130
+ update?: Expression | null | undefined;
131
+ body: Statement;
132
+ }
133
+ interface BaseForXStatement extends BaseStatement {
134
+ left: VariableDeclaration | Pattern;
135
+ right: Expression;
136
+ body: Statement;
137
+ }
138
+ interface ForInStatement extends BaseForXStatement {
139
+ type: "ForInStatement";
140
+ }
141
+ interface DebuggerStatement extends BaseStatement {
142
+ type: "DebuggerStatement";
143
+ }
144
+ type Declaration = FunctionDeclaration | VariableDeclaration | ClassDeclaration;
145
+ interface BaseDeclaration extends BaseStatement {}
146
+ interface MaybeNamedFunctionDeclaration extends BaseFunction, BaseDeclaration {
147
+ type: "FunctionDeclaration";
148
+ /** It is null when a function declaration is a part of the `export default function` statement */
149
+ id: Identifier | null;
150
+ body: BlockStatement;
151
+ }
152
+ interface FunctionDeclaration extends MaybeNamedFunctionDeclaration {
153
+ id: Identifier;
154
+ }
155
+ interface VariableDeclaration extends BaseDeclaration {
156
+ type: "VariableDeclaration";
157
+ declarations: VariableDeclarator[];
158
+ kind: "var" | "let" | "const";
159
+ }
160
+ interface VariableDeclarator extends BaseNode {
161
+ type: "VariableDeclarator";
162
+ id: Pattern;
163
+ init?: Expression | null | undefined;
164
+ }
165
+ interface ExpressionMap {
166
+ ArrayExpression: ArrayExpression;
167
+ ArrowFunctionExpression: ArrowFunctionExpression;
168
+ AssignmentExpression: AssignmentExpression;
169
+ AwaitExpression: AwaitExpression;
170
+ BinaryExpression: BinaryExpression;
171
+ CallExpression: CallExpression;
172
+ ChainExpression: ChainExpression;
173
+ ClassExpression: ClassExpression;
174
+ ConditionalExpression: ConditionalExpression;
175
+ FunctionExpression: FunctionExpression;
176
+ Identifier: Identifier;
177
+ ImportExpression: ImportExpression;
178
+ Literal: Literal;
179
+ LogicalExpression: LogicalExpression;
180
+ MemberExpression: MemberExpression;
181
+ MetaProperty: MetaProperty;
182
+ NewExpression: NewExpression;
183
+ ObjectExpression: ObjectExpression;
184
+ SequenceExpression: SequenceExpression;
185
+ TaggedTemplateExpression: TaggedTemplateExpression;
186
+ TemplateLiteral: TemplateLiteral;
187
+ ThisExpression: ThisExpression;
188
+ UnaryExpression: UnaryExpression;
189
+ UpdateExpression: UpdateExpression;
190
+ YieldExpression: YieldExpression;
191
+ }
192
+ type Expression = ExpressionMap[keyof ExpressionMap];
193
+ interface BaseExpression extends BaseNode {}
194
+ type ChainElement = SimpleCallExpression | MemberExpression;
195
+ interface ChainExpression extends BaseExpression {
196
+ type: "ChainExpression";
197
+ expression: ChainElement;
198
+ }
199
+ interface ThisExpression extends BaseExpression {
200
+ type: "ThisExpression";
201
+ }
202
+ interface ArrayExpression extends BaseExpression {
203
+ type: "ArrayExpression";
204
+ elements: Array<Expression | SpreadElement | null>;
205
+ }
206
+ interface ObjectExpression extends BaseExpression {
207
+ type: "ObjectExpression";
208
+ properties: Array<Property | SpreadElement>;
209
+ }
210
+ interface PrivateIdentifier extends BaseNode {
211
+ type: "PrivateIdentifier";
212
+ name: string;
213
+ }
214
+ interface Property extends BaseNode {
215
+ type: "Property";
216
+ key: Expression | PrivateIdentifier;
217
+ value: Expression | Pattern; // Could be an AssignmentProperty
218
+ kind: "init" | "get" | "set";
219
+ method: boolean;
220
+ shorthand: boolean;
221
+ computed: boolean;
222
+ }
223
+ interface PropertyDefinition extends BaseNode {
224
+ type: "PropertyDefinition";
225
+ key: Expression | PrivateIdentifier;
226
+ value?: Expression | null | undefined;
227
+ computed: boolean;
228
+ static: boolean;
229
+ }
230
+ interface FunctionExpression extends BaseFunction, BaseExpression {
231
+ id?: Identifier | null | undefined;
232
+ type: "FunctionExpression";
233
+ body: BlockStatement;
234
+ }
235
+ interface SequenceExpression extends BaseExpression {
236
+ type: "SequenceExpression";
237
+ expressions: Expression[];
238
+ }
239
+ interface UnaryExpression extends BaseExpression {
240
+ type: "UnaryExpression";
241
+ operator: UnaryOperator;
242
+ prefix: true;
243
+ argument: Expression;
244
+ }
245
+ interface BinaryExpression extends BaseExpression {
246
+ type: "BinaryExpression";
247
+ operator: BinaryOperator;
248
+ left: Expression | PrivateIdentifier;
249
+ right: Expression;
250
+ }
251
+ interface AssignmentExpression extends BaseExpression {
252
+ type: "AssignmentExpression";
253
+ operator: AssignmentOperator;
254
+ left: Pattern | MemberExpression;
255
+ right: Expression;
256
+ }
257
+ interface UpdateExpression extends BaseExpression {
258
+ type: "UpdateExpression";
259
+ operator: UpdateOperator;
260
+ argument: Expression;
261
+ prefix: boolean;
262
+ }
263
+ interface LogicalExpression extends BaseExpression {
264
+ type: "LogicalExpression";
265
+ operator: LogicalOperator;
266
+ left: Expression;
267
+ right: Expression;
268
+ }
269
+ interface ConditionalExpression extends BaseExpression {
270
+ type: "ConditionalExpression";
271
+ test: Expression;
272
+ alternate: Expression;
273
+ consequent: Expression;
274
+ }
275
+ interface BaseCallExpression extends BaseExpression {
276
+ callee: Expression | Super;
277
+ arguments: Array<Expression | SpreadElement>;
278
+ }
279
+ type CallExpression = SimpleCallExpression | NewExpression;
280
+ interface SimpleCallExpression extends BaseCallExpression {
281
+ type: "CallExpression";
282
+ optional: boolean;
283
+ }
284
+ interface NewExpression extends BaseCallExpression {
285
+ type: "NewExpression";
286
+ }
287
+ interface MemberExpression extends BaseExpression, BasePattern {
288
+ type: "MemberExpression";
289
+ object: Expression | Super;
290
+ property: Expression | PrivateIdentifier;
291
+ computed: boolean;
292
+ optional: boolean;
293
+ }
294
+ type Pattern = Identifier | ObjectPattern | ArrayPattern | RestElement | AssignmentPattern | MemberExpression;
295
+ interface BasePattern extends BaseNode {}
296
+ interface SwitchCase extends BaseNode {
297
+ type: "SwitchCase";
298
+ test?: Expression | null | undefined;
299
+ consequent: Statement[];
300
+ }
301
+ interface CatchClause extends BaseNode {
302
+ type: "CatchClause";
303
+ param: Pattern | null;
304
+ body: BlockStatement;
305
+ }
306
+ interface Identifier extends BaseNode, BaseExpression, BasePattern {
307
+ type: "Identifier";
308
+ name: string;
309
+ }
310
+ type Literal = SimpleLiteral | RegExpLiteral | BigIntLiteral;
311
+ interface SimpleLiteral extends BaseNode, BaseExpression {
312
+ type: "Literal";
313
+ value: string | boolean | number | null;
314
+ raw?: string | undefined;
315
+ }
316
+ interface RegExpLiteral extends BaseNode, BaseExpression {
317
+ type: "Literal";
318
+ value?: RegExp | null | undefined;
319
+ regex: {
320
+ pattern: string;
321
+ flags: string;
322
+ };
323
+ raw?: string | undefined;
324
+ }
325
+ interface BigIntLiteral extends BaseNode, BaseExpression {
326
+ type: "Literal";
327
+ value?: bigint | null | undefined;
328
+ bigint: string;
329
+ raw?: string | undefined;
330
+ }
331
+ type UnaryOperator = "-" | "+" | "!" | "~" | "typeof" | "void" | "delete";
332
+ type BinaryOperator = "==" | "!=" | "===" | "!==" | "<" | "<=" | ">" | ">=" | "<<" | ">>" | ">>>" | "+" | "-" | "*" | "/" | "%" | "**" | "|" | "^" | "&" | "in" | "instanceof";
333
+ type LogicalOperator = "||" | "&&" | "??";
334
+ type AssignmentOperator = "=" | "+=" | "-=" | "*=" | "/=" | "%=" | "**=" | "<<=" | ">>=" | ">>>=" | "|=" | "^=" | "&=" | "||=" | "&&=" | "??=";
335
+ type UpdateOperator = "++" | "--";
336
+ interface ForOfStatement extends BaseForXStatement {
337
+ type: "ForOfStatement";
338
+ await: boolean;
339
+ }
340
+ interface Super extends BaseNode {
341
+ type: "Super";
342
+ }
343
+ interface SpreadElement extends BaseNode {
344
+ type: "SpreadElement";
345
+ argument: Expression;
346
+ }
347
+ interface ArrowFunctionExpression extends BaseExpression, BaseFunction {
348
+ type: "ArrowFunctionExpression";
349
+ expression: boolean;
350
+ body: BlockStatement | Expression;
351
+ }
352
+ interface YieldExpression extends BaseExpression {
353
+ type: "YieldExpression";
354
+ argument?: Expression | null | undefined;
355
+ delegate: boolean;
356
+ }
357
+ interface TemplateLiteral extends BaseExpression {
358
+ type: "TemplateLiteral";
359
+ quasis: TemplateElement[];
360
+ expressions: Expression[];
361
+ }
362
+ interface TaggedTemplateExpression extends BaseExpression {
363
+ type: "TaggedTemplateExpression";
364
+ tag: Expression;
365
+ quasi: TemplateLiteral;
366
+ }
367
+ interface TemplateElement extends BaseNode {
368
+ type: "TemplateElement";
369
+ tail: boolean;
370
+ value: {
371
+ /** It is null when the template literal is tagged and the text has an invalid escape (e.g. - tag`\unicode and \u{55}`) */cooked?: string | null | undefined;
372
+ raw: string;
373
+ };
374
+ }
375
+ interface AssignmentProperty extends Property {
376
+ value: Pattern;
377
+ kind: "init";
378
+ method: boolean; // false
379
+ }
380
+ interface ObjectPattern extends BasePattern {
381
+ type: "ObjectPattern";
382
+ properties: Array<AssignmentProperty | RestElement>;
383
+ }
384
+ interface ArrayPattern extends BasePattern {
385
+ type: "ArrayPattern";
386
+ elements: Array<Pattern | null>;
387
+ }
388
+ interface RestElement extends BasePattern {
389
+ type: "RestElement";
390
+ argument: Pattern;
391
+ }
392
+ interface AssignmentPattern extends BasePattern {
393
+ type: "AssignmentPattern";
394
+ left: Pattern;
395
+ right: Expression;
396
+ }
397
+ interface BaseClass extends BaseNode {
398
+ superClass?: Expression | null | undefined;
399
+ body: ClassBody;
400
+ }
401
+ interface ClassBody extends BaseNode {
402
+ type: "ClassBody";
403
+ body: Array<MethodDefinition | PropertyDefinition | StaticBlock>;
404
+ }
405
+ interface MethodDefinition extends BaseNode {
406
+ type: "MethodDefinition";
407
+ key: Expression | PrivateIdentifier;
408
+ value: FunctionExpression;
409
+ kind: "constructor" | "method" | "get" | "set";
410
+ computed: boolean;
411
+ static: boolean;
412
+ }
413
+ interface MaybeNamedClassDeclaration extends BaseClass, BaseDeclaration {
414
+ type: "ClassDeclaration";
415
+ /** It is null when a class declaration is a part of the `export default class` statement */
416
+ id: Identifier | null;
417
+ }
418
+ interface ClassDeclaration extends MaybeNamedClassDeclaration {
419
+ id: Identifier;
420
+ }
421
+ interface ClassExpression extends BaseClass, BaseExpression {
422
+ type: "ClassExpression";
423
+ id?: Identifier | null | undefined;
424
+ }
425
+ interface MetaProperty extends BaseExpression {
426
+ type: "MetaProperty";
427
+ meta: Identifier;
428
+ property: Identifier;
429
+ }
430
+ interface ImportExpression extends BaseExpression {
431
+ type: "ImportExpression";
432
+ source: Expression;
433
+ }
434
+ interface AwaitExpression extends BaseExpression {
435
+ type: "AwaitExpression";
436
+ argument: Expression;
437
+ }
438
+ //#endregion
439
+ //#region src/addObjectProperty.d.ts
440
+ /**
441
+ * Given an ObjectProperty, and a rule fixer, this function yields the addition
442
+ * of a new property to the given ObjectExpression, along with any necessary commas.
443
+ * The new property is at the end of the object.
444
+ * @param context ESLint Rule Context
445
+ * @param fixer Rule fixer
446
+ * @param objectExpression The object expression to which the property will be added
447
+ * @param propertyKey The key for the new property
448
+ * @param propertyValue The value for the new property
449
+ * @yields fixer addition for the new property into the object expression, as well as any necessary commas
450
+ */
451
+ declare function addObjectProperty(context: Rule.RuleContext, fixer: Rule.RuleFixer, objectExpression: ObjectExpression, propertyKey: string, propertyValue: unknown): Generator<Rule.Fix, void>;
452
+ //#endregion
453
+ //#region src/fixAddObjectProperty.d.ts
454
+ /**
455
+ * Given an ObjectExpression and the key and value of a property,
456
+ * this function returns a fixer function that you can provide to a report
457
+ * descriptor that will add the new property to it.
458
+ * @param context ESLint Rule Context
459
+ * @param objectExpression The object expression to which the property will be added
460
+ * @param propertyKey The key for the new property
461
+ * @param propertyValue The value for the new property
462
+ * @returns a fixer function that you can provide to a report descriptor that
463
+ * adds a new property to an object expression, along with any commas that
464
+ * are needed.
465
+ */
466
+ declare const fixAddObjectProperty: (context: Rule.RuleContext, objectExpression: ObjectExpression, propertyKey: string, propertyValue: unknown) => ((fixer: Rule.RuleFixer) => Generator<Rule.Fix, void>);
467
+ //#endregion
468
+ //#region src/removeArrayElement.d.ts
469
+ type ArrayElement = Expression | SpreadElement;
470
+ type ArrayElementsOrParent = ArrayExpression | ArrayExpression["elements"];
471
+ /**
472
+ * Given an ArrayExpression or the list of elements an ArrayExpression has,
473
+ * the index or node within that array that you want to remove, and a rule fixer,
474
+ * this function yields removals for the node itself, as well as any trailing
475
+ * commas that are no longer necessary.
476
+ * @param context ESLint Rule Context
477
+ * @param fixer Rule fixer
478
+ * @param elementOrIndex The child expression, spread element, or a numeric
479
+ * index of the child
480
+ * @param parentOrElements The array expression node, or its `.elements` array
481
+ * @yields fixer removals for the node itself, as well as any trailing commas
482
+ * that are no longer necessary.
483
+ */
484
+ declare function removeArrayElement(context: Rule.RuleContext, fixer: Rule.RuleFixer, elementOrIndex: ArrayElement | number, parentOrElements: ArrayElementsOrParent): Generator<Rule.Fix, void>;
485
+ //#endregion
486
+ //#region src/fixRemoveArrayElement.d.ts
487
+ /**
488
+ * Given an ArrayExpression or the list of elements an ArrayExpression has, and
489
+ * the index or node within that array that you want to remove, this function
490
+ * returns a fixer function that you can provide to a report descriptor that
491
+ * will remove that node along with any trailing comma.
492
+ * @param context ESLint Rule Context
493
+ * @param elementOrIndex The child expression, spread element, or a numeric
494
+ * index of the child
495
+ * @param parentOrElements The array expression node, or its `.elements` array
496
+ * @returns a fixer function that you can provide to a report descriptor, that
497
+ * removes an element from an array expression, along with any commas that are
498
+ * no longer necessary.
499
+ */
500
+ declare const fixRemoveArrayElement: (context: Rule.RuleContext, elementOrIndex: ArrayElement | number, parentOrElements: ArrayElementsOrParent) => ((fixer: Rule.RuleFixer) => Generator<Rule.Fix, void>);
501
+ //#endregion
502
+ //#region src/removeObjectProperty.d.ts
503
+ type ObjectProperty = Property | SpreadElement;
504
+ /**
505
+ * Given an ObjectProperty, and a rule fixer, this function yields removals for
506
+ * the node itself, as well as any trailing commas that are no longer necessary.
507
+ * @param context ESLint Rule Context
508
+ * @param fixer Rule fixer
509
+ * @param property The property node
510
+ * @yields fixer removals for the node itself, as well as any trailing commas
511
+ * that are no longer necessary.
512
+ */
513
+ declare function removeObjectProperty(context: Rule.RuleContext, fixer: Rule.RuleFixer, property: ObjectProperty): Generator<Rule.Fix, void>;
514
+ //#endregion
515
+ //#region src/fixRemoveObjectProperty.d.ts
516
+ /**
517
+ * Given an ObjectProperty, this function returns a fixer function that you can
518
+ * provide to a report descriptor that will remove that node along with any
519
+ * trailing comma.
520
+ * @param context ESLint Rule Context
521
+ * @param property The property node
522
+ * @returns a fixer function that you can provide to a report descriptor, that
523
+ * removes a property from an object expression, along with any commas that
524
+ * are no longer necessary.
525
+ */
526
+ declare const fixRemoveObjectProperty: (context: Rule.RuleContext, property: ObjectProperty) => ((fixer: Rule.RuleFixer) => Generator<Rule.Fix, void>);
527
+ //#endregion
528
+ export { type ArrayElement, type ArrayElementsOrParent, type ObjectProperty, addObjectProperty, fixAddObjectProperty, fixRemoveArrayElement, fixRemoveObjectProperty, removeArrayElement, removeObjectProperty };
@@ -1,3 +1,55 @@
1
+ //#region src/addObjectProperty.ts
2
+ /**
3
+ * Given an ObjectProperty, and a rule fixer, this function yields the addition
4
+ * of a new property to the given ObjectExpression, along with any necessary commas.
5
+ * The new property is at the end of the object.
6
+ * @param context ESLint Rule Context
7
+ * @param fixer Rule fixer
8
+ * @param objectExpression The object expression to which the property will be added
9
+ * @param propertyKey The key for the new property
10
+ * @param propertyValue The value for the new property
11
+ * @yields fixer addition for the new property into the object expression, as well as any necessary commas
12
+ */
13
+ function* addObjectProperty(context, fixer, objectExpression, propertyKey, propertyValue) {
14
+ const sourceCode = context.sourceCode;
15
+ let insertPosition;
16
+ let needsComma = false;
17
+ if (objectExpression.properties.length > 0) {
18
+ const tokenAfter = sourceCode.getTokenAfter(objectExpression.properties[objectExpression.properties.length - 1]);
19
+ if (tokenAfter?.value === ",") insertPosition = tokenAfter.range;
20
+ else {
21
+ needsComma = true;
22
+ insertPosition = objectExpression.properties.at(-1)?.range;
23
+ }
24
+ }
25
+ insertPosition ??= [0, 1];
26
+ if (needsComma) {
27
+ yield fixer.insertTextAfterRange(insertPosition, ",");
28
+ insertPosition = [insertPosition[0] + 1, insertPosition[1] + 1];
29
+ } else yield fixer.insertTextAfterRange(insertPosition, "\n");
30
+ const textToInsert = ` ${`${JSON.stringify(propertyKey)}: ${JSON.stringify(propertyValue)}`}\n`;
31
+ yield fixer.insertTextAfterRange(insertPosition, textToInsert);
32
+ }
33
+
34
+ //#endregion
35
+ //#region src/fixAddObjectProperty.ts
36
+ /**
37
+ * Given an ObjectExpression and the key and value of a property,
38
+ * this function returns a fixer function that you can provide to a report
39
+ * descriptor that will add the new property to it.
40
+ * @param context ESLint Rule Context
41
+ * @param objectExpression The object expression to which the property will be added
42
+ * @param propertyKey The key for the new property
43
+ * @param propertyValue The value for the new property
44
+ * @returns a fixer function that you can provide to a report descriptor that
45
+ * adds a new property to an object expression, along with any commas that
46
+ * are needed.
47
+ */
48
+ const fixAddObjectProperty = (context, objectExpression, propertyKey, propertyValue) => {
49
+ return (fixer) => addObjectProperty(context, fixer, objectExpression, propertyKey, propertyValue);
50
+ };
51
+
52
+ //#endregion
1
53
  //#region src/removeArrayElement.ts
2
54
  /**
3
55
  * Given an ArrayExpression or the list of elements an ArrayExpression has,
@@ -13,8 +65,7 @@
13
65
  * that are no longer necessary.
14
66
  */
15
67
  function* removeArrayElement(context, fixer, elementOrIndex, parentOrElements) {
16
- const elements = Array.isArray(parentOrElements) ? parentOrElements : parentOrElements.elements;
17
- const [element, index] = getElementAndIndex(elements, elementOrIndex);
68
+ const [element, index] = getElementAndIndex(Array.isArray(parentOrElements) ? parentOrElements : parentOrElements.elements, elementOrIndex);
18
69
  if (!element) throw new Error("Cannot remove a null (blank) array element.");
19
70
  const tokenAfter = context.sourceCode.getTokenAfter(element);
20
71
  const tokenBefore = context.sourceCode.getTokenBefore(element);
@@ -84,4 +135,4 @@ const fixRemoveObjectProperty = (context, property) => {
84
135
  };
85
136
 
86
137
  //#endregion
87
- export { fixRemoveArrayElement, fixRemoveObjectProperty, removeArrayElement, removeObjectProperty };
138
+ export { addObjectProperty, fixAddObjectProperty, fixRemoveArrayElement, fixRemoveObjectProperty, removeArrayElement, removeObjectProperty };
package/package.json CHANGED
@@ -1,96 +1,93 @@
1
1
  {
2
- "name": "eslint-fix-utils",
3
- "version": "0.4.0",
4
- "description": "Utilities for ESLint rule fixers and suggestions. 🧑‍🔧",
5
- "repository": {
6
- "type": "git",
7
- "url": "git+https://github.com/JoshuaKGoldberg/eslint-fix-utils.git"
8
- },
9
- "license": "MIT",
10
- "author": {
11
- "name": "Josh Goldberg ✨",
12
- "email": "npm@joshuakgoldberg.com"
13
- },
14
- "type": "module",
15
- "exports": {
16
- ".": {
17
- "types": "./lib/index.d.ts",
18
- "default": "./lib/index.js"
19
- }
20
- },
21
- "main": "lib/index.js",
22
- "module": "lib/index.js",
23
- "types": "lib/index.d.ts",
24
- "files": [
25
- "CHANGELOG.md",
26
- "lib/"
27
- ],
28
- "scripts": {
29
- "build": "tsdown",
30
- "format": "prettier .",
31
- "lint": "eslint . --max-warnings 0",
32
- "lint:knip": "knip",
33
- "lint:md": "markdownlint \"**/*.md\" \".github/**/*.md\" --rules sentences-per-line",
34
- "lint:packages": "pnpm dedupe --check",
35
- "lint:spelling": "cspell \"**\" \".github/**/*\"",
36
- "prepare": "husky",
37
- "test": "vitest",
38
- "tsc": "tsc"
39
- },
40
- "lint-staged": {
41
- "*": "prettier --ignore-unknown --write"
42
- },
43
- "devDependencies": {
44
- "@eslint-community/eslint-plugin-eslint-comments": "4.5.0",
45
- "@eslint/js": "9.28.0",
46
- "@release-it/conventional-changelog": "10.0.0",
47
- "@types/eslint-plugin-markdown": "2.0.2",
48
- "@types/estree": "1.0.6",
49
- "@types/node": "22.15.0",
50
- "@vitest/coverage-v8": "3.2.0",
51
- "@vitest/eslint-plugin": "1.2.0",
52
- "console-fail-test": "0.5.0",
53
- "create-typescript-app": "2.42.0",
54
- "cspell": "9.0.0",
55
- "eslint": "9.28.0",
56
- "eslint-plugin-jsdoc": "50.7.0",
57
- "eslint-plugin-jsonc": "2.20.0",
58
- "eslint-plugin-markdown": "5.1.0",
59
- "eslint-plugin-n": "17.19.0",
60
- "eslint-plugin-package-json": "0.33.0",
61
- "eslint-plugin-perfectionist": "4.14.0",
62
- "eslint-plugin-regexp": "2.8.0",
63
- "eslint-plugin-yml": "1.18.0",
64
- "husky": "9.1.7",
65
- "knip": "5.60.0",
66
- "lint-staged": "16.1.0",
67
- "markdownlint": "0.38.0",
68
- "markdownlint-cli": "0.45.0",
69
- "prettier": "3.5.3",
70
- "prettier-plugin-curly": "0.3.1",
71
- "prettier-plugin-packagejson": "2.5.10",
72
- "prettier-plugin-sh": "0.17.0",
73
- "release-it": "19.0.1",
74
- "sentences-per-line": "0.3.0",
75
- "tsdown": "0.12.0",
76
- "typescript": "5.8.2",
77
- "typescript-eslint": "8.33.0",
78
- "vitest": "3.2.0"
79
- },
80
- "peerDependencies": {
81
- "@types/estree": ">=1",
82
- "eslint": ">=8"
83
- },
84
- "peerDependenciesMeta": {
85
- "@types/estree": {
86
- "optional": true
87
- }
88
- },
89
- "packageManager": "pnpm@10.11.0",
90
- "engines": {
91
- "node": "^20.19.0 || >=22.12.0"
92
- },
93
- "publishConfig": {
94
- "provenance": true
95
- }
96
- }
2
+ "name": "eslint-fix-utils",
3
+ "version": "0.4.2",
4
+ "description": "Utilities for ESLint rule fixers and suggestions. 🧑‍🔧",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "git+https://github.com/michaelfaith/eslint-fix-utils.git"
8
+ },
9
+ "license": "MIT",
10
+ "contributors": [
11
+ {
12
+ "name": "JoshuaKGoldberg",
13
+ "email": "npm@joshuakgoldberg.com",
14
+ "url": "https://joshuakgoldberg.com"
15
+ },
16
+ {
17
+ "name": "michael faith",
18
+ "email": "michaelfaith@users.noreply.github.com",
19
+ "url": "https://michael.faith"
20
+ }
21
+ ],
22
+ "sideEffects": false,
23
+ "type": "module",
24
+ "exports": {
25
+ ".": {
26
+ "types": "./lib/index.d.mts",
27
+ "default": "./lib/index.mjs"
28
+ }
29
+ },
30
+ "main": "lib/index.mjs",
31
+ "module": "lib/index.mjs",
32
+ "types": "lib/index.d.mts",
33
+ "files": [
34
+ "CHANGELOG.md",
35
+ "lib/"
36
+ ],
37
+ "lint-staged": {
38
+ "*": "prettier --ignore-unknown --write"
39
+ },
40
+ "devDependencies": {
41
+ "@eslint-community/eslint-plugin-eslint-comments": "4.6.0",
42
+ "@eslint/js": "10.0.1",
43
+ "@types/estree": "1.0.6",
44
+ "@types/node": "24.10.0",
45
+ "@vitest/coverage-v8": "4.0.15",
46
+ "@vitest/eslint-plugin": "1.6.9",
47
+ "console-fail-test": "0.6.1",
48
+ "cspell": "9.7.0",
49
+ "eslint": "10.0.0",
50
+ "eslint-plugin-jsdoc": "62.7.0",
51
+ "eslint-plugin-jsonc": "3.1.0",
52
+ "eslint-plugin-n": "17.24.0",
53
+ "eslint-plugin-package-json": "0.89.0",
54
+ "eslint-plugin-perfectionist": "5.6.0",
55
+ "eslint-plugin-regexp": "3.0.0",
56
+ "eslint-plugin-yml": "3.3.0",
57
+ "husky": "9.1.7",
58
+ "knip": "5.85.0",
59
+ "lint-staged": "16.2.0",
60
+ "markdownlint": "0.40.0",
61
+ "markdownlint-cli": "0.47.0",
62
+ "prettier": "3.8.0",
63
+ "prettier-plugin-curly": "0.4.0",
64
+ "prettier-plugin-packagejson": "3.0.0",
65
+ "prettier-plugin-sh": "0.18.0",
66
+ "tsdown": "0.20.0",
67
+ "typescript": "5.9.2",
68
+ "typescript-eslint": "8.56.0",
69
+ "vitest": "4.0.15"
70
+ },
71
+ "peerDependencies": {
72
+ "@types/estree": ">=1",
73
+ "eslint": ">=8"
74
+ },
75
+ "peerDependenciesMeta": {
76
+ "@types/estree": {
77
+ "optional": true
78
+ }
79
+ },
80
+ "engines": {
81
+ "node": "^20.19.0 || ^22.12.0 || >=24.0.0"
82
+ },
83
+ "scripts": {
84
+ "build": "tsdown",
85
+ "format": "prettier .",
86
+ "lint": "eslint . --max-warnings 0",
87
+ "lint:knip": "knip",
88
+ "lint:md": "markdownlint \"**/*.md\" \".github/**/*.md\"",
89
+ "lint:spelling": "cspell \"**\" \".github/**/*\"",
90
+ "test": "vitest",
91
+ "type-check": "tsc"
92
+ }
93
+ }
package/lib/index.d.ts DELETED
@@ -1,65 +0,0 @@
1
- import { Rule } from "eslint";
2
- import * as ESTree$1 from "estree";
3
- import * as ESTree from "estree";
4
-
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"];
8
- /**
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
24
- /**
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
40
- type ObjectProperty = ESTree.Property | ESTree.SpreadElement;
41
- /**
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
53
- /**
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 };