@so1ve/eslint-plugin 1.5.4 → 3.0.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.mjs → index.js} +62 -47
- package/package.json +15 -8
- package/dist/index.cjs +0 -549
- package/dist/index.d.cts +0 -18
- package/dist/index.d.mts +0 -18
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
1
|
+
// src/rules/function-style.ts
|
|
2
|
+
import { AST_NODE_TYPES } from "@typescript-eslint/types";
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
// src/utils/index.ts
|
|
5
|
+
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
6
|
+
var createEslintRule = ESLintUtils.RuleCreator((ruleName) => ruleName);
|
|
5
7
|
function getPreviousNode(node) {
|
|
6
8
|
if (!node) {
|
|
7
9
|
return;
|
|
@@ -19,9 +21,10 @@ function getPreviousNode(node) {
|
|
|
19
21
|
}
|
|
20
22
|
}
|
|
21
23
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
24
|
+
// src/rules/function-style.ts
|
|
25
|
+
var RULE_NAME = "function-style";
|
|
26
|
+
var function_style_default = createEslintRule({
|
|
27
|
+
name: RULE_NAME,
|
|
25
28
|
meta: {
|
|
26
29
|
type: "problem",
|
|
27
30
|
docs: {
|
|
@@ -166,9 +169,10 @@ const functionStyle = createEslintRule({
|
|
|
166
169
|
}
|
|
167
170
|
});
|
|
168
171
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
+
// src/rules/import-dedupe.ts
|
|
173
|
+
var RULE_NAME2 = "import-dedupe";
|
|
174
|
+
var import_dedupe_default = createEslintRule({
|
|
175
|
+
name: RULE_NAME2,
|
|
172
176
|
meta: {
|
|
173
177
|
type: "problem",
|
|
174
178
|
docs: {
|
|
@@ -215,14 +219,15 @@ const importDedupe = createEslintRule({
|
|
|
215
219
|
})
|
|
216
220
|
});
|
|
217
221
|
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
222
|
+
// src/rules/no-import-promises-as.ts
|
|
223
|
+
var RULE_NAME3 = "no-import-promises-as";
|
|
224
|
+
var _POSSIBLE_IMPORT_SOURCES = ["dns", "fs", "readline", "stream"];
|
|
225
|
+
var POSSIBLE_IMPORT_SOURCES = [
|
|
221
226
|
..._POSSIBLE_IMPORT_SOURCES,
|
|
222
227
|
..._POSSIBLE_IMPORT_SOURCES.map((s) => `node:${s}`)
|
|
223
228
|
];
|
|
224
|
-
|
|
225
|
-
name:
|
|
229
|
+
var no_import_promises_as_default = createEslintRule({
|
|
230
|
+
name: RULE_NAME3,
|
|
226
231
|
meta: {
|
|
227
232
|
type: "problem",
|
|
228
233
|
docs: {
|
|
@@ -273,9 +278,11 @@ import ${as} from "${node.source.value}/promises";`
|
|
|
273
278
|
}
|
|
274
279
|
});
|
|
275
280
|
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
281
|
+
// src/rules/no-inline-type-import.ts
|
|
282
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES2 } from "@typescript-eslint/types";
|
|
283
|
+
var RULE_NAME4 = "no-inline-type-import";
|
|
284
|
+
var no_inline_type_import_default = createEslintRule({
|
|
285
|
+
name: RULE_NAME4,
|
|
279
286
|
meta: {
|
|
280
287
|
type: "layout",
|
|
281
288
|
docs: {
|
|
@@ -295,13 +302,13 @@ const noInlineTypeImport = createEslintRule({
|
|
|
295
302
|
ImportDeclaration: (node) => {
|
|
296
303
|
const { specifiers } = node;
|
|
297
304
|
const typeSpecifiers = specifiers.filter(
|
|
298
|
-
(s) => s.type ===
|
|
305
|
+
(s) => s.type === AST_NODE_TYPES2.ImportSpecifier && s.importKind === "type"
|
|
299
306
|
);
|
|
300
307
|
const valueSpecifiers = specifiers.filter(
|
|
301
|
-
(s) => s.type ===
|
|
308
|
+
(s) => s.type === AST_NODE_TYPES2.ImportSpecifier && s.importKind === "value"
|
|
302
309
|
);
|
|
303
310
|
const defaultImportSpecifier = specifiers.find(
|
|
304
|
-
(s) => s.type ===
|
|
311
|
+
(s) => s.type === AST_NODE_TYPES2.ImportDefaultSpecifier
|
|
305
312
|
);
|
|
306
313
|
if (typeSpecifiers.length > 0 && valueSpecifiers.length > 0) {
|
|
307
314
|
context.report({
|
|
@@ -339,8 +346,10 @@ const noInlineTypeImport = createEslintRule({
|
|
|
339
346
|
}
|
|
340
347
|
});
|
|
341
348
|
|
|
342
|
-
|
|
343
|
-
|
|
349
|
+
// src/rules/no-negated-comparison.ts
|
|
350
|
+
import { AST_NODE_TYPES as AST_NODE_TYPES3 } from "@typescript-eslint/types";
|
|
351
|
+
var RULE_NAME5 = "no-negated-comparison";
|
|
352
|
+
var negatedToPositive = {
|
|
344
353
|
"==": "!=",
|
|
345
354
|
"===": "!==",
|
|
346
355
|
"!=": "==",
|
|
@@ -350,9 +359,9 @@ const negatedToPositive = {
|
|
|
350
359
|
">": "<=",
|
|
351
360
|
">=": "<"
|
|
352
361
|
};
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
name:
|
|
362
|
+
var negatives = Object.keys(negatedToPositive);
|
|
363
|
+
var no_negated_comparison_default = createEslintRule({
|
|
364
|
+
name: RULE_NAME5,
|
|
356
365
|
meta: {
|
|
357
366
|
type: "problem",
|
|
358
367
|
docs: {
|
|
@@ -372,7 +381,7 @@ const noNegatedComparison = createEslintRule({
|
|
|
372
381
|
if (!parent) {
|
|
373
382
|
return;
|
|
374
383
|
}
|
|
375
|
-
if (negatives.includes(operator) && parent.type ===
|
|
384
|
+
if (negatives.includes(operator) && parent.type === AST_NODE_TYPES3.UnaryExpression && // Is this necessary?
|
|
376
385
|
parent.operator === "!") {
|
|
377
386
|
context.report({
|
|
378
387
|
node,
|
|
@@ -389,9 +398,10 @@ const noNegatedComparison = createEslintRule({
|
|
|
389
398
|
})
|
|
390
399
|
});
|
|
391
400
|
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
401
|
+
// src/rules/no-useless-template-string.ts
|
|
402
|
+
var RULE_NAME6 = "no-useless-template-string";
|
|
403
|
+
var no_useless_template_string_default = createEslintRule({
|
|
404
|
+
name: RULE_NAME6,
|
|
395
405
|
meta: {
|
|
396
406
|
type: "problem",
|
|
397
407
|
docs: {
|
|
@@ -427,9 +437,10 @@ const noUselessTemplateString = createEslintRule({
|
|
|
427
437
|
})
|
|
428
438
|
});
|
|
429
439
|
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
440
|
+
// src/rules/pad-after-last-import.ts
|
|
441
|
+
var RULE_NAME7 = "pad-after-last-import";
|
|
442
|
+
var pad_after_last_import_default = createEslintRule({
|
|
443
|
+
name: RULE_NAME7,
|
|
433
444
|
meta: {
|
|
434
445
|
type: "problem",
|
|
435
446
|
docs: {
|
|
@@ -457,7 +468,7 @@ const padAfterLastImport = createEslintRule({
|
|
|
457
468
|
const expectedLine = lastImportNode.loc.end.line + 1;
|
|
458
469
|
const nextTokenStartLine = nextToken?.loc.start.line;
|
|
459
470
|
if (nextToken && // Workaround: Vue
|
|
460
|
-
nextToken.value !== "
|
|
471
|
+
nextToken.value !== "</script>" && (expectedLine === nextTokenStartLine || expectedLine === firstCommentAfterTokenStartLine)) {
|
|
461
472
|
context.report({
|
|
462
473
|
node: lastImportNode,
|
|
463
474
|
messageId: "padAfterLastImport",
|
|
@@ -470,9 +481,11 @@ const padAfterLastImport = createEslintRule({
|
|
|
470
481
|
}
|
|
471
482
|
});
|
|
472
483
|
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
484
|
+
// src/rules/require-async-with-await.ts
|
|
485
|
+
import { TSESTree } from "@typescript-eslint/types";
|
|
486
|
+
var RULE_NAME8 = "require-async-with-await";
|
|
487
|
+
var require_async_with_await_default = createEslintRule({
|
|
488
|
+
name: RULE_NAME8,
|
|
476
489
|
meta: {
|
|
477
490
|
type: "problem",
|
|
478
491
|
docs: {
|
|
@@ -531,17 +544,19 @@ const requireAsyncWithAwait = createEslintRule({
|
|
|
531
544
|
}
|
|
532
545
|
});
|
|
533
546
|
|
|
534
|
-
|
|
547
|
+
// src/index.ts
|
|
548
|
+
var src_default = {
|
|
535
549
|
rules: {
|
|
536
|
-
"function-style":
|
|
537
|
-
"import-dedupe":
|
|
538
|
-
"no-inline-type-import":
|
|
539
|
-
"no-negated-comparison":
|
|
540
|
-
"no-useless-template-string":
|
|
541
|
-
"no-import-promises-as":
|
|
542
|
-
"pad-after-last-import":
|
|
543
|
-
"require-async-with-await":
|
|
550
|
+
"function-style": function_style_default,
|
|
551
|
+
"import-dedupe": import_dedupe_default,
|
|
552
|
+
"no-inline-type-import": no_inline_type_import_default,
|
|
553
|
+
"no-negated-comparison": no_negated_comparison_default,
|
|
554
|
+
"no-useless-template-string": no_useless_template_string_default,
|
|
555
|
+
"no-import-promises-as": no_import_promises_as_default,
|
|
556
|
+
"pad-after-last-import": pad_after_last_import_default,
|
|
557
|
+
"require-async-with-await": require_async_with_await_default
|
|
544
558
|
}
|
|
545
559
|
};
|
|
546
|
-
|
|
547
|
-
|
|
560
|
+
export {
|
|
561
|
+
src_default as default
|
|
562
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@so1ve/eslint-plugin",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
4
4
|
"author": "Ray <i@mk1.io> (https://github.com/so1ve/)",
|
|
5
|
+
"type": "module",
|
|
5
6
|
"keywords": [
|
|
6
7
|
"eslint",
|
|
7
8
|
"eslint-config",
|
|
@@ -16,8 +17,14 @@
|
|
|
16
17
|
"url": "https://github.com/so1ve/codestyle-config/issues"
|
|
17
18
|
},
|
|
18
19
|
"license": "MIT",
|
|
19
|
-
"
|
|
20
|
-
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"types": "./dist/index.d.ts",
|
|
23
|
+
"import": "./dist/index.js"
|
|
24
|
+
},
|
|
25
|
+
"./package.json": "./package.json"
|
|
26
|
+
},
|
|
27
|
+
"module": "./dist/index.js",
|
|
21
28
|
"types": "./dist/index.d.ts",
|
|
22
29
|
"files": [
|
|
23
30
|
"dist"
|
|
@@ -26,12 +33,12 @@
|
|
|
26
33
|
"access": "public"
|
|
27
34
|
},
|
|
28
35
|
"dependencies": {
|
|
29
|
-
"@typescript-eslint/types": "^7.
|
|
30
|
-
"@typescript-eslint/utils": "^7.
|
|
36
|
+
"@typescript-eslint/types": "^7.12.0",
|
|
37
|
+
"@typescript-eslint/utils": "^7.12.0"
|
|
31
38
|
},
|
|
32
39
|
"scripts": {
|
|
33
|
-
"build": "
|
|
34
|
-
"
|
|
35
|
-
"
|
|
40
|
+
"build": "tsup",
|
|
41
|
+
"test": "vitest",
|
|
42
|
+
"watch": "tsup --watch"
|
|
36
43
|
}
|
|
37
44
|
}
|
package/dist/index.cjs
DELETED
|
@@ -1,549 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const types = require('@typescript-eslint/types');
|
|
4
|
-
const utils = require('@typescript-eslint/utils');
|
|
5
|
-
|
|
6
|
-
const createEslintRule = utils.ESLintUtils.RuleCreator((ruleName) => ruleName);
|
|
7
|
-
function getPreviousNode(node) {
|
|
8
|
-
if (!node) {
|
|
9
|
-
return;
|
|
10
|
-
}
|
|
11
|
-
const { parent } = node;
|
|
12
|
-
if (parent && "body" in parent) {
|
|
13
|
-
const { body } = parent;
|
|
14
|
-
if (!Array.isArray(body)) {
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
const index = body.indexOf(node);
|
|
18
|
-
if (index > 0) {
|
|
19
|
-
return body[index - 1];
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
const RULE_NAME$7 = "function-style";
|
|
25
|
-
const functionStyle = createEslintRule({
|
|
26
|
-
name: RULE_NAME$7,
|
|
27
|
-
meta: {
|
|
28
|
-
type: "problem",
|
|
29
|
-
docs: {
|
|
30
|
-
description: "Enforce function style.",
|
|
31
|
-
recommended: "stylistic"
|
|
32
|
-
},
|
|
33
|
-
fixable: "code",
|
|
34
|
-
schema: [],
|
|
35
|
-
messages: {
|
|
36
|
-
arrow: "Expected an arrow function shorthand.",
|
|
37
|
-
declaration: "Expected a function declaration."
|
|
38
|
-
}
|
|
39
|
-
},
|
|
40
|
-
defaultOptions: [],
|
|
41
|
-
create: (context) => {
|
|
42
|
-
const sourceCode = context.sourceCode;
|
|
43
|
-
function getLoneReturnStatement(node) {
|
|
44
|
-
const { body } = node;
|
|
45
|
-
if (body.type !== types.AST_NODE_TYPES.BlockStatement) {
|
|
46
|
-
return;
|
|
47
|
-
}
|
|
48
|
-
const { body: blockBody } = body;
|
|
49
|
-
const allComments = sourceCode.getCommentsInside(node);
|
|
50
|
-
if (blockBody.length !== 1) {
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
const [statement] = blockBody;
|
|
54
|
-
const statementComments = sourceCode.getCommentsInside(statement);
|
|
55
|
-
if (allComments.length !== statementComments.length) {
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
if (statement?.type === types.AST_NODE_TYPES.ReturnStatement) {
|
|
59
|
-
return statement;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
function generateFunction(type, name, node, rawStatement, asVariable = true) {
|
|
63
|
-
const async = node.async ? "async " : "";
|
|
64
|
-
const generics = node.typeParameters ? sourceCode.getText(node.typeParameters) : "";
|
|
65
|
-
const params = node.params.map((param) => sourceCode.getText(param)).join(", ");
|
|
66
|
-
const returnType = node.returnType ? sourceCode.getText(node.returnType) : "";
|
|
67
|
-
const body = sourceCode.getText(node.body);
|
|
68
|
-
const variableDeclaration = asVariable && name ? `const ${name} = ` : "";
|
|
69
|
-
return type === "arrow" ? `${variableDeclaration}${async}${generics}(${params})${returnType} => ${rawStatement};` : `${async}function ${name}${generics}(${params})${returnType} ${body}`;
|
|
70
|
-
}
|
|
71
|
-
const scopeStack = [];
|
|
72
|
-
let haveThisAccess = false;
|
|
73
|
-
function setupScope(node) {
|
|
74
|
-
scopeStack.push(sourceCode.getScope(node));
|
|
75
|
-
}
|
|
76
|
-
function clearThisAccess() {
|
|
77
|
-
scopeStack.pop();
|
|
78
|
-
haveThisAccess = false;
|
|
79
|
-
}
|
|
80
|
-
return {
|
|
81
|
-
"FunctionExpression": setupScope,
|
|
82
|
-
"FunctionExpression:exit"(node) {
|
|
83
|
-
if (node.parent?.id?.typeAnnotation || node.parent?.type !== types.AST_NODE_TYPES.VariableDeclarator || haveThisAccess) {
|
|
84
|
-
clearThisAccess();
|
|
85
|
-
return;
|
|
86
|
-
}
|
|
87
|
-
const name = node.parent.id.name;
|
|
88
|
-
context.report({
|
|
89
|
-
node,
|
|
90
|
-
messageId: "declaration",
|
|
91
|
-
fix: (fixer) => fixer.replaceText(
|
|
92
|
-
node.parent.parent,
|
|
93
|
-
generateFunction("declaration", name, node)
|
|
94
|
-
)
|
|
95
|
-
});
|
|
96
|
-
clearThisAccess();
|
|
97
|
-
},
|
|
98
|
-
"FunctionDeclaration:not(TSDeclareFunction + FunctionDeclaration)": setupScope,
|
|
99
|
-
"FunctionDeclaration:not(TSDeclareFunction + FunctionDeclaration):exit"(node) {
|
|
100
|
-
if (haveThisAccess) {
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
const previousNode = getPreviousNode(node.parent);
|
|
104
|
-
if (previousNode?.type === types.AST_NODE_TYPES.ExportNamedDeclaration && previousNode.declaration?.type === types.AST_NODE_TYPES.TSDeclareFunction) {
|
|
105
|
-
return;
|
|
106
|
-
}
|
|
107
|
-
const statement = getLoneReturnStatement(node);
|
|
108
|
-
const isExportDefault = node.parent?.type === types.AST_NODE_TYPES.ExportDefaultDeclaration;
|
|
109
|
-
if (!statement?.argument || !node.id?.name && !isExportDefault || node.generator) {
|
|
110
|
-
clearThisAccess();
|
|
111
|
-
return;
|
|
112
|
-
}
|
|
113
|
-
const returnVal = `(${sourceCode.getText(statement.argument)})`;
|
|
114
|
-
context.report({
|
|
115
|
-
node,
|
|
116
|
-
messageId: "arrow",
|
|
117
|
-
fix: (fixer) => fixer.replaceText(
|
|
118
|
-
node,
|
|
119
|
-
generateFunction(
|
|
120
|
-
"arrow",
|
|
121
|
-
node.id?.name ?? null,
|
|
122
|
-
node,
|
|
123
|
-
returnVal,
|
|
124
|
-
!isExportDefault
|
|
125
|
-
)
|
|
126
|
-
)
|
|
127
|
-
});
|
|
128
|
-
clearThisAccess();
|
|
129
|
-
},
|
|
130
|
-
"ArrowFunctionExpression": setupScope,
|
|
131
|
-
"ArrowFunctionExpression:exit"(node) {
|
|
132
|
-
if (haveThisAccess) {
|
|
133
|
-
return;
|
|
134
|
-
}
|
|
135
|
-
const { body, parent } = node;
|
|
136
|
-
const statement = getLoneReturnStatement(node);
|
|
137
|
-
if (statement?.argument) {
|
|
138
|
-
const returnVal = `(${sourceCode.getText(statement.argument)})`;
|
|
139
|
-
context.report({
|
|
140
|
-
node,
|
|
141
|
-
messageId: "arrow",
|
|
142
|
-
fix: (fixer) => fixer.replaceText(node.body, returnVal)
|
|
143
|
-
});
|
|
144
|
-
} else if (body.type === types.AST_NODE_TYPES.BlockStatement && !parent?.id?.typeAnnotation) {
|
|
145
|
-
const { body: blockBody } = body;
|
|
146
|
-
if (blockBody.length > 0 && node.parent?.parent?.type === types.AST_NODE_TYPES.VariableDeclaration) {
|
|
147
|
-
const { parent: grandParent } = node.parent;
|
|
148
|
-
context.report({
|
|
149
|
-
node: grandParent,
|
|
150
|
-
messageId: "declaration",
|
|
151
|
-
fix: (fixer) => fixer.replaceText(
|
|
152
|
-
grandParent,
|
|
153
|
-
generateFunction(
|
|
154
|
-
"declaration",
|
|
155
|
-
node.parent.id.name,
|
|
156
|
-
node
|
|
157
|
-
)
|
|
158
|
-
)
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
clearThisAccess();
|
|
163
|
-
},
|
|
164
|
-
ThisExpression(node) {
|
|
165
|
-
haveThisAccess = scopeStack.includes(sourceCode.getScope(node));
|
|
166
|
-
}
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
const RULE_NAME$6 = "import-dedupe";
|
|
172
|
-
const importDedupe = createEslintRule({
|
|
173
|
-
name: RULE_NAME$6,
|
|
174
|
-
meta: {
|
|
175
|
-
type: "problem",
|
|
176
|
-
docs: {
|
|
177
|
-
description: "Fix duplication in imports.",
|
|
178
|
-
recommended: "recommended"
|
|
179
|
-
},
|
|
180
|
-
fixable: "code",
|
|
181
|
-
schema: [],
|
|
182
|
-
messages: {
|
|
183
|
-
importDedupe: "Expect no duplication in imports."
|
|
184
|
-
}
|
|
185
|
-
},
|
|
186
|
-
defaultOptions: [],
|
|
187
|
-
create: (context) => ({
|
|
188
|
-
ImportDeclaration(node) {
|
|
189
|
-
if (node.specifiers.length <= 1) {
|
|
190
|
-
return;
|
|
191
|
-
}
|
|
192
|
-
const names = /* @__PURE__ */ new Set();
|
|
193
|
-
for (const n of node.specifiers) {
|
|
194
|
-
const id = n.local.name;
|
|
195
|
-
if (names.has(id)) {
|
|
196
|
-
context.report({
|
|
197
|
-
node,
|
|
198
|
-
loc: {
|
|
199
|
-
start: n.loc.end,
|
|
200
|
-
end: n.loc.start
|
|
201
|
-
},
|
|
202
|
-
messageId: "importDedupe",
|
|
203
|
-
fix(fixer) {
|
|
204
|
-
const start = n.range[0];
|
|
205
|
-
let end = n.range[1];
|
|
206
|
-
const nextToken = context.sourceCode.getTokenAfter(n);
|
|
207
|
-
if (nextToken && nextToken.value === ",") {
|
|
208
|
-
end = nextToken.range[1];
|
|
209
|
-
}
|
|
210
|
-
return fixer.removeRange([start, end]);
|
|
211
|
-
}
|
|
212
|
-
});
|
|
213
|
-
}
|
|
214
|
-
names.add(id);
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
})
|
|
218
|
-
});
|
|
219
|
-
|
|
220
|
-
const RULE_NAME$5 = "no-import-promises-as";
|
|
221
|
-
const _POSSIBLE_IMPORT_SOURCES = ["dns", "fs", "readline", "stream"];
|
|
222
|
-
const POSSIBLE_IMPORT_SOURCES = [
|
|
223
|
-
..._POSSIBLE_IMPORT_SOURCES,
|
|
224
|
-
..._POSSIBLE_IMPORT_SOURCES.map((s) => `node:${s}`)
|
|
225
|
-
];
|
|
226
|
-
const noImportPromisesAs = createEslintRule({
|
|
227
|
-
name: RULE_NAME$5,
|
|
228
|
-
meta: {
|
|
229
|
-
type: "problem",
|
|
230
|
-
docs: {
|
|
231
|
-
description: "Disallow import promises as.",
|
|
232
|
-
recommended: "stylistic"
|
|
233
|
-
},
|
|
234
|
-
fixable: "code",
|
|
235
|
-
schema: [],
|
|
236
|
-
messages: {
|
|
237
|
-
noImportPromisesAs: "Expect no import promises as."
|
|
238
|
-
}
|
|
239
|
-
},
|
|
240
|
-
defaultOptions: [],
|
|
241
|
-
create: (context) => {
|
|
242
|
-
const sourceCode = context.sourceCode;
|
|
243
|
-
const { text } = sourceCode;
|
|
244
|
-
return {
|
|
245
|
-
ImportDeclaration(node) {
|
|
246
|
-
if (!POSSIBLE_IMPORT_SOURCES.includes(node.source.value)) {
|
|
247
|
-
return;
|
|
248
|
-
}
|
|
249
|
-
const promisesSpecifier = node.specifiers.find(
|
|
250
|
-
(s) => s.type === "ImportSpecifier" && s.imported.name === "promises" && s.local.name !== "promises"
|
|
251
|
-
);
|
|
252
|
-
const as = promisesSpecifier?.local.name;
|
|
253
|
-
if (!promisesSpecifier || !as) {
|
|
254
|
-
return;
|
|
255
|
-
}
|
|
256
|
-
context.report({
|
|
257
|
-
node,
|
|
258
|
-
messageId: "noImportPromisesAs",
|
|
259
|
-
*fix(fixer) {
|
|
260
|
-
const s = promisesSpecifier.range[0];
|
|
261
|
-
let e = promisesSpecifier.range[1];
|
|
262
|
-
if (text[e] === ",") {
|
|
263
|
-
e += 1;
|
|
264
|
-
}
|
|
265
|
-
yield fixer.removeRange([s, e]);
|
|
266
|
-
yield fixer.insertTextAfter(
|
|
267
|
-
node,
|
|
268
|
-
`
|
|
269
|
-
import ${as} from "${node.source.value}/promises";`
|
|
270
|
-
);
|
|
271
|
-
}
|
|
272
|
-
});
|
|
273
|
-
}
|
|
274
|
-
};
|
|
275
|
-
}
|
|
276
|
-
});
|
|
277
|
-
|
|
278
|
-
const RULE_NAME$4 = "no-inline-type-import";
|
|
279
|
-
const noInlineTypeImport = createEslintRule({
|
|
280
|
-
name: RULE_NAME$4,
|
|
281
|
-
meta: {
|
|
282
|
-
type: "layout",
|
|
283
|
-
docs: {
|
|
284
|
-
description: "Disallow inline type import.",
|
|
285
|
-
recommended: "stylistic"
|
|
286
|
-
},
|
|
287
|
-
fixable: "code",
|
|
288
|
-
schema: [],
|
|
289
|
-
messages: {
|
|
290
|
-
noInlineTypeImport: "Expected no inline type import."
|
|
291
|
-
}
|
|
292
|
-
},
|
|
293
|
-
defaultOptions: [],
|
|
294
|
-
create: (context) => {
|
|
295
|
-
const sourceCode = context.sourceCode;
|
|
296
|
-
return {
|
|
297
|
-
ImportDeclaration: (node) => {
|
|
298
|
-
const { specifiers } = node;
|
|
299
|
-
const typeSpecifiers = specifiers.filter(
|
|
300
|
-
(s) => s.type === types.AST_NODE_TYPES.ImportSpecifier && s.importKind === "type"
|
|
301
|
-
);
|
|
302
|
-
const valueSpecifiers = specifiers.filter(
|
|
303
|
-
(s) => s.type === types.AST_NODE_TYPES.ImportSpecifier && s.importKind === "value"
|
|
304
|
-
);
|
|
305
|
-
const defaultImportSpecifier = specifiers.find(
|
|
306
|
-
(s) => s.type === types.AST_NODE_TYPES.ImportDefaultSpecifier
|
|
307
|
-
);
|
|
308
|
-
if (typeSpecifiers.length > 0 && valueSpecifiers.length > 0) {
|
|
309
|
-
context.report({
|
|
310
|
-
node,
|
|
311
|
-
messageId: "noInlineTypeImport",
|
|
312
|
-
fix(fixer) {
|
|
313
|
-
const typeSpecifiersText = typeSpecifiers.map((s) => sourceCode.getText(s).replace("type ", "")).join(", ");
|
|
314
|
-
const valueSpecifiersText = valueSpecifiers.map((s) => sourceCode.getText(s)).join(", ");
|
|
315
|
-
const defaultImportSpecifierText = sourceCode.getText(
|
|
316
|
-
defaultImportSpecifier
|
|
317
|
-
);
|
|
318
|
-
const defaultAndValueSpecifiersText = defaultImportSpecifier ? `import ${defaultImportSpecifierText}, { ${valueSpecifiersText} } from "${node.source.value}";` : `import { ${valueSpecifiersText} } from "${node.source.value}";`;
|
|
319
|
-
const texts = [
|
|
320
|
-
`import type { ${typeSpecifiersText} } from "${node.source.value}";`,
|
|
321
|
-
defaultAndValueSpecifiersText
|
|
322
|
-
];
|
|
323
|
-
return fixer.replaceText(node, texts.join("\n"));
|
|
324
|
-
}
|
|
325
|
-
});
|
|
326
|
-
} else if (typeSpecifiers.length > 0) {
|
|
327
|
-
context.report({
|
|
328
|
-
node,
|
|
329
|
-
messageId: "noInlineTypeImport",
|
|
330
|
-
fix(fixer) {
|
|
331
|
-
const typeSpecifiersText = typeSpecifiers.map((s) => sourceCode.getText(s).replace("type ", "")).join(", ");
|
|
332
|
-
return fixer.replaceText(
|
|
333
|
-
node,
|
|
334
|
-
`import type { ${typeSpecifiersText} } from "${node.source.value}";`
|
|
335
|
-
);
|
|
336
|
-
}
|
|
337
|
-
});
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
};
|
|
341
|
-
}
|
|
342
|
-
});
|
|
343
|
-
|
|
344
|
-
const RULE_NAME$3 = "no-negated-comparison";
|
|
345
|
-
const negatedToPositive = {
|
|
346
|
-
"==": "!=",
|
|
347
|
-
"===": "!==",
|
|
348
|
-
"!=": "==",
|
|
349
|
-
"!==": "===",
|
|
350
|
-
"<": ">=",
|
|
351
|
-
"<=": ">",
|
|
352
|
-
">": "<=",
|
|
353
|
-
">=": "<"
|
|
354
|
-
};
|
|
355
|
-
const negatives = Object.keys(negatedToPositive);
|
|
356
|
-
const noNegatedComparison = createEslintRule({
|
|
357
|
-
name: RULE_NAME$3,
|
|
358
|
-
meta: {
|
|
359
|
-
type: "problem",
|
|
360
|
-
docs: {
|
|
361
|
-
description: "Disallow negated comparison.",
|
|
362
|
-
recommended: "stylistic"
|
|
363
|
-
},
|
|
364
|
-
fixable: "code",
|
|
365
|
-
schema: [],
|
|
366
|
-
messages: {
|
|
367
|
-
noNegatedComparison: "Expect no negated comparison."
|
|
368
|
-
}
|
|
369
|
-
},
|
|
370
|
-
defaultOptions: [],
|
|
371
|
-
create: (context) => ({
|
|
372
|
-
BinaryExpression(node) {
|
|
373
|
-
const { parent, left, right, operator } = node;
|
|
374
|
-
if (!parent) {
|
|
375
|
-
return;
|
|
376
|
-
}
|
|
377
|
-
if (negatives.includes(operator) && parent.type === types.AST_NODE_TYPES.UnaryExpression && // Is this necessary?
|
|
378
|
-
parent.operator === "!") {
|
|
379
|
-
context.report({
|
|
380
|
-
node,
|
|
381
|
-
messageId: "noNegatedComparison",
|
|
382
|
-
*fix(fixer) {
|
|
383
|
-
const operatorRange = [left.range[1], right.range[0]];
|
|
384
|
-
const fixedOperator = negatedToPositive[operator];
|
|
385
|
-
yield fixer.replaceTextRange(operatorRange, fixedOperator);
|
|
386
|
-
yield fixer.removeRange([parent.range[0], parent.range[0] + 1]);
|
|
387
|
-
}
|
|
388
|
-
});
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
})
|
|
392
|
-
});
|
|
393
|
-
|
|
394
|
-
const RULE_NAME$2 = "no-useless-template-string";
|
|
395
|
-
const noUselessTemplateString = createEslintRule({
|
|
396
|
-
name: RULE_NAME$2,
|
|
397
|
-
meta: {
|
|
398
|
-
type: "problem",
|
|
399
|
-
docs: {
|
|
400
|
-
description: "No useless template string.",
|
|
401
|
-
recommended: "stylistic"
|
|
402
|
-
},
|
|
403
|
-
fixable: "code",
|
|
404
|
-
schema: [],
|
|
405
|
-
messages: {
|
|
406
|
-
noUselessTemplateString: "No useless template string."
|
|
407
|
-
}
|
|
408
|
-
},
|
|
409
|
-
defaultOptions: [],
|
|
410
|
-
create: (context) => ({
|
|
411
|
-
"TemplateLiteral:not(TaggedTemplateExpression > TemplateLiteral)"(node) {
|
|
412
|
-
const { quasis } = node;
|
|
413
|
-
const isSafe = !quasis.some(
|
|
414
|
-
({ value: { raw } }) => raw.includes('"') || raw.includes("'") || raw.includes("\n")
|
|
415
|
-
);
|
|
416
|
-
if (node.expressions.length === 0 && isSafe) {
|
|
417
|
-
context.report({
|
|
418
|
-
node,
|
|
419
|
-
messageId: "noUselessTemplateString",
|
|
420
|
-
fix(fixer) {
|
|
421
|
-
return fixer.replaceTextRange(
|
|
422
|
-
node.range,
|
|
423
|
-
`"${node.quasis[0].value.raw}"`
|
|
424
|
-
);
|
|
425
|
-
}
|
|
426
|
-
});
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
})
|
|
430
|
-
});
|
|
431
|
-
|
|
432
|
-
const RULE_NAME$1 = "pad-after-last-import";
|
|
433
|
-
const padAfterLastImport = createEslintRule({
|
|
434
|
-
name: RULE_NAME$1,
|
|
435
|
-
meta: {
|
|
436
|
-
type: "problem",
|
|
437
|
-
docs: {
|
|
438
|
-
description: "Pad after the last import.",
|
|
439
|
-
recommended: "stylistic"
|
|
440
|
-
},
|
|
441
|
-
fixable: "code",
|
|
442
|
-
schema: [],
|
|
443
|
-
messages: {
|
|
444
|
-
padAfterLastImport: "Expected a blank line after the last import."
|
|
445
|
-
}
|
|
446
|
-
},
|
|
447
|
-
defaultOptions: [],
|
|
448
|
-
create: (context) => {
|
|
449
|
-
const sourceCode = context.sourceCode;
|
|
450
|
-
let lastImportNode = null;
|
|
451
|
-
return {
|
|
452
|
-
ImportDeclaration(node) {
|
|
453
|
-
lastImportNode = node;
|
|
454
|
-
},
|
|
455
|
-
"Program:exit"() {
|
|
456
|
-
if (lastImportNode) {
|
|
457
|
-
const nextToken = sourceCode.getTokenAfter(lastImportNode);
|
|
458
|
-
const firstCommentAfterTokenStartLine = sourceCode.getCommentsAfter(lastImportNode)[0]?.loc.start.line;
|
|
459
|
-
const expectedLine = lastImportNode.loc.end.line + 1;
|
|
460
|
-
const nextTokenStartLine = nextToken?.loc.start.line;
|
|
461
|
-
if (nextToken && // Workaround: Vue
|
|
462
|
-
nextToken.value !== "<\/script>" && (expectedLine === nextTokenStartLine || expectedLine === firstCommentAfterTokenStartLine)) {
|
|
463
|
-
context.report({
|
|
464
|
-
node: lastImportNode,
|
|
465
|
-
messageId: "padAfterLastImport",
|
|
466
|
-
fix: (fixer) => fixer.insertTextAfter(lastImportNode, "\n")
|
|
467
|
-
});
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
}
|
|
471
|
-
};
|
|
472
|
-
}
|
|
473
|
-
});
|
|
474
|
-
|
|
475
|
-
const RULE_NAME = "require-async-with-await";
|
|
476
|
-
const requireAsyncWithAwait = createEslintRule({
|
|
477
|
-
name: RULE_NAME,
|
|
478
|
-
meta: {
|
|
479
|
-
type: "problem",
|
|
480
|
-
docs: {
|
|
481
|
-
description: "Require using async keyword with await.",
|
|
482
|
-
recommended: "recommended"
|
|
483
|
-
},
|
|
484
|
-
fixable: "code",
|
|
485
|
-
schema: [],
|
|
486
|
-
messages: {
|
|
487
|
-
requireAsyncWithAwait: "Expect using async keyword with await."
|
|
488
|
-
}
|
|
489
|
-
},
|
|
490
|
-
defaultOptions: [],
|
|
491
|
-
create: (context) => {
|
|
492
|
-
const functionNodeStack = [];
|
|
493
|
-
function setupNode(node) {
|
|
494
|
-
functionNodeStack.push(node);
|
|
495
|
-
}
|
|
496
|
-
function clearNode() {
|
|
497
|
-
functionNodeStack.pop();
|
|
498
|
-
}
|
|
499
|
-
return {
|
|
500
|
-
"FunctionExpression": setupNode,
|
|
501
|
-
"FunctionExpression:exit": clearNode,
|
|
502
|
-
"FunctionDeclaration": setupNode,
|
|
503
|
-
"FunctionDeclaration:exit": clearNode,
|
|
504
|
-
"ArrowFunctionExpression": setupNode,
|
|
505
|
-
"ArrowFunctionExpression:exit": clearNode,
|
|
506
|
-
AwaitExpression() {
|
|
507
|
-
const node = functionNodeStack[functionNodeStack.length - 1];
|
|
508
|
-
if (!node || node.async) {
|
|
509
|
-
return;
|
|
510
|
-
}
|
|
511
|
-
let fixRange;
|
|
512
|
-
if (node.type === types.TSESTree.AST_NODE_TYPES.ArrowFunctionExpression) {
|
|
513
|
-
fixRange = node.range;
|
|
514
|
-
}
|
|
515
|
-
if (node.type === types.TSESTree.AST_NODE_TYPES.FunctionDeclaration || node.type === types.TSESTree.AST_NODE_TYPES.FunctionExpression) {
|
|
516
|
-
if (node.parent.type === types.TSESTree.AST_NODE_TYPES.Property || node.parent.type === types.TSESTree.AST_NODE_TYPES.MethodDefinition) {
|
|
517
|
-
if (node.parent.kind === "method" || node.parent.kind === "init") {
|
|
518
|
-
fixRange = node.parent.key.range;
|
|
519
|
-
}
|
|
520
|
-
} else {
|
|
521
|
-
fixRange = node.range;
|
|
522
|
-
}
|
|
523
|
-
}
|
|
524
|
-
if (fixRange) {
|
|
525
|
-
context.report({
|
|
526
|
-
node,
|
|
527
|
-
messageId: "requireAsyncWithAwait",
|
|
528
|
-
fix: (fixer) => fixer.insertTextBeforeRange(fixRange, "async ")
|
|
529
|
-
});
|
|
530
|
-
}
|
|
531
|
-
}
|
|
532
|
-
};
|
|
533
|
-
}
|
|
534
|
-
});
|
|
535
|
-
|
|
536
|
-
const index = {
|
|
537
|
-
rules: {
|
|
538
|
-
"function-style": functionStyle,
|
|
539
|
-
"import-dedupe": importDedupe,
|
|
540
|
-
"no-inline-type-import": noInlineTypeImport,
|
|
541
|
-
"no-negated-comparison": noNegatedComparison,
|
|
542
|
-
"no-useless-template-string": noUselessTemplateString,
|
|
543
|
-
"no-import-promises-as": noImportPromisesAs,
|
|
544
|
-
"pad-after-last-import": padAfterLastImport,
|
|
545
|
-
"require-async-with-await": requireAsyncWithAwait
|
|
546
|
-
}
|
|
547
|
-
};
|
|
548
|
-
|
|
549
|
-
module.exports = index;
|
package/dist/index.d.cts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import * as _typescript_eslint_utils_ts_eslint from '@typescript-eslint/utils/ts-eslint';
|
|
2
|
-
|
|
3
|
-
type MessageIds = "arrow" | "declaration";
|
|
4
|
-
|
|
5
|
-
declare const _default: {
|
|
6
|
-
rules: {
|
|
7
|
-
"function-style": _typescript_eslint_utils_ts_eslint.RuleModule<MessageIds, [], _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
8
|
-
"import-dedupe": _typescript_eslint_utils_ts_eslint.RuleModule<"importDedupe", [], _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
9
|
-
"no-inline-type-import": _typescript_eslint_utils_ts_eslint.RuleModule<"noInlineTypeImport", [], _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
10
|
-
"no-negated-comparison": _typescript_eslint_utils_ts_eslint.RuleModule<"noNegatedComparison", [], _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
11
|
-
"no-useless-template-string": _typescript_eslint_utils_ts_eslint.RuleModule<"noUselessTemplateString", [], _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
12
|
-
"no-import-promises-as": _typescript_eslint_utils_ts_eslint.RuleModule<"noImportPromisesAs", [], _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
13
|
-
"pad-after-last-import": _typescript_eslint_utils_ts_eslint.RuleModule<"padAfterLastImport", [], _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
14
|
-
"require-async-with-await": _typescript_eslint_utils_ts_eslint.RuleModule<"requireAsyncWithAwait", [], _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
15
|
-
};
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export { _default as default };
|
package/dist/index.d.mts
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import * as _typescript_eslint_utils_ts_eslint from '@typescript-eslint/utils/ts-eslint';
|
|
2
|
-
|
|
3
|
-
type MessageIds = "arrow" | "declaration";
|
|
4
|
-
|
|
5
|
-
declare const _default: {
|
|
6
|
-
rules: {
|
|
7
|
-
"function-style": _typescript_eslint_utils_ts_eslint.RuleModule<MessageIds, [], _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
8
|
-
"import-dedupe": _typescript_eslint_utils_ts_eslint.RuleModule<"importDedupe", [], _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
9
|
-
"no-inline-type-import": _typescript_eslint_utils_ts_eslint.RuleModule<"noInlineTypeImport", [], _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
10
|
-
"no-negated-comparison": _typescript_eslint_utils_ts_eslint.RuleModule<"noNegatedComparison", [], _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
11
|
-
"no-useless-template-string": _typescript_eslint_utils_ts_eslint.RuleModule<"noUselessTemplateString", [], _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
12
|
-
"no-import-promises-as": _typescript_eslint_utils_ts_eslint.RuleModule<"noImportPromisesAs", [], _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
13
|
-
"pad-after-last-import": _typescript_eslint_utils_ts_eslint.RuleModule<"padAfterLastImport", [], _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
14
|
-
"require-async-with-await": _typescript_eslint_utils_ts_eslint.RuleModule<"requireAsyncWithAwait", [], _typescript_eslint_utils_ts_eslint.RuleListener>;
|
|
15
|
-
};
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export { _default as default };
|