@shigen/eslint-plugin 0.12.1 → 0.14.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/dist/index.d.ts +4 -4
- package/dist/index.js +7 -10
- package/dist/index.js.map +1 -1
- package/dist/rules/group-imports.d.ts +6 -5
- package/dist/rules/group-imports.d.ts.map +1 -1
- package/dist/rules/group-imports.js +77 -77
- package/dist/rules/group-imports.js.map +1 -1
- package/dist/rules/sort-imports.d.ts +7 -7
- package/dist/rules/sort-imports.d.ts.map +1 -1
- package/dist/rules/sort-imports.js +58 -66
- package/dist/rules/sort-imports.js.map +1 -1
- package/dist/tools/ast.d.ts +9 -9
- package/dist/tools/ast.d.ts.map +1 -1
- package/dist/tools/ast.js +17 -28
- package/dist/tools/ast.js.map +1 -1
- package/dist/tools/rule.d.ts +2 -2
- package/dist/tools/rule.js +3 -7
- package/dist/tools/rule.js.map +1 -1
- package/dist/tools/sort.d.ts +2 -4
- package/dist/tools/sort.d.ts.map +1 -1
- package/dist/tools/sort.js +8 -13
- package/dist/tools/sort.js.map +1 -1
- package/package.json +16 -13
package/dist/index.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
export declare const rules: {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
"group-imports": import("./tools/rule.ts").RuleModule<import("./rules/group-imports.ts").GroupConfiguration[]>;
|
|
3
|
+
"sort-imports": import("./tools/rule.ts").RuleModule<[Partial<import("./rules/sort-imports.ts").Configuration>?]>;
|
|
4
4
|
};
|
|
5
5
|
declare const plugin: {
|
|
6
6
|
rules: {
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
"group-imports": import("./tools/rule.ts").RuleModule<import("./rules/group-imports.ts").GroupConfiguration[]>;
|
|
8
|
+
"sort-imports": import("./tools/rule.ts").RuleModule<[Partial<import("./rules/sort-imports.ts").Configuration>?]>;
|
|
9
9
|
};
|
|
10
10
|
};
|
|
11
11
|
export default plugin;
|
package/dist/index.js
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
exports.rules = {
|
|
7
|
-
'group-imports': group_imports_js_1.rule,
|
|
8
|
-
'sort-imports': sort_imports_js_1.rule,
|
|
1
|
+
import { rule as groupImports } from "./rules/group-imports.js";
|
|
2
|
+
import { rule as sortImports } from "./rules/sort-imports.js";
|
|
3
|
+
export const rules = {
|
|
4
|
+
"group-imports": groupImports,
|
|
5
|
+
"sort-imports": sortImports,
|
|
9
6
|
};
|
|
10
7
|
const plugin = {
|
|
11
|
-
rules
|
|
8
|
+
rules,
|
|
12
9
|
};
|
|
13
|
-
|
|
10
|
+
export default plugin;
|
|
14
11
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,IAAI,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAChE,OAAO,EAAE,IAAI,IAAI,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAE9D,MAAM,CAAC,MAAM,KAAK,GAAG;IACpB,eAAe,EAAE,YAAY;IAC7B,cAAc,EAAE,WAAW;CAC3B,CAAC;AAEF,MAAM,MAAM,GAAG;IACd,KAAK;CACmB,CAAC;AAE1B,eAAe,MAAM,CAAC"}
|
|
@@ -1,22 +1,23 @@
|
|
|
1
|
-
import type
|
|
2
|
-
export type ModuleClassOption =
|
|
3
|
-
export type TypeImportOption =
|
|
1
|
+
import { type RuleModule } from "../tools/rule.ts";
|
|
2
|
+
export type ModuleClassOption = "node" | "external" | "internal" | "absolute" | "relative";
|
|
3
|
+
export type TypeImportOption = "include" | "exclude" | "only";
|
|
4
4
|
declare const ModuleClass_base: import("@shigen/enum").EnumConstructor<{
|
|
5
5
|
Key: ModuleClassOption;
|
|
6
6
|
}, [fields: {
|
|
7
|
-
readonly name?: string
|
|
7
|
+
readonly name?: string;
|
|
8
8
|
readonly key: ModuleClassOption;
|
|
9
9
|
}]>;
|
|
10
10
|
export declare class ModuleClass extends ModuleClass_base {
|
|
11
11
|
static readonly Node: ModuleClass;
|
|
12
12
|
static readonly External: ModuleClass;
|
|
13
|
+
static readonly Internal: ModuleClass;
|
|
13
14
|
static readonly Absolute: ModuleClass;
|
|
14
15
|
static readonly Relative: ModuleClass;
|
|
15
16
|
}
|
|
16
17
|
declare const TypeImport_base: import("@shigen/enum").EnumConstructor<{
|
|
17
18
|
Key: TypeImportOption;
|
|
18
19
|
}, [fields: {
|
|
19
|
-
readonly name?: string
|
|
20
|
+
readonly name?: string;
|
|
20
21
|
readonly key: TypeImportOption;
|
|
21
22
|
}]>;
|
|
22
23
|
export declare class TypeImport extends TypeImport_base {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"group-imports.d.ts","sourceRoot":"","sources":["../../src/rules/group-imports.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"group-imports.d.ts","sourceRoot":"","sources":["../../src/rules/group-imports.ts"],"names":[],"mappings":"AASA,OAAO,EAA8B,KAAK,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAG/E,MAAM,MAAM,iBAAiB,GAAG,MAAM,GAAG,UAAU,GAAG,UAAU,GAAG,UAAU,GAAG,UAAU,CAAC;AAC3F,MAAM,MAAM,gBAAgB,GAAG,SAAS,GAAG,SAAS,GAAG,MAAM,CAAC;;SAKjB,iBAAiB;;;;;AAA9D,qBAAa,WAAY,SAAQ,gBAAgD;IAChF,MAAM,CAAC,QAAQ,CAAC,IAAI,cAAoD;IACxE,MAAM,CAAC,QAAQ,CAAC,QAAQ,cAAwD;IAChF,MAAM,CAAC,QAAQ,CAAC,QAAQ,cAAwD;IAChF,MAAM,CAAC,QAAQ,CAAC,QAAQ,cAAwD;IAChF,MAAM,CAAC,QAAQ,CAAC,QAAQ,cAAwD;CAChF;;SAE2C,gBAAgB;;;;;AAA5D,qBAAa,UAAW,SAAQ,eAA8C;IAC7E,MAAM,CAAC,QAAQ,CAAC,OAAO,aAAqD;IAC5E,MAAM,CAAC,QAAQ,CAAC,OAAO,aAAqD;IAC5E,MAAM,CAAC,QAAQ,CAAC,IAAI,aAAkD;CACtE;AAED,UAAU,wBAAwB;IACjC,KAAK,EAAE,iBAAiB,CAAC;IACzB,KAAK,CAAC,EAAE,gBAAgB,CAAC;CACzB;AAED,UAAU,uBAAuB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,gBAAgB,CAAC;CACzB;AAED,KAAK,mBAAmB,GAAG,MAAM,GAAG,uBAAuB,GAAG,wBAAwB,CAAC;AAEvF,MAAM,MAAM,kBAAkB,GAAG,mBAAmB,GAAG,mBAAmB,EAAE,CAAC;AAmL7E,eAAO,MAAM,IAAI,EAAE,UAAU,CAAC,kBAAkB,EAAE,CAuHjD,CAAC"}
|
|
@@ -1,36 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const ast_js_1 = require("../tools/ast.js");
|
|
9
|
-
const rule_js_1 = require("../tools/rule.js");
|
|
10
|
-
const sort_js_1 = require("../tools/sort.js");
|
|
1
|
+
import { isBuiltin } from "node:module";
|
|
2
|
+
import { isAbsolute } from "node:path";
|
|
3
|
+
import { Enum } from "@shigen/enum";
|
|
4
|
+
import { minimatch } from "minimatch";
|
|
5
|
+
import { assertLoc, assertRange, extrema, importModules, isComment, isTypeImportOrExport } from "../tools/ast.js";
|
|
6
|
+
import { fixRange } from "../tools/rule.js";
|
|
7
|
+
import { sortByPath } from "../tools/sort.js";
|
|
11
8
|
const moduleClassId = Symbol();
|
|
12
9
|
const typeImportId = Symbol();
|
|
13
|
-
class ModuleClass extends
|
|
14
|
-
static Node = new ModuleClass(moduleClassId, { key:
|
|
15
|
-
static External = new ModuleClass(moduleClassId, { key:
|
|
16
|
-
static
|
|
17
|
-
static
|
|
10
|
+
export class ModuleClass extends Enum(moduleClassId) {
|
|
11
|
+
static Node = new ModuleClass(moduleClassId, { key: "node", });
|
|
12
|
+
static External = new ModuleClass(moduleClassId, { key: "external", });
|
|
13
|
+
static Internal = new ModuleClass(moduleClassId, { key: "internal", });
|
|
14
|
+
static Absolute = new ModuleClass(moduleClassId, { key: "absolute", });
|
|
15
|
+
static Relative = new ModuleClass(moduleClassId, { key: "relative", });
|
|
18
16
|
}
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
static
|
|
22
|
-
static
|
|
23
|
-
static Only = new TypeImport(typeImportId, { key: 'only' });
|
|
17
|
+
export class TypeImport extends Enum(typeImportId) {
|
|
18
|
+
static Include = new TypeImport(typeImportId, { key: "include", });
|
|
19
|
+
static Exclude = new TypeImport(typeImportId, { key: "exclude", });
|
|
20
|
+
static Only = new TypeImport(typeImportId, { key: "only", });
|
|
24
21
|
}
|
|
25
|
-
exports.TypeImport = TypeImport;
|
|
26
22
|
const defaultConfiguration = [
|
|
27
|
-
{ class: ModuleClass.Node.key },
|
|
28
|
-
{ class: ModuleClass.External.key },
|
|
29
|
-
{ class: ModuleClass.Absolute.key },
|
|
30
|
-
{ class: ModuleClass.
|
|
23
|
+
{ class: ModuleClass.Node.key, },
|
|
24
|
+
{ class: ModuleClass.External.key, },
|
|
25
|
+
{ class: ModuleClass.Absolute.key, },
|
|
26
|
+
{ class: ModuleClass.Internal.key, },
|
|
27
|
+
{ class: ModuleClass.Relative.key, },
|
|
31
28
|
];
|
|
32
29
|
function groupIndex(node, groups) {
|
|
33
|
-
if (typeof node.source.value !==
|
|
30
|
+
if (typeof node.source.value !== "string") {
|
|
34
31
|
return groups.length;
|
|
35
32
|
}
|
|
36
33
|
const importPath = node.source.value;
|
|
@@ -40,36 +37,39 @@ function groupIndex(node, groups) {
|
|
|
40
37
|
}
|
|
41
38
|
return callback(group);
|
|
42
39
|
});
|
|
43
|
-
const isTypeImport =
|
|
40
|
+
const isTypeImport = isTypeImportOrExport(node);
|
|
44
41
|
const hardCodedIndex = findIndex((group) => {
|
|
45
|
-
if (typeof group ===
|
|
46
|
-
return
|
|
42
|
+
if (typeof group === "string") {
|
|
43
|
+
return minimatch(importPath, group, { matchBase: true, });
|
|
47
44
|
}
|
|
48
|
-
if (!(
|
|
45
|
+
if (!("path" in group)) {
|
|
49
46
|
return false;
|
|
50
47
|
}
|
|
51
48
|
if (isTypeImport) {
|
|
52
|
-
return
|
|
49
|
+
return minimatch(importPath, group.path, { matchBase: true, }) && group.types !== TypeImport.Exclude.key;
|
|
53
50
|
}
|
|
54
|
-
return
|
|
51
|
+
return minimatch(importPath, group.path, { matchBase: true, }) && group.types !== TypeImport.Only.key;
|
|
55
52
|
});
|
|
56
53
|
if (hardCodedIndex >= 0) {
|
|
57
54
|
return hardCodedIndex;
|
|
58
55
|
}
|
|
59
56
|
// split path at / delimiter but keep first / for absolute paths
|
|
60
|
-
const [moduleName] = importPath.split(/(?=^\/)|\//u);
|
|
57
|
+
const [moduleName,] = importPath.split(/(?=^\/)|\//u);
|
|
61
58
|
if (!moduleName) {
|
|
62
59
|
throw new Error(`group-imports: unexpected undefined module name for path '${importPath}'`);
|
|
63
60
|
}
|
|
64
61
|
let moduleClass = ModuleClass.External;
|
|
65
|
-
if (
|
|
62
|
+
if (isBuiltin(moduleName)) {
|
|
66
63
|
moduleClass = ModuleClass.Node;
|
|
67
64
|
}
|
|
65
|
+
else if (moduleName.startsWith("#")) {
|
|
66
|
+
moduleClass = ModuleClass.Internal;
|
|
67
|
+
}
|
|
68
68
|
else if (/^(?:\/|\.)/u.exec(moduleName)) {
|
|
69
|
-
moduleClass =
|
|
69
|
+
moduleClass = isAbsolute(moduleName) ? ModuleClass.Absolute : ModuleClass.Relative;
|
|
70
70
|
}
|
|
71
71
|
const classIndex = findIndex((group) => {
|
|
72
|
-
if (typeof group !==
|
|
72
|
+
if (typeof group !== "object" || !("class" in group)) {
|
|
73
73
|
return false;
|
|
74
74
|
}
|
|
75
75
|
if (isTypeImport) {
|
|
@@ -83,14 +83,14 @@ function checkLines(context, previous, next, lineCount) {
|
|
|
83
83
|
if (!previous || !next) {
|
|
84
84
|
throw new Error(`group-imports: unexpected undefined node`);
|
|
85
85
|
}
|
|
86
|
-
const tokensBetween = context.sourceCode.getTokensBetween(previous, next, { includeComments: true });
|
|
87
|
-
const relevantItems = [previous];
|
|
86
|
+
const tokensBetween = context.sourceCode.getTokensBetween(previous, next, { includeComments: true, });
|
|
87
|
+
const relevantItems = [previous,];
|
|
88
88
|
for (const token of tokensBetween) {
|
|
89
|
-
if (!
|
|
89
|
+
if (!isComment(token)) {
|
|
90
90
|
return context.report({
|
|
91
91
|
loc: {
|
|
92
|
-
start:
|
|
93
|
-
end:
|
|
92
|
+
start: assertLoc(tokensBetween.find((t) => !isComment(t))).start,
|
|
93
|
+
end: assertLoc(tokensBetween.findLast((t) => !isComment(t))).end,
|
|
94
94
|
},
|
|
95
95
|
message: `Unexpected code between imports of group`,
|
|
96
96
|
});
|
|
@@ -101,14 +101,14 @@ function checkLines(context, previous, next, lineCount) {
|
|
|
101
101
|
for (let i = 0; i < relevantItems.length - 1; i++) {
|
|
102
102
|
const a = relevantItems[i];
|
|
103
103
|
const b = relevantItems[i + 1];
|
|
104
|
-
const locA =
|
|
105
|
-
const locB =
|
|
106
|
-
const rangeA =
|
|
107
|
-
const rangeB =
|
|
104
|
+
const locA = assertLoc(a);
|
|
105
|
+
const locB = assertLoc(b);
|
|
106
|
+
const rangeA = assertRange(a);
|
|
107
|
+
const rangeB = assertRange(b);
|
|
108
108
|
const linesBetween = locB.start.line - locA.end.line - 1;
|
|
109
109
|
if (lineCount === 0) {
|
|
110
110
|
if (linesBetween > 0) {
|
|
111
|
-
const range = [rangeA[1], rangeB[0] - locB.start.column];
|
|
111
|
+
const range = [rangeA[1], rangeB[0] - locB.start.column,];
|
|
112
112
|
context.report({
|
|
113
113
|
loc: {
|
|
114
114
|
start: locA.end,
|
|
@@ -118,12 +118,12 @@ function checkLines(context, previous, next, lineCount) {
|
|
|
118
118
|
},
|
|
119
119
|
},
|
|
120
120
|
message: `Unexpected white space between imports`,
|
|
121
|
-
fix: (fixer) => fixer.replaceTextRange(range,
|
|
121
|
+
fix: (fixer) => fixer.replaceTextRange(range, "\n"),
|
|
122
122
|
});
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
125
|
else {
|
|
126
|
-
const columnOffset =
|
|
126
|
+
const columnOffset = isComment(b) ? 0 : locB.start.column;
|
|
127
127
|
const reportLoc = {
|
|
128
128
|
start: locA.end,
|
|
129
129
|
end: {
|
|
@@ -131,8 +131,8 @@ function checkLines(context, previous, next, lineCount) {
|
|
|
131
131
|
column: columnOffset,
|
|
132
132
|
},
|
|
133
133
|
};
|
|
134
|
-
const fix = (fixer) => fixer.replaceTextRange([rangeA[1], rangeB[0] - columnOffset],
|
|
135
|
-
if (
|
|
134
|
+
const fix = (fixer) => fixer.replaceTextRange([rangeA[1], rangeB[0] - columnOffset,], "\n\n");
|
|
135
|
+
if (isComment(a) || isComment(b)) {
|
|
136
136
|
if (linesBetween > 1) {
|
|
137
137
|
context.report({
|
|
138
138
|
loc: reportLoc,
|
|
@@ -155,62 +155,62 @@ function checkLines(context, previous, next, lineCount) {
|
|
|
155
155
|
}
|
|
156
156
|
function groupLabels(groups) {
|
|
157
157
|
return groups.map((group) => {
|
|
158
|
-
if (group instanceof Array || typeof group ===
|
|
159
|
-
return
|
|
158
|
+
if (group instanceof Array || typeof group === "string" || "path" in group || "pattern" in group) {
|
|
159
|
+
return "custom";
|
|
160
160
|
}
|
|
161
161
|
return group.class.toUpperCase();
|
|
162
162
|
});
|
|
163
163
|
}
|
|
164
|
-
|
|
164
|
+
export const rule = {
|
|
165
165
|
meta: {
|
|
166
|
-
fixable:
|
|
166
|
+
fixable: "code",
|
|
167
167
|
schema: {
|
|
168
168
|
definitions: {
|
|
169
169
|
typeImportConfiguration: {
|
|
170
|
-
enum: [...TypeImport.keys()],
|
|
170
|
+
enum: [...TypeImport.keys(),],
|
|
171
171
|
},
|
|
172
172
|
moduleConfiguration: {
|
|
173
173
|
oneOf: [
|
|
174
|
-
{ type:
|
|
174
|
+
{ type: "string", },
|
|
175
175
|
{
|
|
176
|
-
type:
|
|
176
|
+
type: "object",
|
|
177
177
|
properties: {
|
|
178
178
|
class: {
|
|
179
|
-
enum: [...ModuleClass.keys()],
|
|
179
|
+
enum: [...ModuleClass.keys(),],
|
|
180
180
|
},
|
|
181
181
|
types: {
|
|
182
|
-
$ref:
|
|
182
|
+
$ref: "#/definitions/typeImportConfiguration",
|
|
183
183
|
},
|
|
184
184
|
},
|
|
185
|
-
required: [
|
|
185
|
+
required: ["class",],
|
|
186
186
|
additionalProperties: false,
|
|
187
187
|
},
|
|
188
188
|
{
|
|
189
|
-
type:
|
|
189
|
+
type: "object",
|
|
190
190
|
properties: {
|
|
191
191
|
path: {
|
|
192
|
-
type:
|
|
192
|
+
type: "string",
|
|
193
193
|
},
|
|
194
194
|
types: {
|
|
195
|
-
$ref:
|
|
195
|
+
$ref: "#/definitions/typeImportConfiguration",
|
|
196
196
|
},
|
|
197
197
|
},
|
|
198
|
-
required: [
|
|
198
|
+
required: ["path",],
|
|
199
199
|
additionalProperties: false,
|
|
200
200
|
},
|
|
201
201
|
],
|
|
202
202
|
},
|
|
203
203
|
},
|
|
204
|
-
type:
|
|
204
|
+
type: "array",
|
|
205
205
|
items: {
|
|
206
206
|
anyOf: [
|
|
207
207
|
{
|
|
208
|
-
$ref:
|
|
208
|
+
$ref: "#/definitions/moduleConfiguration",
|
|
209
209
|
},
|
|
210
210
|
{
|
|
211
|
-
type:
|
|
211
|
+
type: "array",
|
|
212
212
|
items: {
|
|
213
|
-
$ref:
|
|
213
|
+
$ref: "#/definitions/moduleConfiguration",
|
|
214
214
|
},
|
|
215
215
|
},
|
|
216
216
|
],
|
|
@@ -220,7 +220,7 @@ exports.rule = {
|
|
|
220
220
|
create(context) {
|
|
221
221
|
const groupConfigurations = context.options.length ? context.options : defaultConfiguration;
|
|
222
222
|
const source = context.sourceCode;
|
|
223
|
-
const imports =
|
|
223
|
+
const imports = importModules(source).map((node) => {
|
|
224
224
|
return {
|
|
225
225
|
index: groupIndex(node, groupConfigurations),
|
|
226
226
|
node,
|
|
@@ -229,7 +229,7 @@ exports.rule = {
|
|
|
229
229
|
if (imports.length === 0) {
|
|
230
230
|
return {};
|
|
231
231
|
}
|
|
232
|
-
const sorted =
|
|
232
|
+
const sorted = sortByPath(imports, ["index",]);
|
|
233
233
|
let previousIndex = sorted[0]?.index;
|
|
234
234
|
const groups = sorted.reduce((result, value) => {
|
|
235
235
|
const current = result.at(-1);
|
|
@@ -237,16 +237,16 @@ exports.rule = {
|
|
|
237
237
|
current.push(value.node);
|
|
238
238
|
}
|
|
239
239
|
else {
|
|
240
|
-
result.push([value.node]);
|
|
240
|
+
result.push([value.node,]);
|
|
241
241
|
}
|
|
242
242
|
previousIndex = value.index;
|
|
243
243
|
return result;
|
|
244
|
-
}, [[]]);
|
|
244
|
+
}, [[],]);
|
|
245
245
|
if (sorted.some((node, i) => node !== imports[i])) {
|
|
246
|
-
|
|
247
|
-
range:
|
|
248
|
-
message: `Expected import groups: ${groupLabels(groupConfigurations).join(
|
|
249
|
-
code: groups.map((nodes) => nodes.map((node) => source.getText(node)).join(
|
|
246
|
+
fixRange(context, {
|
|
247
|
+
range: extrema(imports.map(({ node, }) => node)),
|
|
248
|
+
message: `Expected import groups: ${groupLabels(groupConfigurations).join(", ")}`,
|
|
249
|
+
code: groups.map((nodes) => nodes.map((node) => source.getText(node)).join("\n")).join("\n\n"),
|
|
250
250
|
});
|
|
251
251
|
}
|
|
252
252
|
else {
|
|
@@ -260,7 +260,7 @@ exports.rule = {
|
|
|
260
260
|
return;
|
|
261
261
|
}
|
|
262
262
|
const previous = groups[i - 1]?.at(-1);
|
|
263
|
-
const [current] = group;
|
|
263
|
+
const [current,] = group;
|
|
264
264
|
checkLines(context, previous, current, 1);
|
|
265
265
|
});
|
|
266
266
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"group-imports.js","sourceRoot":"","sources":["../../src/rules/group-imports.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"group-imports.js","sourceRoot":"","sources":["../../src/rules/group-imports.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AAIvC,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACpC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,oBAAoB,EAAgC,MAAM,iBAAiB,CAAC;AAChJ,OAAO,EAAE,QAAQ,EAAqC,MAAM,kBAAkB,CAAC;AAC/E,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAK9C,MAAM,aAAa,GAAG,MAAM,EAAE,CAAC;AAC/B,MAAM,YAAY,GAAG,MAAM,EAAE,CAAC;AAE9B,MAAM,OAAO,WAAY,SAAQ,IAAI,CAA8B,aAAa,CAAC;IAChF,MAAM,CAAU,IAAI,GAAG,IAAI,WAAW,CAAC,aAAa,EAAE,EAAE,GAAG,EAAE,MAAM,GAAG,CAAC,CAAC;IACxE,MAAM,CAAU,QAAQ,GAAG,IAAI,WAAW,CAAC,aAAa,EAAE,EAAE,GAAG,EAAE,UAAU,GAAG,CAAC,CAAC;IAChF,MAAM,CAAU,QAAQ,GAAG,IAAI,WAAW,CAAC,aAAa,EAAE,EAAE,GAAG,EAAE,UAAU,GAAG,CAAC,CAAC;IAChF,MAAM,CAAU,QAAQ,GAAG,IAAI,WAAW,CAAC,aAAa,EAAE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AC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;oBACvC,MAAM,QAAQ,GAAG,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;oBAC9B,MAAM,OAAO,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC;oBACzB,UAAU,CAAC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC;gBAC3C,CAAC;gBAED,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC;oBACb,OAAO;gBACR,CAAC;gBAED,MAAM,QAAQ,GAAG,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;gBACvC,MAAM,CAAE,OAAO,EAAG,GAAG,KAAK,CAAC;gBAC3B,UAAU,CAAC,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC;YAC3C,CAAC,CAAC,CAAC;QACJ,CAAC;QAED,OAAO,EAAE,CAAC;IACX,CAAC;CACD,CAAC"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import type
|
|
3
|
-
export type GroupPositionOption =
|
|
4
|
-
export type InlinePositionOption =
|
|
1
|
+
import { type RuleModule } from "../tools/rule.ts";
|
|
2
|
+
import { type SortOptions } from "../tools/sort.ts";
|
|
3
|
+
export type GroupPositionOption = "ignore" | "top" | "bottom" | "above-value" | "below-value";
|
|
4
|
+
export type InlinePositionOption = "ignore" | "start" | "end";
|
|
5
5
|
declare const TypeImportGroupPosition_base: import("@shigen/enum").EnumConstructor<{
|
|
6
6
|
Key: GroupPositionOption;
|
|
7
7
|
}, [fields: {
|
|
8
|
-
readonly name?: string
|
|
8
|
+
readonly name?: string;
|
|
9
9
|
readonly key: GroupPositionOption;
|
|
10
10
|
}]>;
|
|
11
11
|
export declare class TypeImportGroupPosition extends TypeImportGroupPosition_base {
|
|
@@ -18,7 +18,7 @@ export declare class TypeImportGroupPosition extends TypeImportGroupPosition_bas
|
|
|
18
18
|
declare const TypeImportInlinePosition_base: import("@shigen/enum").EnumConstructor<{
|
|
19
19
|
Key: InlinePositionOption;
|
|
20
20
|
}, [fields: {
|
|
21
|
-
readonly name?: string
|
|
21
|
+
readonly name?: string;
|
|
22
22
|
readonly key: InlinePositionOption;
|
|
23
23
|
}]>;
|
|
24
24
|
export declare class TypeImportInlinePosition extends TypeImportInlinePosition_base {
|
|
@@ -27,7 +27,7 @@ export declare class TypeImportInlinePosition extends TypeImportInlinePosition_b
|
|
|
27
27
|
static readonly End: TypeImportInlinePosition;
|
|
28
28
|
}
|
|
29
29
|
export interface Configuration extends SortOptions {
|
|
30
|
-
specifier:
|
|
30
|
+
specifier: "source" | "rename";
|
|
31
31
|
sortExports: boolean;
|
|
32
32
|
typesInGroup: GroupPositionOption;
|
|
33
33
|
inlineTypes: InlinePositionOption;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sort-imports.d.ts","sourceRoot":"","sources":["../../src/rules/sort-imports.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"sort-imports.d.ts","sourceRoot":"","sources":["../../src/rules/sort-imports.ts"],"names":[],"mappings":"AAeA,OAAO,EAAY,KAAK,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAc,KAAK,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEhE,MAAM,MAAM,mBAAmB,GAAG,QAAQ,GAAG,KAAK,GAAG,QAAQ,GAAG,aAAa,GAAG,aAAa,CAAC;AAC9F,MAAM,MAAM,oBAAoB,GAAG,QAAQ,GAAG,OAAO,GAAG,KAAK,CAAC;;SAKL,mBAAmB;;;;;AAA5E,qBAAa,uBAAwB,SAAQ,4BAA8D;IAC1G,MAAM,CAAC,QAAQ,CAAC,MAAM,0BAA8E;IACpG,MAAM,CAAC,QAAQ,CAAC,GAAG,0BAA2E;IAC9F,MAAM,CAAC,QAAQ,CAAC,MAAM,0BAA8E;IACpG,MAAM,CAAC,QAAQ,CAAC,UAAU,0BAAmF;IAC7G,MAAM,CAAC,QAAQ,CAAC,UAAU,0BAAmF;CAC7G;;SAEyD,oBAAoB;;;;;AAA9E,qBAAa,wBAAyB,SAAQ,6BAAgE;IAC7G,MAAM,CAAC,QAAQ,CAAC,MAAM,2BAAgF;IACtG,MAAM,CAAC,QAAQ,CAAC,KAAK,2BAA+E;IACpG,MAAM,CAAC,QAAQ,CAAC,GAAG,2BAA6E;CAChG;AAED,MAAM,WAAW,aAAc,SAAQ,WAAW;IACjD,SAAS,EAAE,QAAQ,GAAG,QAAQ,CAAC;IAC/B,WAAW,EAAE,OAAO,CAAC;IACrB,YAAY,EAAE,mBAAmB,CAAC;IAClC,WAAW,EAAE,oBAAoB,CAAC;CAClC;AAYD,eAAO,MAAM,IAAI,EAAE,UAAU,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CA6KtD,CAAC"}
|
|
@@ -1,99 +1,93 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const ast_js_1 = require("../tools/ast.js");
|
|
6
|
-
const rule_js_1 = require("../tools/rule.js");
|
|
7
|
-
const sort_js_1 = require("../tools/sort.js");
|
|
1
|
+
import { Enum } from "@shigen/enum";
|
|
2
|
+
import { exportModules, extrema, importModules, isTypeImportOrExport, linesBetween, } from "../tools/ast.js";
|
|
3
|
+
import { fixRange } from "../tools/rule.js";
|
|
4
|
+
import { sortByPath } from "../tools/sort.js";
|
|
8
5
|
const typeImportGroupPositionId = Symbol();
|
|
9
6
|
const typeImportInlinePositionId = Symbol();
|
|
10
|
-
class TypeImportGroupPosition extends
|
|
11
|
-
static Ignore = new TypeImportGroupPosition(typeImportGroupPositionId, { key:
|
|
12
|
-
static Top = new TypeImportGroupPosition(typeImportGroupPositionId, { key:
|
|
13
|
-
static Bottom = new TypeImportGroupPosition(typeImportGroupPositionId, { key:
|
|
14
|
-
static AboveValue = new TypeImportGroupPosition(typeImportGroupPositionId, { key:
|
|
15
|
-
static BelowValue = new TypeImportGroupPosition(typeImportGroupPositionId, { key:
|
|
7
|
+
export class TypeImportGroupPosition extends Enum(typeImportGroupPositionId) {
|
|
8
|
+
static Ignore = new TypeImportGroupPosition(typeImportGroupPositionId, { key: "ignore", });
|
|
9
|
+
static Top = new TypeImportGroupPosition(typeImportGroupPositionId, { key: "top", });
|
|
10
|
+
static Bottom = new TypeImportGroupPosition(typeImportGroupPositionId, { key: "bottom", });
|
|
11
|
+
static AboveValue = new TypeImportGroupPosition(typeImportGroupPositionId, { key: "above-value", });
|
|
12
|
+
static BelowValue = new TypeImportGroupPosition(typeImportGroupPositionId, { key: "below-value", });
|
|
16
13
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
static
|
|
20
|
-
static
|
|
21
|
-
static End = new TypeImportInlinePosition(typeImportInlinePositionId, { key: 'end' });
|
|
14
|
+
export class TypeImportInlinePosition extends Enum(typeImportInlinePositionId) {
|
|
15
|
+
static Ignore = new TypeImportInlinePosition(typeImportInlinePositionId, { key: "ignore", });
|
|
16
|
+
static Start = new TypeImportInlinePosition(typeImportInlinePositionId, { key: "start", });
|
|
17
|
+
static End = new TypeImportInlinePosition(typeImportInlinePositionId, { key: "end", });
|
|
22
18
|
}
|
|
23
|
-
exports.TypeImportInlinePosition = TypeImportInlinePosition;
|
|
24
19
|
const defaultConfiguration = {
|
|
25
|
-
specifier:
|
|
26
|
-
locales: [
|
|
20
|
+
specifier: "source",
|
|
21
|
+
locales: ["en-US",],
|
|
27
22
|
numeric: true,
|
|
28
|
-
caseFirst:
|
|
23
|
+
caseFirst: "lower",
|
|
29
24
|
sortExports: true,
|
|
30
25
|
typesInGroup: TypeImportGroupPosition.Ignore.key,
|
|
31
26
|
inlineTypes: TypeImportInlinePosition.Ignore.key,
|
|
32
27
|
};
|
|
33
|
-
|
|
28
|
+
export const rule = {
|
|
34
29
|
meta: {
|
|
35
|
-
fixable:
|
|
30
|
+
fixable: "code",
|
|
36
31
|
schema: [
|
|
37
32
|
{
|
|
38
|
-
type:
|
|
33
|
+
type: "object",
|
|
39
34
|
properties: {
|
|
40
35
|
locales: {
|
|
41
|
-
type:
|
|
36
|
+
type: "array",
|
|
42
37
|
items: {
|
|
43
|
-
type:
|
|
38
|
+
type: "string",
|
|
44
39
|
},
|
|
45
40
|
},
|
|
46
41
|
sensitivity: {
|
|
47
|
-
enum: [
|
|
42
|
+
enum: ["base", "accent", "case", "variant",],
|
|
48
43
|
},
|
|
49
44
|
ignorePunctuation: {
|
|
50
|
-
type:
|
|
45
|
+
type: "boolean",
|
|
51
46
|
},
|
|
52
47
|
numeric: {
|
|
53
|
-
type:
|
|
48
|
+
type: "boolean",
|
|
54
49
|
},
|
|
55
50
|
caseFirst: {
|
|
56
|
-
enum: [
|
|
51
|
+
enum: ["upper", "lower", "false",],
|
|
57
52
|
},
|
|
58
53
|
caseGroups: {
|
|
59
|
-
type:
|
|
54
|
+
type: "boolean",
|
|
60
55
|
},
|
|
61
56
|
specifier: {
|
|
62
|
-
enum: [
|
|
57
|
+
enum: ["source", "rename",],
|
|
63
58
|
},
|
|
64
59
|
sortExports: {
|
|
65
|
-
type:
|
|
60
|
+
type: "boolean",
|
|
66
61
|
},
|
|
67
62
|
typesInGroup: {
|
|
68
|
-
enum: [...TypeImportGroupPosition.keys()],
|
|
63
|
+
enum: [...TypeImportGroupPosition.keys(),],
|
|
69
64
|
},
|
|
70
65
|
inlineTypes: {
|
|
71
|
-
enum: [...TypeImportInlinePosition.keys()],
|
|
66
|
+
enum: [...TypeImportInlinePosition.keys(),],
|
|
72
67
|
},
|
|
73
68
|
},
|
|
74
69
|
},
|
|
75
70
|
],
|
|
76
71
|
},
|
|
77
72
|
create(context) {
|
|
78
|
-
const configuration = { ...defaultConfiguration, ...context.options[0] };
|
|
73
|
+
const configuration = { ...defaultConfiguration, ...context.options[0], };
|
|
79
74
|
const source = context.sourceCode;
|
|
80
75
|
const partition = (result, node, index, from) => {
|
|
81
|
-
if (index > 0 &&
|
|
76
|
+
if (index > 0 && linesBetween(from[index - 1], node) > 0) {
|
|
82
77
|
result.push([]);
|
|
83
78
|
}
|
|
84
79
|
result.at(-1)?.push(node);
|
|
85
80
|
return result;
|
|
86
81
|
};
|
|
87
82
|
const sortModules = (group) => {
|
|
88
|
-
const sorted =
|
|
83
|
+
const sorted = sortByPath(group, ["source", "value",], configuration);
|
|
89
84
|
if (configuration.typesInGroup !== TypeImportGroupPosition.Ignore.key) {
|
|
90
85
|
sorted.sort((a, b) => {
|
|
91
|
-
const aIsType =
|
|
92
|
-
const bIsType =
|
|
86
|
+
const aIsType = isTypeImportOrExport(a);
|
|
87
|
+
const bIsType = isTypeImportOrExport(b);
|
|
93
88
|
if (aIsType === bIsType) {
|
|
94
89
|
return 0;
|
|
95
90
|
}
|
|
96
|
-
// eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
|
|
97
91
|
switch (configuration.typesInGroup) {
|
|
98
92
|
case TypeImportGroupPosition.Top.key:
|
|
99
93
|
return aIsType ? -1 : 1;
|
|
@@ -101,7 +95,6 @@ exports.rule = {
|
|
|
101
95
|
return aIsType ? 1 : -1;
|
|
102
96
|
}
|
|
103
97
|
if (a.source.value === b.source.value) {
|
|
104
|
-
// eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
|
|
105
98
|
switch (configuration.typesInGroup) {
|
|
106
99
|
case TypeImportGroupPosition.AboveValue.key:
|
|
107
100
|
return aIsType ? -1 : 1;
|
|
@@ -113,40 +106,39 @@ exports.rule = {
|
|
|
113
106
|
});
|
|
114
107
|
}
|
|
115
108
|
if (sorted.some((node, i) => node !== group[i])) {
|
|
116
|
-
|
|
117
|
-
range:
|
|
118
|
-
message:
|
|
119
|
-
code: sorted.map((node) => source.getText(node)).join(
|
|
109
|
+
fixRange(context, {
|
|
110
|
+
range: extrema(group),
|
|
111
|
+
message: "Expected modules in group to be sorted",
|
|
112
|
+
code: sorted.map((node) => source.getText(node)).join("\n"),
|
|
120
113
|
});
|
|
121
114
|
}
|
|
122
115
|
};
|
|
123
116
|
const specifiersText = (nodes) => {
|
|
124
117
|
if (nodes[0]?.loc?.start.line !== nodes[1]?.loc?.start.line) {
|
|
125
|
-
const indent = source.lines[nodes[0].loc.start.line - 1]?.match(/^\s+/g)?.[0] ??
|
|
126
|
-
return nodes.map((node, index) => `${index > 0 ? indent :
|
|
118
|
+
const indent = source.lines[nodes[0].loc.start.line - 1]?.match(/^\s+/g)?.[0] ?? "";
|
|
119
|
+
return nodes.map((node, index) => `${index > 0 ? indent : ""}${source.getText(node)}`).join(",\n");
|
|
127
120
|
}
|
|
128
|
-
return nodes.map((node) => source.getText(node)).join(
|
|
121
|
+
return nodes.map((node) => source.getText(node)).join(", ");
|
|
129
122
|
};
|
|
130
123
|
const sortSpecifiers = (specifiers) => {
|
|
131
124
|
if (!specifiers.length) {
|
|
132
125
|
return;
|
|
133
126
|
}
|
|
134
127
|
const sorted = (() => {
|
|
135
|
-
if (specifiers[0]?.type ===
|
|
136
|
-
const from = configuration.specifier ===
|
|
137
|
-
return
|
|
128
|
+
if (specifiers[0]?.type === "ImportSpecifier") {
|
|
129
|
+
const from = configuration.specifier === "source" ? "imported" : "local";
|
|
130
|
+
return sortByPath(specifiers, [from, "name",], configuration);
|
|
138
131
|
}
|
|
139
|
-
const from = configuration.specifier ===
|
|
140
|
-
return
|
|
132
|
+
const from = configuration.specifier === "source" ? "local" : "exported";
|
|
133
|
+
return sortByPath(specifiers, [from, "name",], configuration);
|
|
141
134
|
})();
|
|
142
135
|
if (configuration.inlineTypes !== TypeImportInlinePosition.Ignore.key) {
|
|
143
136
|
sorted.sort((a, b) => {
|
|
144
|
-
const aIsType =
|
|
145
|
-
const bIsType =
|
|
137
|
+
const aIsType = isTypeImportOrExport(a);
|
|
138
|
+
const bIsType = isTypeImportOrExport(b);
|
|
146
139
|
if (aIsType === bIsType) {
|
|
147
140
|
return 0;
|
|
148
141
|
}
|
|
149
|
-
// eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
|
|
150
142
|
switch (configuration.inlineTypes) {
|
|
151
143
|
case TypeImportInlinePosition.Start.key:
|
|
152
144
|
return aIsType ? -1 : 1;
|
|
@@ -157,24 +149,24 @@ exports.rule = {
|
|
|
157
149
|
});
|
|
158
150
|
}
|
|
159
151
|
if (sorted.some((node, i) => node !== specifiers[i])) {
|
|
160
|
-
|
|
161
|
-
range:
|
|
162
|
-
message:
|
|
152
|
+
fixRange(context, {
|
|
153
|
+
range: extrema(specifiers),
|
|
154
|
+
message: "Expected specifiers to be sorted",
|
|
163
155
|
code: specifiersText(sorted),
|
|
164
156
|
});
|
|
165
157
|
}
|
|
166
158
|
};
|
|
167
|
-
|
|
168
|
-
.reduce(partition, [[]])
|
|
159
|
+
importModules(source)
|
|
160
|
+
.reduce(partition, [[],])
|
|
169
161
|
.forEach((group) => {
|
|
170
162
|
sortModules(group);
|
|
171
163
|
group.forEach((node) => {
|
|
172
|
-
sortSpecifiers(node.specifiers.filter(($) => $.type ===
|
|
164
|
+
sortSpecifiers(node.specifiers.filter(($) => $.type === "ImportSpecifier"));
|
|
173
165
|
});
|
|
174
166
|
});
|
|
175
167
|
if (configuration.sortExports) {
|
|
176
|
-
|
|
177
|
-
.reduce(partition, [[]])
|
|
168
|
+
exportModules(source)
|
|
169
|
+
.reduce(partition, [[],])
|
|
178
170
|
.forEach((group) => {
|
|
179
171
|
sortModules(group);
|
|
180
172
|
group.forEach((node) => sortSpecifiers(node.specifiers ?? []));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sort-imports.js","sourceRoot":"","sources":["../../src/rules/sort-imports.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"sort-imports.js","sourceRoot":"","sources":["../../src/rules/sort-imports.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAEpC,OAAO,EACN,aAAa,EACb,OAAO,EACP,aAAa,EACb,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,CAAC,KAAK,CAAC,CAAC;YACnB,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;gBACtB,cAAc,CAAC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,EAAwB,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,iBAAiB,CAAC,CAAC,CAAC;YACnG,CAAC,CAAC,CAAC;QACJ,CAAC,CAAC,CAAC;QAEJ,IAAI,aAAa,CAAC,WAAW,EAAE,CAAC;YAC/B,aAAa,CAAC,MAAM,CAAC;iBACnB,MAAM,CAA8B,SAAS,EAAE,CAAE,EAAE,EAAG,CAAC;iBACvD,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;gBAClB,WAAW,CAAC,KAAK,CAAC,CAAC;gBACnB,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,cAAc,CAAC,IAAI,CAAC,UAAU,IAAI,EAAE,CAAC,CAAC,CAAC;YAChE,CAAC,CAAC,CAAC;QACL,CAAC;QAED,OAAO,EAAE,CAAC;IACX,CAAC;CACD,CAAC"}
|
package/dist/tools/ast.d.ts
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import type { TSESTree } from
|
|
2
|
-
import type { AST, SourceCode } from
|
|
3
|
-
import type estree from
|
|
4
|
-
export type ImportModuleDeclaration = estree.ImportDeclaration & Partial<Pick<TSESTree.ImportDeclaration,
|
|
5
|
-
export type ExportModuleDeclaration = estree.ExportAllDeclaration & Partial<Pick<estree.ExportNamedDeclaration,
|
|
1
|
+
import type { TSESTree } from "@typescript-eslint/types";
|
|
2
|
+
import type { AST, SourceCode } from "eslint";
|
|
3
|
+
import type estree from "estree";
|
|
4
|
+
export type ImportModuleDeclaration = estree.ImportDeclaration & Partial<Pick<TSESTree.ImportDeclaration, "importKind">>;
|
|
5
|
+
export type ExportModuleDeclaration = estree.ExportAllDeclaration & Partial<Pick<estree.ExportNamedDeclaration, "specifiers"> & Pick<TSESTree.ExportAllDeclaration, "exportKind">>;
|
|
6
6
|
export type ModuleDeclaration = ImportModuleDeclaration | ExportModuleDeclaration;
|
|
7
|
-
export type ImportSpecifier = estree.ImportSpecifier & Partial<Pick<TSESTree.ImportSpecifier,
|
|
8
|
-
export type ExportSpecifier = estree.ExportSpecifier & Partial<Pick<TSESTree.ExportSpecifier,
|
|
7
|
+
export type ImportSpecifier = estree.ImportSpecifier & Partial<Pick<TSESTree.ImportSpecifier, "importKind">>;
|
|
8
|
+
export type ExportSpecifier = estree.ExportSpecifier & Partial<Pick<TSESTree.ExportSpecifier, "exportKind">>;
|
|
9
9
|
export declare function importModules(source: SourceCode): ImportModuleDeclaration[];
|
|
10
10
|
export declare function exportModules(source: SourceCode): ExportModuleDeclaration[];
|
|
11
11
|
export declare function isTypeImportOrExport(node: ModuleDeclaration | ImportSpecifier | ExportSpecifier): boolean;
|
|
@@ -13,9 +13,9 @@ export declare function extrema<T extends estree.Node>(source: readonly T[]): [T
|
|
|
13
13
|
export declare function linesBetween(a: estree.Node | undefined, b: estree.Node | undefined): number;
|
|
14
14
|
export declare function isComment(value: AST.Token | estree.Comment | estree.Node): value is estree.Comment;
|
|
15
15
|
export declare function assertLoc(value: {
|
|
16
|
-
loc?: AST.SourceLocation | null;
|
|
16
|
+
loc?: AST.SourceLocation | null | undefined;
|
|
17
17
|
} | undefined): AST.SourceLocation;
|
|
18
18
|
export declare function assertRange(value: {
|
|
19
|
-
range?: AST.Range | null;
|
|
19
|
+
range?: AST.Range | null | undefined;
|
|
20
20
|
} | undefined): AST.Range;
|
|
21
21
|
//# sourceMappingURL=ast.d.ts.map
|
package/dist/tools/ast.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ast.d.ts","sourceRoot":"","sources":["../../src/tools/ast.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACzD,OAAO,KAAK,EAAE,GAAG,EAAE,UAAU,EAAE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E,UAAU,GAAG,uBAAuB,EAAE,CAK3E;AAED,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,iBAAiB,GAAG,eAAe,GAAG,eAAe,GAAG,OAAO,CAEzG;AAED,wBAAgB,OAAO,CAAC,CAAC,SAAS,MAAM,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAQ3E;AAED,wBAAgB,YAAY,CAAC,CAAC,EAAE,MAAM,CAAC,IAAI,GAAG,SAAS,EAAE,CAAC,EAAE,MAAM,CAAC,IAAI,GAAG,SAAS,GAAG,MAAM,CAM3F;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,GAAG,CAAC,KAAK,GAAG,MAAM,CAAC,OAAO,GAAG,MAAM,CAAC,IAAI,GAAG,KAAK,IAAI,MAAM,CAAC,OAAO,CAElG;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE;IAAE,GAAG,CAAC,EAAE,GAAG,CAAC,cAAc,GAAG,IAAI,GAAG,SAAS,CAAC;CAAE,GAAG,SAAS,GAAG,GAAG,CAAC,cAAc,CAMjH;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE;IAAE,KAAK,CAAC,EAAE,GAAG,CAAC,KAAK,GAAG,IAAI,GAAG,SAAS,CAAC;CAAE,GAAG,SAAS,GAAG,GAAG,CAAC,KAAK,CAMnG"}
|
package/dist/tools/ast.js
CHANGED
|
@@ -1,49 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
function
|
|
5
|
-
return source.ast.body.filter((node) => node.type ===
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
function isTypeImportOrExport(node) {
|
|
13
|
-
return ('importKind' in node && node.importKind === 'type') || ('exportKind' in node && node.exportKind === 'type');
|
|
14
|
-
}
|
|
15
|
-
exports.isTypeImportOrExport = isTypeImportOrExport;
|
|
16
|
-
function extrema(source) {
|
|
17
|
-
const [a, b] = [source.at(0), source.at(-1)];
|
|
1
|
+
export function importModules(source) {
|
|
2
|
+
return source.ast.body.filter((node) => node.type === "ImportDeclaration");
|
|
3
|
+
}
|
|
4
|
+
export function exportModules(source) {
|
|
5
|
+
return source.ast.body.filter((node) => (node.type === "ExportNamedDeclaration" || node.type === "ExportAllDeclaration") && Boolean(node.source));
|
|
6
|
+
}
|
|
7
|
+
export function isTypeImportOrExport(node) {
|
|
8
|
+
return ("importKind" in node && node.importKind === "type") || ("exportKind" in node && node.exportKind === "type");
|
|
9
|
+
}
|
|
10
|
+
export function extrema(source) {
|
|
11
|
+
const [a, b,] = [source.at(0), source.at(-1),];
|
|
18
12
|
if (!a || !b) {
|
|
19
13
|
throw new Error(`extrema: invalid input`);
|
|
20
14
|
}
|
|
21
|
-
return [a, b];
|
|
15
|
+
return [a, b,];
|
|
22
16
|
}
|
|
23
|
-
|
|
24
|
-
function linesBetween(a, b) {
|
|
17
|
+
export function linesBetween(a, b) {
|
|
25
18
|
if (!a?.loc || !b?.loc) {
|
|
26
19
|
throw new Error(`error: AST was generated without node location information`);
|
|
27
20
|
}
|
|
28
21
|
return b.loc.start.line - a.loc.end.line - 1;
|
|
29
22
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
return value.type === 'Block' || value.type === 'Line';
|
|
23
|
+
export function isComment(value) {
|
|
24
|
+
return value.type === "Block" || value.type === "Line";
|
|
33
25
|
}
|
|
34
|
-
|
|
35
|
-
function assertLoc(value) {
|
|
26
|
+
export function assertLoc(value) {
|
|
36
27
|
if (value?.loc) {
|
|
37
28
|
return value.loc;
|
|
38
29
|
}
|
|
39
30
|
throw new Error(`error: AST was generated without node location information`);
|
|
40
31
|
}
|
|
41
|
-
|
|
42
|
-
function assertRange(value) {
|
|
32
|
+
export function assertRange(value) {
|
|
43
33
|
if (value?.range) {
|
|
44
34
|
return value.range;
|
|
45
35
|
}
|
|
46
36
|
throw new Error();
|
|
47
37
|
}
|
|
48
|
-
exports.assertRange = assertRange;
|
|
49
38
|
//# sourceMappingURL=ast.js.map
|
package/dist/tools/ast.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ast.js","sourceRoot":"","sources":["../../src/tools/ast.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ast.js","sourceRoot":"","sources":["../../src/tools/ast.ts"],"names":[],"mappings":"AAeA,MAAM,UAAU,aAAa,CAAC,MAAkB;IAC/C,OAAO,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,IAAI,EAAmC,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,mBAAmB,CAAC,CAAC;AAC7G,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,MAAkB;IAC/C,OAAO,MAAM,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAC5B,CAAC,IAAI,EAAmC,EAAE,CACzC,CAAC,IAAI,CAAC,IAAI,KAAK,wBAAwB,IAAI,IAAI,CAAC,IAAI,KAAK,sBAAsB,CAAC,IAAI,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CACzG,CAAC;AACH,CAAC;AAED,MAAM,UAAU,oBAAoB,CAAC,IAA2D;IAC/F,OAAO,CAAC,YAAY,IAAI,IAAI,IAAI,IAAI,CAAC,UAAU,KAAK,MAAM,CAAC,IAAI,CAAC,YAAY,IAAI,IAAI,IAAI,IAAI,CAAC,UAAU,KAAK,MAAM,CAAC,CAAC;AACrH,CAAC;AAED,MAAM,UAAU,OAAO,CAAwB,MAAoB;IAClE,MAAM,CAAE,CAAC,EAAE,CAAC,EAAG,GAAG,CAAE,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAG,CAAC;IAEnD,IAAI,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC;QACd,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;IAC3C,CAAC;IAED,OAAO,CAAE,CAAC,EAAE,CAAC,EAAG,CAAC;AAClB,CAAC;AAED,MAAM,UAAU,YAAY,CAAC,CAA0B,EAAE,CAA0B;IAClF,IAAI,CAAC,CAAC,EAAE,GAAG,IAAI,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC;QACxB,MAAM,IAAI,KAAK,CAAC,4DAA4D,CAAC,CAAC;IAC/E,CAAC;IAED,OAAO,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,GAAG,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,GAAG,CAAC,CAAC;AAC9C,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,KAA+C;IACxE,OAAO,KAAK,CAAC,IAAI,KAAK,OAAO,IAAI,KAAK,CAAC,IAAI,KAAK,MAAM,CAAC;AACxD,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,KAAmE;IAC5F,IAAI,KAAK,EAAE,GAAG,EAAE,CAAC;QAChB,OAAO,KAAK,CAAC,GAAG,CAAC;IAClB,CAAC;IAED,MAAM,IAAI,KAAK,CAAC,4DAA4D,CAAC,CAAC;AAC/E,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,KAA4D;IACvF,IAAI,KAAK,EAAE,KAAK,EAAE,CAAC;QAClB,OAAO,KAAK,CAAC,KAAK,CAAC;IACpB,CAAC;IAED,MAAM,IAAI,KAAK,EAAE,CAAC;AACnB,CAAC"}
|
package/dist/tools/rule.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Rule } from
|
|
2
|
-
import type { Node } from
|
|
1
|
+
import type { Rule } from "eslint";
|
|
2
|
+
import type { Node } from "estree";
|
|
3
3
|
export interface RuleContext<Configuration extends unknown[]> extends Rule.RuleContext {
|
|
4
4
|
options: Configuration;
|
|
5
5
|
}
|
package/dist/tools/rule.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.fixRange = void 0;
|
|
4
|
-
function fixRange(context, data) {
|
|
5
|
-
const [first, last] = data.range;
|
|
1
|
+
export function fixRange(context, data) {
|
|
2
|
+
const [first, last,] = data.range;
|
|
6
3
|
context.report({
|
|
7
4
|
node: last,
|
|
8
5
|
message: data.message,
|
|
@@ -10,9 +7,8 @@ function fixRange(context, data) {
|
|
|
10
7
|
if (!first.range || !last.range) {
|
|
11
8
|
return null;
|
|
12
9
|
}
|
|
13
|
-
return fixer.replaceTextRange([first.range[0], last.range[1]], data.code);
|
|
10
|
+
return fixer.replaceTextRange([first.range[0], last.range[1],], data.code);
|
|
14
11
|
},
|
|
15
12
|
});
|
|
16
13
|
}
|
|
17
|
-
exports.fixRange = fixRange;
|
|
18
14
|
//# sourceMappingURL=rule.js.map
|
package/dist/tools/rule.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rule.js","sourceRoot":"","sources":["../../src/tools/rule.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"rule.js","sourceRoot":"","sources":["../../src/tools/rule.ts"],"names":[],"mappings":"AAWA,MAAM,UAAU,QAAQ,CACvB,OAAyB,EACzB,IAIC;IAED,MAAM,CAAE,KAAK,EAAE,IAAI,EAAG,GAAG,IAAI,CAAC,KAAK,CAAC;IAEpC,OAAO,CAAC,MAAM,CAAC;QACd,IAAI,EAAE,IAAI;QACV,OAAO,EAAE,IAAI,CAAC,OAAO;QACrB,GAAG,CAAC,KAAK;YACR,IAAI,CAAC,KAAK,CAAC,KAAK,IAAI,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;gBACjC,OAAO,IAAI,CAAC;YACb,CAAC;YAED,OAAO,KAAK,CAAC,gBAAgB,CAAC,CAAE,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,EAAG,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC;QAC9E,CAAC;KACD,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/tools/sort.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
export type SortOptions = Pick<Intl.CollatorOptions,
|
|
1
|
+
export type SortOptions = Pick<Intl.CollatorOptions, "sensitivity" | "ignorePunctuation" | "numeric" | "caseFirst"> & {
|
|
2
2
|
locales?: string[];
|
|
3
3
|
caseGroups?: boolean;
|
|
4
4
|
};
|
|
5
|
-
export declare function sortByPath<T extends object
|
|
6
|
-
export declare function sortByPath<T extends object, K1 extends keyof T, K2 extends keyof T[K1]>(source: T[], path: readonly [K1, K2], options?: SortOptions): T[];
|
|
7
|
-
export declare function sortByPath<T extends object, K extends keyof T>(source: T[], path: readonly [K], options?: SortOptions): T[];
|
|
5
|
+
export declare function sortByPath<T extends object>(sources: T[], path: ReadonlyArray<string | number>, options?: SortOptions): T[];
|
|
8
6
|
//# sourceMappingURL=sort.d.ts.map
|
package/dist/tools/sort.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sort.d.ts","sourceRoot":"","sources":["../../src/tools/sort.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,aAAa,GAAG,mBAAmB,GAAG,SAAS,GAAG,WAAW,CAAC,GAAG;IACrH,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,UAAU,CAAC,EAAE,OAAO,CAAC;CACrB,CAAC;
|
|
1
|
+
{"version":3,"file":"sort.d.ts","sourceRoot":"","sources":["../../src/tools/sort.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,aAAa,GAAG,mBAAmB,GAAG,SAAS,GAAG,WAAW,CAAC,GAAG;IACrH,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,UAAU,CAAC,EAAE,OAAO,CAAC;CACrB,CAAC;AAmDF,wBAAgB,UAAU,CAAC,CAAC,SAAS,MAAM,EAC1C,OAAO,EAAE,CAAC,EAAE,EACZ,IAAI,EAAE,aAAa,CAAC,MAAM,GAAG,MAAM,CAAC,EACpC,OAAO,CAAC,EAAE,WAAW,GACnB,CAAC,EAAE,CAwCL"}
|
package/dist/tools/sort.js
CHANGED
|
@@ -1,8 +1,5 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.sortByPath = void 0;
|
|
4
1
|
function isIndexable(value) {
|
|
5
|
-
return typeof value ===
|
|
2
|
+
return typeof value === "object" && value !== null;
|
|
6
3
|
}
|
|
7
4
|
function readPath(from, path) {
|
|
8
5
|
if (!isIndexable(from)) {
|
|
@@ -19,17 +16,16 @@ function readPath(from, path) {
|
|
|
19
16
|
}
|
|
20
17
|
function sort(options) {
|
|
21
18
|
return (a, b) => {
|
|
22
|
-
if (typeof a.sortValue ===
|
|
19
|
+
if (typeof a.sortValue === "number" && typeof b.sortValue === "number") {
|
|
23
20
|
return a.sortValue - b.sortValue;
|
|
24
21
|
}
|
|
25
|
-
if (typeof a.sortValue ===
|
|
22
|
+
if (typeof a.sortValue === "string" && typeof b.sortValue === "string") {
|
|
26
23
|
return a.sortValue.localeCompare(b.sortValue, options?.locales, options);
|
|
27
24
|
}
|
|
28
25
|
return 0;
|
|
29
26
|
};
|
|
30
27
|
}
|
|
31
|
-
|
|
32
|
-
function sortByPath(sources, path, options) {
|
|
28
|
+
export function sortByPath(sources, path, options) {
|
|
33
29
|
const caseGroups = sources.reduce((groups, source) => {
|
|
34
30
|
const sortValue = readPath(source, path);
|
|
35
31
|
const sortable = {
|
|
@@ -37,7 +33,7 @@ function sortByPath(sources, path, options) {
|
|
|
37
33
|
sortValue,
|
|
38
34
|
};
|
|
39
35
|
let target = groups.lower;
|
|
40
|
-
if (options?.caseGroups && typeof sortValue ===
|
|
36
|
+
if (options?.caseGroups && typeof sortValue === "string" && sortValue.length) {
|
|
41
37
|
if (/^[@$_]/u.test(sortValue)) {
|
|
42
38
|
target = groups.punctuation;
|
|
43
39
|
}
|
|
@@ -56,10 +52,9 @@ function sortByPath(sources, path, options) {
|
|
|
56
52
|
caseGroups.upper.sort(sort(options));
|
|
57
53
|
caseGroups.lower.sort(sort(options));
|
|
58
54
|
return [
|
|
59
|
-
...caseGroups.punctuation.map(({ source }) => source),
|
|
60
|
-
...(options?.caseFirst ===
|
|
61
|
-
...(options?.caseFirst ===
|
|
55
|
+
...caseGroups.punctuation.map(({ source, }) => source),
|
|
56
|
+
...(options?.caseFirst === "upper" ? caseGroups.upper : caseGroups.lower).map(({ source, }) => source),
|
|
57
|
+
...(options?.caseFirst === "upper" ? caseGroups.lower : caseGroups.upper).map(({ source, }) => source),
|
|
62
58
|
];
|
|
63
59
|
}
|
|
64
|
-
exports.sortByPath = sortByPath;
|
|
65
60
|
//# sourceMappingURL=sort.js.map
|
package/dist/tools/sort.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sort.js","sourceRoot":"","sources":["../../src/tools/sort.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"sort.js","sourceRoot":"","sources":["../../src/tools/sort.ts"],"names":[],"mappings":"AAkBA,SAAS,WAAW,CAAC,KAAc;IAClC,OAAO,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,CAAC;AACpD,CAAC;AAED,SAAS,QAAQ,CAAC,IAAa,EAAE,IAA0B;IAC1D,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,EAAE,CAAC;QACxB,OAAO;IACR,CAAC;IAED,MAAM,CAAE,IAAI,EAAE,GAAG,IAAI,CAAE,GAAG,IAAI,CAAC;IAE/B,IAAI,CAAC,IAAI,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAC5C,CAAC;IAED,IAAI,IAAI,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QACvB,OAAO,IAAI,CAAC,IAAI,CAAC,CAAC;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pose plugin for ESLint",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eslint",
|
|
@@ -19,8 +19,10 @@
|
|
|
19
19
|
"readme.md",
|
|
20
20
|
"dist/**/*"
|
|
21
21
|
],
|
|
22
|
-
"
|
|
23
|
-
"
|
|
22
|
+
"type": "module",
|
|
23
|
+
"exports": {
|
|
24
|
+
".": "./dist/index.js"
|
|
25
|
+
},
|
|
24
26
|
"wireit": {
|
|
25
27
|
"prepublishOnly": {
|
|
26
28
|
"dependencies": [
|
|
@@ -29,21 +31,21 @@
|
|
|
29
31
|
]
|
|
30
32
|
},
|
|
31
33
|
"test": {
|
|
32
|
-
"command": "
|
|
34
|
+
"command": "node --test-reporter spec --test 'src/**/*.test.ts'",
|
|
33
35
|
"files": [
|
|
34
36
|
"src/**/*.ts"
|
|
35
37
|
],
|
|
36
38
|
"output": []
|
|
37
39
|
},
|
|
38
40
|
"build": {
|
|
39
|
-
"command": "tsc --build tsconfig.
|
|
41
|
+
"command": "tsc --build tsconfig.json",
|
|
40
42
|
"clean": "if-file-deleted",
|
|
41
43
|
"files": [
|
|
42
44
|
"src/**/*.ts",
|
|
43
45
|
"!src/**/*.test.ts",
|
|
44
46
|
"!src/tools/test.ts",
|
|
45
47
|
"../../tsconfig.base.json",
|
|
46
|
-
"tsconfig.
|
|
48
|
+
"tsconfig.json"
|
|
47
49
|
],
|
|
48
50
|
"output": [
|
|
49
51
|
"dist/**",
|
|
@@ -56,22 +58,23 @@
|
|
|
56
58
|
},
|
|
57
59
|
"dependencies": {
|
|
58
60
|
"@shigen/enum": "~0.5.0",
|
|
59
|
-
"minimatch": "^10.0.
|
|
61
|
+
"minimatch": "^10.0.3"
|
|
60
62
|
},
|
|
61
63
|
"devDependencies": {
|
|
62
64
|
"@types/eslint": "9.6.1",
|
|
63
|
-
"@types/estree": "1.0.
|
|
64
|
-
"typescript-eslint": "8.
|
|
65
|
+
"@types/estree": "1.0.8",
|
|
66
|
+
"@typescript-eslint/types": "8.42.0",
|
|
67
|
+
"typescript-eslint": "8.42.0",
|
|
65
68
|
"ajv": "8.17.1",
|
|
66
|
-
"eslint": "9.
|
|
67
|
-
"dedent": "1.
|
|
69
|
+
"eslint": "9.35.0",
|
|
70
|
+
"dedent": "1.7.0"
|
|
68
71
|
},
|
|
69
72
|
"peerDependencies": {
|
|
70
|
-
"
|
|
73
|
+
"typescript-eslint": "^8.0.0",
|
|
71
74
|
"eslint": "^9.0.0"
|
|
72
75
|
},
|
|
73
76
|
"peerDependenciesMeta": {
|
|
74
|
-
"
|
|
77
|
+
"typescript-eslint": {
|
|
75
78
|
"optional": true
|
|
76
79
|
}
|
|
77
80
|
},
|