@shigen/eslint-plugin 0.3.1 → 0.5.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.js +0 -2
- package/dist/index.js.map +1 -1
- package/dist/rules/group-imports.js +97 -39
- package/dist/rules/group-imports.js.map +1 -1
- package/dist/rules/sort-imports.js +32 -26
- package/dist/rules/sort-imports.js.map +1 -1
- package/dist/tools/ast.js +18 -4
- package/dist/tools/ast.js.map +1 -1
- package/package.json +79 -80
- package/readme.md +0 -34
- package/dist/rules/experimental/no-commented-code.js +0 -142
- package/dist/rules/experimental/no-commented-code.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.rules = void 0;
|
|
4
|
-
const no_commented_code_1 = require("./rules/experimental/no-commented-code");
|
|
5
4
|
const group_imports_1 = require("./rules/group-imports");
|
|
6
5
|
const sort_imports_1 = require("./rules/sort-imports");
|
|
7
6
|
exports.rules = {
|
|
8
7
|
'group-imports': group_imports_1.rule,
|
|
9
8
|
'sort-imports': sort_imports_1.rule,
|
|
10
|
-
'experimental/no-commented-code': no_commented_code_1.rule,
|
|
11
9
|
};
|
|
12
10
|
//# 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":";;;AAGA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;AAGA,yDAA6D;AAC7D,uDAA2D;AAY9C,QAAA,KAAK,GAAoC;IACrD,eAAe,EAAE,oBAAY;IAC7B,cAAc,EAAE,mBAAW;CAC3B,CAAC"}
|
|
@@ -1,30 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.rule = exports.
|
|
4
|
-
const
|
|
5
|
-
const node_module_1 = tslib_1.__importDefault(require("node:module"));
|
|
3
|
+
exports.rule = exports.TypeImport = exports.ModuleClass = void 0;
|
|
4
|
+
const node_module_1 = require("node:module");
|
|
6
5
|
const node_path_1 = require("node:path");
|
|
6
|
+
const enum_1 = require("@shigen/enum");
|
|
7
7
|
const ast_1 = require("../tools/ast");
|
|
8
8
|
const rule_1 = require("../tools/rule");
|
|
9
9
|
const sort_1 = require("../tools/sort");
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
10
|
+
const moduleClassId = Symbol();
|
|
11
|
+
const typeImportId = Symbol();
|
|
12
|
+
class ModuleClass extends (0, enum_1.Enum)(moduleClassId) {
|
|
13
|
+
static Node = new ModuleClass(moduleClassId, { key: 'node' });
|
|
14
|
+
static External = new ModuleClass(moduleClassId, { key: 'external' });
|
|
15
|
+
static Absolute = new ModuleClass(moduleClassId, { key: 'absolute' });
|
|
16
|
+
static Relative = new ModuleClass(moduleClassId, { key: 'relative' });
|
|
17
|
+
}
|
|
18
|
+
exports.ModuleClass = ModuleClass;
|
|
19
|
+
class TypeImport extends (0, enum_1.Enum)(typeImportId) {
|
|
20
|
+
static Include = new TypeImport(typeImportId, { key: 'include' });
|
|
21
|
+
static Exclude = new TypeImport(typeImportId, { key: 'exclude' });
|
|
22
|
+
static Only = new TypeImport(typeImportId, { key: 'only' });
|
|
23
|
+
}
|
|
24
|
+
exports.TypeImport = TypeImport;
|
|
23
25
|
const defaultConfiguration = [
|
|
24
|
-
{ class: ModuleClass.Node },
|
|
25
|
-
{ class: ModuleClass.External },
|
|
26
|
-
{ class: ModuleClass.Absolute },
|
|
27
|
-
{ class: ModuleClass.Relative },
|
|
26
|
+
{ class: ModuleClass.Node.key },
|
|
27
|
+
{ class: ModuleClass.External.key },
|
|
28
|
+
{ class: ModuleClass.Absolute.key },
|
|
29
|
+
{ class: ModuleClass.Relative.key },
|
|
28
30
|
];
|
|
29
31
|
function groupIndex(node, groups) {
|
|
30
32
|
if (typeof node.source.value !== 'string') {
|
|
@@ -46,9 +48,9 @@ function groupIndex(node, groups) {
|
|
|
46
48
|
return false;
|
|
47
49
|
}
|
|
48
50
|
if (isTypeImport) {
|
|
49
|
-
return importPath.startsWith(group.path) && group.types !==
|
|
51
|
+
return importPath.startsWith(group.path) && group.types !== TypeImport.Exclude.key;
|
|
50
52
|
}
|
|
51
|
-
return importPath.startsWith(group.path) && group.types !==
|
|
53
|
+
return importPath.startsWith(group.path) && group.types !== TypeImport.Only.key;
|
|
52
54
|
});
|
|
53
55
|
if (hardCodedIndex >= 0) {
|
|
54
56
|
return hardCodedIndex;
|
|
@@ -59,7 +61,7 @@ function groupIndex(node, groups) {
|
|
|
59
61
|
throw new Error(`group-imports: unexpected undefined module name for path '${importPath}'`);
|
|
60
62
|
}
|
|
61
63
|
let moduleClass = ModuleClass.External;
|
|
62
|
-
if (node_module_1.
|
|
64
|
+
if ((0, node_module_1.isBuiltin)(moduleName)) {
|
|
63
65
|
moduleClass = ModuleClass.Node;
|
|
64
66
|
}
|
|
65
67
|
else if (/^(?:\/|\.)/u.exec(moduleName)) {
|
|
@@ -70,9 +72,9 @@ function groupIndex(node, groups) {
|
|
|
70
72
|
return false;
|
|
71
73
|
}
|
|
72
74
|
if (isTypeImport) {
|
|
73
|
-
return group.class === moduleClass && group.types !==
|
|
75
|
+
return group.class === moduleClass.key && group.types !== TypeImport.Exclude.key;
|
|
74
76
|
}
|
|
75
|
-
return group.class === moduleClass && group.types !==
|
|
77
|
+
return group.class === moduleClass.key && group.types !== TypeImport.Only.key;
|
|
76
78
|
});
|
|
77
79
|
return classIndex >= 0 ? classIndex : groups.length;
|
|
78
80
|
}
|
|
@@ -80,19 +82,75 @@ function checkLines(context, previous, next, lineCount) {
|
|
|
80
82
|
if (!previous || !next) {
|
|
81
83
|
throw new Error(`group-imports: unexpected undefined node`);
|
|
82
84
|
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
+
const tokensBetween = context.sourceCode.getTokensBetween(previous, next, { includeComments: true });
|
|
86
|
+
const relevantItems = [previous];
|
|
87
|
+
for (const token of tokensBetween) {
|
|
88
|
+
if (!(0, ast_1.isComment)(token)) {
|
|
89
|
+
return context.report({
|
|
90
|
+
loc: {
|
|
91
|
+
start: (0, ast_1.assertLoc)(tokensBetween.find((t) => !(0, ast_1.isComment)(t))).start,
|
|
92
|
+
end: (0, ast_1.assertLoc)(tokensBetween.findLast((t) => !(0, ast_1.isComment)(t))).end,
|
|
93
|
+
},
|
|
94
|
+
message: `Unexpected code between imports of group`,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
relevantItems.push(token);
|
|
85
98
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
99
|
+
relevantItems.push(next);
|
|
100
|
+
for (let i = 0; i < relevantItems.length - 1; i++) {
|
|
101
|
+
const a = relevantItems[i];
|
|
102
|
+
const b = relevantItems[i + 1];
|
|
103
|
+
const locA = (0, ast_1.assertLoc)(a);
|
|
104
|
+
const locB = (0, ast_1.assertLoc)(b);
|
|
105
|
+
const rangeA = (0, ast_1.assertRange)(a);
|
|
106
|
+
const rangeB = (0, ast_1.assertRange)(b);
|
|
107
|
+
const linesBetween = locB.start.line - locA.end.line - 1;
|
|
108
|
+
if (lineCount === 0) {
|
|
109
|
+
if (linesBetween > 0) {
|
|
110
|
+
const range = [rangeA[1], rangeB[0] - locB.start.column];
|
|
111
|
+
context.report({
|
|
112
|
+
loc: {
|
|
113
|
+
start: locA.end,
|
|
114
|
+
end: {
|
|
115
|
+
line: locB.start.line,
|
|
116
|
+
column: 0,
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
message: `Unexpected white space between imports`,
|
|
120
|
+
fix: (fixer) => fixer.replaceTextRange(range, '\n'),
|
|
121
|
+
});
|
|
92
122
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
123
|
+
}
|
|
124
|
+
else {
|
|
125
|
+
const columnOffset = (0, ast_1.isComment)(b) ? 0 : locB.start.column;
|
|
126
|
+
const reportLoc = {
|
|
127
|
+
start: locA.end,
|
|
128
|
+
end: {
|
|
129
|
+
line: locB.start.line,
|
|
130
|
+
column: columnOffset,
|
|
131
|
+
},
|
|
132
|
+
};
|
|
133
|
+
const fix = (fixer) => fixer.replaceTextRange([rangeA[1], rangeB[0] - columnOffset], '\n\n');
|
|
134
|
+
if ((0, ast_1.isComment)(a) || (0, ast_1.isComment)(b)) {
|
|
135
|
+
if (linesBetween > 1) {
|
|
136
|
+
context.report({
|
|
137
|
+
loc: reportLoc,
|
|
138
|
+
message: `TODO 1`,
|
|
139
|
+
fix,
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
else {
|
|
144
|
+
if (linesBetween !== 1) {
|
|
145
|
+
context.report({
|
|
146
|
+
loc: reportLoc,
|
|
147
|
+
message: `TODO 2`,
|
|
148
|
+
fix,
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
96
154
|
}
|
|
97
155
|
function groupLabels(groups) {
|
|
98
156
|
return groups.map((group) => {
|
|
@@ -108,7 +166,7 @@ exports.rule = {
|
|
|
108
166
|
schema: {
|
|
109
167
|
definitions: {
|
|
110
168
|
typeImportConfiguration: {
|
|
111
|
-
enum: [
|
|
169
|
+
enum: [...TypeImport.keys()],
|
|
112
170
|
},
|
|
113
171
|
moduleConfiguration: {
|
|
114
172
|
oneOf: [
|
|
@@ -117,7 +175,7 @@ exports.rule = {
|
|
|
117
175
|
type: 'object',
|
|
118
176
|
properties: {
|
|
119
177
|
class: {
|
|
120
|
-
enum: [
|
|
178
|
+
enum: [...ModuleClass.keys()],
|
|
121
179
|
},
|
|
122
180
|
types: {
|
|
123
181
|
$ref: '#/definitions/typeImportConfiguration',
|
|
@@ -160,7 +218,7 @@ exports.rule = {
|
|
|
160
218
|
},
|
|
161
219
|
create(context) {
|
|
162
220
|
const groupConfigurations = context.options.length ? context.options : defaultConfiguration;
|
|
163
|
-
const source = context.
|
|
221
|
+
const source = context.sourceCode;
|
|
164
222
|
const imports = (0, ast_1.importModules)(source).map((node) => {
|
|
165
223
|
return {
|
|
166
224
|
index: groupIndex(node, groupConfigurations),
|
|
@@ -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,6CAAwC;AACxC,yCAAuC;AAIvC,uCAAoC;AAIpC,sCAA+G;AAC/G,wCAAyC;AACzC,wCAA2C;AAK3C,MAAM,aAAa,GAAG,MAAM,EAAE,CAAC;AAC/B,MAAM,YAAY,GAAG,MAAM,EAAE,CAAC;AAE9B,MAAa,WAAY,SAAQ,IAAA,WAAI,EAA6B,aAAa,CAAC;IAC/E,MAAM,CAAU,IAAI,GAAG,IAAI,WAAW,CAAC,aAAa,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,CAAC,CAAC;IACvE,MAAM,CAAU,QAAQ,GAAG,IAAI,WAAW,CAAC,aAAa,EAAE,EAAE,GAAG,EAAE,UAAU,EAAE,CAAC,CAAC;IAC/E,MAAM,CAAU,QAAQ,GAAG,IAAI,WAAW,CAAC,aAAa,EAAE,EAAE,GAAG,EAAE,UAAU,EAAE,CAAC,CAAC;IAC/E,MAAM,CAAU,QAAQ,GAAG,IAAI,WAAW,CAAC,aAAa,EAAE,EAAE,GAAG,EAAE,UAAU,EAAE,CAAC,CAAC;;AAJhF,kCAKC;AAED,MAAa,UAAW,SAAQ,IAAA,WAAI,EAA4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
|
@@ -1,31 +1,34 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.rule = exports.TypeImportInlinePosition = exports.TypeImportGroupPosition = void 0;
|
|
4
|
+
const enum_1 = require("@shigen/enum");
|
|
4
5
|
const ast_1 = require("../tools/ast");
|
|
5
6
|
const rule_1 = require("../tools/rule");
|
|
6
7
|
const sort_1 = require("../tools/sort");
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
8
|
+
const typeImportGroupPositionId = Symbol();
|
|
9
|
+
const typeImportInlinePositionId = Symbol();
|
|
10
|
+
class TypeImportGroupPosition extends (0, enum_1.Enum)(typeImportGroupPositionId) {
|
|
11
|
+
static Ignore = new TypeImportGroupPosition(typeImportGroupPositionId, { key: 'ignore' });
|
|
12
|
+
static Top = new TypeImportGroupPosition(typeImportGroupPositionId, { key: 'top' });
|
|
13
|
+
static Bottom = new TypeImportGroupPosition(typeImportGroupPositionId, { key: 'bottom' });
|
|
14
|
+
static AboveValue = new TypeImportGroupPosition(typeImportGroupPositionId, { key: 'above-value' });
|
|
15
|
+
static BelowValue = new TypeImportGroupPosition(typeImportGroupPositionId, { key: 'below-value' });
|
|
16
|
+
}
|
|
17
|
+
exports.TypeImportGroupPosition = TypeImportGroupPosition;
|
|
18
|
+
class TypeImportInlinePosition extends (0, enum_1.Enum)(typeImportInlinePositionId) {
|
|
19
|
+
static Ignore = new TypeImportInlinePosition(typeImportInlinePositionId, { key: 'ignore' });
|
|
20
|
+
static Start = new TypeImportInlinePosition(typeImportInlinePositionId, { key: 'start' });
|
|
21
|
+
static End = new TypeImportInlinePosition(typeImportInlinePositionId, { key: 'end' });
|
|
22
|
+
}
|
|
23
|
+
exports.TypeImportInlinePosition = TypeImportInlinePosition;
|
|
21
24
|
const defaultConfiguration = {
|
|
22
25
|
specifier: 'source',
|
|
23
26
|
locales: ['en-US'],
|
|
24
27
|
numeric: true,
|
|
25
28
|
caseFirst: 'lower',
|
|
26
29
|
sortExports: true,
|
|
27
|
-
typesInGroup: TypeImportGroupPosition.Ignore,
|
|
28
|
-
inlineTypes: TypeImportInlinePosition.Ignore,
|
|
30
|
+
typesInGroup: TypeImportGroupPosition.Ignore.key,
|
|
31
|
+
inlineTypes: TypeImportInlinePosition.Ignore.key,
|
|
29
32
|
};
|
|
30
33
|
exports.rule = {
|
|
31
34
|
meta: {
|
|
@@ -62,7 +65,10 @@ exports.rule = {
|
|
|
62
65
|
type: 'boolean',
|
|
63
66
|
},
|
|
64
67
|
typesInGroup: {
|
|
65
|
-
enum: [
|
|
68
|
+
enum: [...TypeImportGroupPosition.keys()],
|
|
69
|
+
},
|
|
70
|
+
inlineTypes: {
|
|
71
|
+
enum: [...TypeImportInlinePosition.keys()],
|
|
66
72
|
},
|
|
67
73
|
},
|
|
68
74
|
},
|
|
@@ -70,7 +76,7 @@ exports.rule = {
|
|
|
70
76
|
},
|
|
71
77
|
create(context) {
|
|
72
78
|
const configuration = { ...defaultConfiguration, ...context.options[0] };
|
|
73
|
-
const source = context.
|
|
79
|
+
const source = context.sourceCode;
|
|
74
80
|
const partition = (result, node, index, from) => {
|
|
75
81
|
if (index > 0 && (0, ast_1.linesBetween)(from[index - 1], node) > 0) {
|
|
76
82
|
result.push([]);
|
|
@@ -80,7 +86,7 @@ exports.rule = {
|
|
|
80
86
|
};
|
|
81
87
|
const sortModules = (group) => {
|
|
82
88
|
const sorted = (0, sort_1.sortByPath)(group, ['source', 'value'], configuration);
|
|
83
|
-
if (configuration.typesInGroup !== TypeImportGroupPosition.Ignore) {
|
|
89
|
+
if (configuration.typesInGroup !== TypeImportGroupPosition.Ignore.key) {
|
|
84
90
|
sorted.sort((a, b) => {
|
|
85
91
|
const aIsType = (0, ast_1.isTypeImportOrExport)(a);
|
|
86
92
|
const bIsType = (0, ast_1.isTypeImportOrExport)(b);
|
|
@@ -89,17 +95,17 @@ exports.rule = {
|
|
|
89
95
|
}
|
|
90
96
|
// eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
|
|
91
97
|
switch (configuration.typesInGroup) {
|
|
92
|
-
case TypeImportGroupPosition.Top:
|
|
98
|
+
case TypeImportGroupPosition.Top.key:
|
|
93
99
|
return aIsType ? -1 : 1;
|
|
94
|
-
case TypeImportGroupPosition.Bottom:
|
|
100
|
+
case TypeImportGroupPosition.Bottom.key:
|
|
95
101
|
return aIsType ? 1 : -1;
|
|
96
102
|
}
|
|
97
103
|
if (a.source.value === b.source.value) {
|
|
98
104
|
// eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
|
|
99
105
|
switch (configuration.typesInGroup) {
|
|
100
|
-
case TypeImportGroupPosition.AboveValue:
|
|
106
|
+
case TypeImportGroupPosition.AboveValue.key:
|
|
101
107
|
return aIsType ? -1 : 1;
|
|
102
|
-
case TypeImportGroupPosition.BelowValue:
|
|
108
|
+
case TypeImportGroupPosition.BelowValue.key:
|
|
103
109
|
return aIsType ? 1 : -1;
|
|
104
110
|
}
|
|
105
111
|
}
|
|
@@ -126,7 +132,7 @@ exports.rule = {
|
|
|
126
132
|
const from = configuration.specifier === 'source' ? 'local' : 'exported';
|
|
127
133
|
return (0, sort_1.sortByPath)(specifiers, [from, 'name'], configuration);
|
|
128
134
|
})();
|
|
129
|
-
if (configuration.inlineTypes !== TypeImportInlinePosition.Ignore) {
|
|
135
|
+
if (configuration.inlineTypes !== TypeImportInlinePosition.Ignore.key) {
|
|
130
136
|
sorted.sort((a, b) => {
|
|
131
137
|
const aIsType = (0, ast_1.isTypeImportOrExport)(a);
|
|
132
138
|
const bIsType = (0, ast_1.isTypeImportOrExport)(b);
|
|
@@ -135,9 +141,9 @@ exports.rule = {
|
|
|
135
141
|
}
|
|
136
142
|
// eslint-disable-next-line @typescript-eslint/switch-exhaustiveness-check
|
|
137
143
|
switch (configuration.inlineTypes) {
|
|
138
|
-
case TypeImportInlinePosition.Start:
|
|
144
|
+
case TypeImportInlinePosition.Start.key:
|
|
139
145
|
return aIsType ? -1 : 1;
|
|
140
|
-
case TypeImportInlinePosition.End:
|
|
146
|
+
case TypeImportInlinePosition.End.key:
|
|
141
147
|
return aIsType ? 1 : -1;
|
|
142
148
|
}
|
|
143
149
|
return 0;
|
|
@@ -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,uCAAoC;AAWpC,sCAAyG;AACzG,wCAAyC;AACzC,wCAA2C;AAK3C,MAAM,yBAAyB,GAAG,MAAM,EAAE,CAAC;AAC3C,MAAM,0BAA0B,GAAG,MAAM,EAAE,CAAC;AAE5C,MAAa,uBAAwB,SAAQ,IAAA,WAAI,EAA+B,yBAAyB,CAAC;IACzG,MAAM,CAAU,MAAM,GAAG,IAAI,uBAAuB,CAAC,yBAAyB,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC,CAAC;IACnG,MAAM,CAAU,GAAG,GAAG,IAAI,uBAAuB,CAAC,yBAAyB,EAAE,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,CAAC;IAC7F,MAAM,CAAU,MAAM,GAAG,IAAI,uBAAuB,CAAC,yBAAyB,EAAE,EAAE,GAAG,EAAE,QAAQ,EAAE,CAAC,CAAC;IACnG,MAAM,CAAU,UAAU,GAAG,IAAI,uBAAuB,CAAC,yBAAyB,EAAE,EAAE,GAAG,EAAE,aAAa,EAAE,CAAC,CAAC;IAC5G,MAAM,CAAU,UAAU,GAAG,IAAI,uBAAuB,CAAC,yBAAyB,EAAE,EAAE,GAAG,EAAE,aAAa,EAAE,CAAC,CAAC;;AAL7G,0DAMC;AAED,MAAa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AyB,aAAa,CAAC,SAAS,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,UAAU,CAAC;gBAC/F,MAAM,MAAM,GAAG,IAAA,iBAAU,EAAC,UAAU,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,aAAa,CAAC,CAAC;gBAErE,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE,CAAC,IAAI,KAAK,UAAU,CAAC,CAAC,CAAC,CAAC,EAAE;oBACrD,IAAA,eAAQ,EAAC,OAAO,EAAE;wBACjB,KAAK,EAAE,IAAA,aAAO,EAAC,UAAU,CAAC;wBAC1B,OAAO,EAAE,kCAAkC;wBAC3C,IAAI,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC;qBAC3D,CAAC,CAAC;iBACH;YACF,CAAC,CAAC;YAEF,IAAA,mBAAa,EAAC,MAAM,CAAC;iBACnB,MAAM,CAA8B,SAAS,EAAE,CAAC,EAAE,CAAC,CAAC;iBACpD,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;gBAClB,WAAW,CAAC,KAAK,CAAC,CAAC;gBACnB,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,oBAAoB,CAAC,IAAI,CAAC,UAAU,IAAI,EAAE,CAAC,CAAC,CAAC;YACtE,CAAC,CAAC,CAAC;SACJ;QAED,OAAO,EAAE,CAAC;IACX,CAAC;CACD,CAAC"}
|
package/dist/tools/ast.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.assertRange = exports.assertLoc = exports.isComment = exports.linesBetween = exports.extrema = exports.isTypeImportOrExport = exports.exportModules = exports.importModules = void 0;
|
|
4
4
|
function importModules(source) {
|
|
5
5
|
return source.ast.body.filter((node) => node.type === 'ImportDeclaration');
|
|
6
6
|
}
|
|
@@ -29,8 +29,22 @@ function linesBetween(a, b) {
|
|
|
29
29
|
return b.loc.start.line - a.loc.end.line - 1;
|
|
30
30
|
}
|
|
31
31
|
exports.linesBetween = linesBetween;
|
|
32
|
-
function
|
|
33
|
-
return
|
|
32
|
+
function isComment(value) {
|
|
33
|
+
return value.type === 'Block' || value.type === 'Line';
|
|
34
34
|
}
|
|
35
|
-
exports.
|
|
35
|
+
exports.isComment = isComment;
|
|
36
|
+
function assertLoc(value) {
|
|
37
|
+
if (value?.loc) {
|
|
38
|
+
return value.loc;
|
|
39
|
+
}
|
|
40
|
+
throw new Error(`error: AST was generated without node location information`);
|
|
41
|
+
}
|
|
42
|
+
exports.assertLoc = assertLoc;
|
|
43
|
+
function assertRange(value) {
|
|
44
|
+
if (value?.range) {
|
|
45
|
+
return value.range;
|
|
46
|
+
}
|
|
47
|
+
throw new Error();
|
|
48
|
+
}
|
|
49
|
+
exports.assertRange = assertRange;
|
|
36
50
|
//# 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":";;;AAeA,SAAgB,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;AAFD,sCAEC;AAED,SAAgB,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,sBAA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
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
}
|
|
2
|
+
"name": "@shigen/eslint-plugin",
|
|
3
|
+
"version": "0.5.0",
|
|
4
|
+
"description": "General purpose plugin for ESLint",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"eslint",
|
|
7
|
+
"lint",
|
|
8
|
+
"js",
|
|
9
|
+
"javascript",
|
|
10
|
+
"ts",
|
|
11
|
+
"typescript",
|
|
12
|
+
"es6"
|
|
13
|
+
],
|
|
14
|
+
"license": "ISC",
|
|
15
|
+
"author": "Tao Cumplido",
|
|
16
|
+
"repository": "https://github.com/tao-cumplido/shigen/tree/main/packages/eslint-plugin",
|
|
17
|
+
"bugs": "https://github.com/tao-cumplido/shigen/issues",
|
|
18
|
+
"files": [
|
|
19
|
+
"readme.md",
|
|
20
|
+
"dist/**/*"
|
|
21
|
+
],
|
|
22
|
+
"main": "dist/index.js",
|
|
23
|
+
"wireit": {
|
|
24
|
+
"prepublishOnly": {
|
|
25
|
+
"dependencies": [
|
|
26
|
+
"test",
|
|
27
|
+
"build"
|
|
28
|
+
]
|
|
29
|
+
},
|
|
30
|
+
"test": {
|
|
31
|
+
"command": "tsx --tsconfig tsconfig.test.json --test-reporter spec --test 'src/**/*.test.ts'",
|
|
32
|
+
"files": [
|
|
33
|
+
"src/**/*.ts"
|
|
34
|
+
],
|
|
35
|
+
"output": []
|
|
36
|
+
},
|
|
37
|
+
"build": {
|
|
38
|
+
"command": "tsc --build tsconfig.build.json",
|
|
39
|
+
"clean": "if-file-deleted",
|
|
40
|
+
"files": [
|
|
41
|
+
"src/**/*.ts",
|
|
42
|
+
"!src/**/*.test.ts",
|
|
43
|
+
"!src/tools/test.ts",
|
|
44
|
+
"../../tsconfig.base.json",
|
|
45
|
+
"tsconfig.build.json"
|
|
46
|
+
],
|
|
47
|
+
"output": [
|
|
48
|
+
"dist/**",
|
|
49
|
+
"*.tsbuildinfo"
|
|
50
|
+
]
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
"engines": {
|
|
54
|
+
"node": "^18.18.0 || >=20.9.0"
|
|
55
|
+
},
|
|
56
|
+
"dependencies": {
|
|
57
|
+
"@shigen/enum": "0.5.0"
|
|
58
|
+
},
|
|
59
|
+
"devDependencies": {
|
|
60
|
+
"@types/eslint": "9.6.1",
|
|
61
|
+
"@types/estree": "1.0.5",
|
|
62
|
+
"typescript-eslint": "8.3.0",
|
|
63
|
+
"ajv": "8.17.1",
|
|
64
|
+
"eslint": "9.9.1",
|
|
65
|
+
"dedent": "1.5.3"
|
|
66
|
+
},
|
|
67
|
+
"peerDependencies": {
|
|
68
|
+
"@typescript-eslint/parser": "^8.0.0",
|
|
69
|
+
"eslint": "^9.0.0"
|
|
70
|
+
},
|
|
71
|
+
"peerDependenciesMeta": {
|
|
72
|
+
"@typescript-eslint/parser": {
|
|
73
|
+
"optional": true
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
"scripts": {
|
|
77
|
+
"test": "wireit",
|
|
78
|
+
"build": "wireit"
|
|
79
|
+
}
|
|
80
|
+
}
|
package/readme.md
CHANGED
|
@@ -135,37 +135,3 @@ The default configuration is:
|
|
|
135
135
|
"inlineTypes": "ignore"
|
|
136
136
|
}
|
|
137
137
|
```
|
|
138
|
-
|
|
139
|
-
## Experimental rules
|
|
140
|
-
|
|
141
|
-
:warning: These rules are experimental and may produce unexpected behavior. :warning:
|
|
142
|
-
|
|
143
|
-
- These rules are not auto-fixable!
|
|
144
|
-
- Consider setting the level to `"warn"` instead of `"error"`.
|
|
145
|
-
|
|
146
|
-
### `@shigen/experimental/no-commented-code`
|
|
147
|
-
|
|
148
|
-
This rule is meant to detect commented code. It does so by uncommenting comment nodes and run the whole file with the uncommented part through the parser. If the parser produces a valid AST the comment is marked as commented code. Generally it should work with any parser but has only been tested with the default parser `espree` and `@typescript-eslint/parser`. For example, `// type A = 0;` is not commented code with `espree` but it is with `@typescript-eslint/parser`.
|
|
149
|
-
|
|
150
|
-
False positives will probably happen, single words for example, are valid identifiers in many positions and `eslint-disable-next-line` is parsed as a `BinaryExpression`. Common patterns can be ignored and `^eslint-` is ignored by default. Additionally, doc comments are ignored as well, this cannot be turned off.
|
|
151
|
-
|
|
152
|
-
The following configuration options can be set:
|
|
153
|
-
|
|
154
|
-
```ts
|
|
155
|
-
interface Configuration {
|
|
156
|
-
ignorePatterns?: string[];
|
|
157
|
-
extendDefaultIgnorePatterns?: boolean;
|
|
158
|
-
}
|
|
159
|
-
```
|
|
160
|
-
|
|
161
|
-
- `ignorePatterns`: When a comment matches one of the specified patterns it will be ignored. The expressions are tested against the trimmed text content of the comment. Invalid regular expressions will be ignored.
|
|
162
|
-
- `extendDefaultIgnorePatterns`: Whether to keep the default ignore patterns without explicitly redefining them.
|
|
163
|
-
|
|
164
|
-
The default configuration is:
|
|
165
|
-
|
|
166
|
-
```json
|
|
167
|
-
{
|
|
168
|
-
"ignorePatterns": ["^eslint-", "^@ts-"],
|
|
169
|
-
"extendDefaultIgnorePatterns": false
|
|
170
|
-
}
|
|
171
|
-
```
|
|
@@ -1,142 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.rule = void 0;
|
|
4
|
-
const defaultConfiguration = {
|
|
5
|
-
ignorePatterns: ['^eslint-', '^@ts-'],
|
|
6
|
-
extendDefaultIgnorePatterns: false,
|
|
7
|
-
};
|
|
8
|
-
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types
|
|
9
|
-
function mapPatternReducer(result, pattern) {
|
|
10
|
-
try {
|
|
11
|
-
result.push(new RegExp(pattern, 'u'));
|
|
12
|
-
}
|
|
13
|
-
catch { }
|
|
14
|
-
return result;
|
|
15
|
-
}
|
|
16
|
-
function parseIgnorePatterns(config) {
|
|
17
|
-
if (!config?.ignorePatterns) {
|
|
18
|
-
return;
|
|
19
|
-
}
|
|
20
|
-
const ignorePatterns = new Set(config.ignorePatterns);
|
|
21
|
-
if (config.extendDefaultIgnorePatterns) {
|
|
22
|
-
defaultConfiguration.ignorePatterns.forEach((pattern) => ignorePatterns.add(pattern));
|
|
23
|
-
}
|
|
24
|
-
return [...ignorePatterns].reduce(mapPatternReducer, []);
|
|
25
|
-
}
|
|
26
|
-
exports.rule = {
|
|
27
|
-
meta: {
|
|
28
|
-
schema: [
|
|
29
|
-
{
|
|
30
|
-
type: 'object',
|
|
31
|
-
properties: {
|
|
32
|
-
ignorePatterns: {
|
|
33
|
-
type: 'array',
|
|
34
|
-
items: {
|
|
35
|
-
type: 'string',
|
|
36
|
-
},
|
|
37
|
-
},
|
|
38
|
-
extendDefaultIgnorePatterns: {
|
|
39
|
-
type: 'boolean',
|
|
40
|
-
},
|
|
41
|
-
},
|
|
42
|
-
},
|
|
43
|
-
],
|
|
44
|
-
},
|
|
45
|
-
create(context) {
|
|
46
|
-
function isNonSyntaxError(error) {
|
|
47
|
-
if (error instanceof SyntaxError) {
|
|
48
|
-
return false;
|
|
49
|
-
}
|
|
50
|
-
return (context.parserPath.includes('@typescript-eslint') &&
|
|
51
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-var-requires
|
|
52
|
-
!(error instanceof require('@typescript-eslint/typescript-estree').TSError));
|
|
53
|
-
}
|
|
54
|
-
// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires
|
|
55
|
-
const parser = require(context.parserPath);
|
|
56
|
-
const source = context.getSourceCode();
|
|
57
|
-
const ignorePatterns = parseIgnorePatterns(context.options[0]) ?? defaultConfiguration.ignorePatterns.reduce(mapPatternReducer, []);
|
|
58
|
-
// generate power set of all comments to process and sort sets by size descending
|
|
59
|
-
const commentSets = source
|
|
60
|
-
.getAllComments()
|
|
61
|
-
.filter((comment) => {
|
|
62
|
-
if (!comment.loc) {
|
|
63
|
-
return false;
|
|
64
|
-
}
|
|
65
|
-
if (comment.type === 'Block' && comment.value.startsWith('*')) {
|
|
66
|
-
// ignore doc comments
|
|
67
|
-
return false;
|
|
68
|
-
}
|
|
69
|
-
return ignorePatterns.every((pattern) => !pattern.test(comment.value.trim()));
|
|
70
|
-
})
|
|
71
|
-
.reduce((sets, comment) => [...sets, ...sets.map((set) => [...set, comment])], [[]])
|
|
72
|
-
.sort((a, b) => b.length - a.length);
|
|
73
|
-
const reportedComments = new Set();
|
|
74
|
-
for (const set of commentSets) {
|
|
75
|
-
if (set.some((comment) => reportedComments.has(comment))) {
|
|
76
|
-
continue;
|
|
77
|
-
}
|
|
78
|
-
// we modify the lines in place so make a copy for each test
|
|
79
|
-
const lines = [...source.getLines()];
|
|
80
|
-
// uncomment locations in source
|
|
81
|
-
for (const comment of set) {
|
|
82
|
-
const startIndex = comment.loc.start.line - 1;
|
|
83
|
-
const start = [...(lines[startIndex] ?? '')];
|
|
84
|
-
// replace comment delimiters with spaces to not move locations for multiple comments on same line
|
|
85
|
-
start.splice(comment.loc.start.column, 2, ' ', ' ');
|
|
86
|
-
if (comment.type === 'Block') {
|
|
87
|
-
const endIndex = comment.loc.end.line - 1;
|
|
88
|
-
if (startIndex === endIndex) {
|
|
89
|
-
start.splice(comment.loc.end.column - 2, 2, ' ', ' ');
|
|
90
|
-
}
|
|
91
|
-
else {
|
|
92
|
-
const end = [...(lines[endIndex] ?? '')];
|
|
93
|
-
end.splice(comment.loc.end.column - 2, 2, ' ', ' ');
|
|
94
|
-
lines[endIndex] = end.join('');
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
lines[startIndex] = start.join('');
|
|
98
|
-
}
|
|
99
|
-
try {
|
|
100
|
-
const parse = parser.parse ?? parser.parseForESLint;
|
|
101
|
-
if (!parse) {
|
|
102
|
-
throw new Error(`unexpected error: no 'parse' method found`);
|
|
103
|
-
}
|
|
104
|
-
parse(lines.join('\n'), {
|
|
105
|
-
...context.parserOptions,
|
|
106
|
-
// provide same parser defaults as eslint (https://github.com/eslint/eslint/blob/82669fa66670a00988db5b1d10fe8f3bf30be84e/lib/linter/linter.js#L636-L645)
|
|
107
|
-
// the typescript parser would potentially error without the 'filePath' or 'range' options (https://github.com/typescript-eslint/typescript-eslint/issues/2742)
|
|
108
|
-
loc: true,
|
|
109
|
-
range: true,
|
|
110
|
-
raw: true,
|
|
111
|
-
tokens: true,
|
|
112
|
-
comment: true,
|
|
113
|
-
eslintVisitorKeys: true,
|
|
114
|
-
eslintScopeManager: true,
|
|
115
|
-
filePath: context.getFilename(),
|
|
116
|
-
// don't parse a typescript source in a project context
|
|
117
|
-
// it'd be much slower and is not necessary for simple syntax validation
|
|
118
|
-
project: undefined,
|
|
119
|
-
projects: undefined,
|
|
120
|
-
});
|
|
121
|
-
for (const comment of set) {
|
|
122
|
-
reportedComments.add(comment);
|
|
123
|
-
context.report({
|
|
124
|
-
loc: comment.loc,
|
|
125
|
-
message: 'comment contains code',
|
|
126
|
-
});
|
|
127
|
-
}
|
|
128
|
-
}
|
|
129
|
-
catch (error) {
|
|
130
|
-
if (isNonSyntaxError(error)) {
|
|
131
|
-
const position = { line: 1, column: 0 };
|
|
132
|
-
context.report({
|
|
133
|
-
loc: { start: position, end: position },
|
|
134
|
-
message: error.message,
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
return {};
|
|
140
|
-
},
|
|
141
|
-
};
|
|
142
|
-
//# sourceMappingURL=no-commented-code.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"no-commented-code.js","sourceRoot":"","sources":["../../../src/rules/experimental/no-commented-code.ts"],"names":[],"mappings":";;;AAkBA,MAAM,oBAAoB,GAAkB;IAC3C,cAAc,EAAE,CAAC,UAAU,EAAE,OAAO,CAAC;IACrC,2BAA2B,EAAE,KAAK;CAClC,CAAC;AAEF,8EAA8E;AAC9E,SAAS,iBAAiB,CAAC,MAAgB,EAAE,OAAe;IAC3D,IAAI;QACH,MAAM,CAAC,IAAI,CAAC,IAAI,MAAM,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,CAAC;KACtC;IAAC,MAAM,GAAE;IAEV,OAAO,MAAM,CAAC;AACf,CAAC;AAED,SAAS,mBAAmB,CAAC,MAA+B;IAC3D,IAAI,CAAC,MAAM,EAAE,cAAc,EAAE;QAC5B,OAAO;KACP;IAED,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC;IAEtD,IAAI,MAAM,CAAC,2BAA2B,EAAE;QACvC,oBAAoB,CAAC,cAAc,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,cAAc,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC;KACtF;IAED,OAAO,CAAC,GAAG,cAAc,CAAC,CAAC,MAAM,CAAC,iBAAiB,EAAE,EAAE,CAAC,CAAC;AAC1D,CAAC;AAEY,QAAA,IAAI,GAA0C;IAC1D,IAAI,EAAE;QACL,MAAM,EAAE;YACP;gBACC,IAAI,EAAE,QAAQ;gBACd,UAAU,EAAE;oBACX,cAAc,EAAE;wBACf,IAAI,EAAE,OAAO;wBACb,KAAK,EAAE;4BACN,IAAI,EAAE,QAAQ;yBACd;qBACD;oBACD,2BAA2B,EAAE;wBAC5B,IAAI,EAAE,SAAS;qBACf;iBACD;aACD;SACD;KACD;IACD,MAAM,CAAC,OAAO;QACb,SAAS,gBAAgB,CAAC,KAAc;YACvC,IAAI,KAAK,YAAY,WAA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