@so1ve/eslint-plugin 3.9.0 → 3.10.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 +1 -0
- package/dist/index.js +73 -37
- package/package.json +3 -3
package/dist/index.d.ts
CHANGED
|
@@ -19,6 +19,7 @@ declare const _default: {
|
|
|
19
19
|
"no-useless-template-string": _typescript_eslint_utils_ts_eslint0.RuleModule<"noUselessTemplateString", [], unknown, _typescript_eslint_utils_ts_eslint0.RuleListener>;
|
|
20
20
|
"no-import-promises-as": _typescript_eslint_utils_ts_eslint0.RuleModule<"noImportPromisesAs", [], unknown, _typescript_eslint_utils_ts_eslint0.RuleListener>;
|
|
21
21
|
"pad-after-last-import": _typescript_eslint_utils_ts_eslint0.RuleModule<"padAfterLastImport", [], unknown, _typescript_eslint_utils_ts_eslint0.RuleListener>;
|
|
22
|
+
"prefer-ts-expect-error": _typescript_eslint_utils_ts_eslint0.RuleModule<"preferExpectErrorComment", [], unknown, _typescript_eslint_utils_ts_eslint0.RuleListener>;
|
|
22
23
|
"require-async-with-await": _typescript_eslint_utils_ts_eslint0.RuleModule<"requireAsyncWithAwait", [], unknown, _typescript_eslint_utils_ts_eslint0.RuleListener>;
|
|
23
24
|
"vue-root-element-sort-attributes": _typescript_eslint_utils_ts_eslint0.RuleModule<"wrongOrder", Options, unknown, _typescript_eslint_utils_ts_eslint0.RuleListener>;
|
|
24
25
|
};
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AST_NODE_TYPES, TSESTree } from "@typescript-eslint/types";
|
|
2
|
-
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
2
|
+
import { AST_TOKEN_TYPES, ESLintUtils } from "@typescript-eslint/utils";
|
|
3
3
|
|
|
4
4
|
//#region src/utils/index.ts
|
|
5
5
|
const createEslintRule = ESLintUtils.RuleCreator((ruleName) => ruleName);
|
|
@@ -55,12 +55,10 @@ var function_style_default = createEslintRule({
|
|
|
55
55
|
});
|
|
56
56
|
function generateArrowFunction(name, info, returnValue, asVariable = true) {
|
|
57
57
|
const asyncKeyword = info.async ? "async " : "";
|
|
58
|
-
|
|
59
|
-
return `${variableDeclaration}${asyncKeyword}${info.generics}(${info.params})${info.returnType} => ${returnValue};`;
|
|
58
|
+
return `${asVariable && name ? `const ${name} = ` : ""}${asyncKeyword}${info.generics}(${info.params})${info.returnType} => ${returnValue};`;
|
|
60
59
|
}
|
|
61
60
|
function generateFunctionDeclaration(name, info) {
|
|
62
|
-
|
|
63
|
-
return `${asyncKeyword}function ${name}${info.generics}(${info.params})${info.returnType} ${info.body}`;
|
|
61
|
+
return `${info.async ? "async " : ""}function ${name}${info.generics}(${info.params})${info.returnType} ${info.body}`;
|
|
64
62
|
}
|
|
65
63
|
function setupScope(node) {
|
|
66
64
|
scopeStack.push(sourceCode.getScope(node));
|
|
@@ -185,7 +183,7 @@ var import_dedupe_default = createEslintRule({
|
|
|
185
183
|
const start = n.range[0];
|
|
186
184
|
let end = n.range[1];
|
|
187
185
|
const nextToken = context.sourceCode.getTokenAfter(n);
|
|
188
|
-
if (nextToken
|
|
186
|
+
if (nextToken?.value === ",") end = nextToken.range[1];
|
|
189
187
|
return fixer.removeRange([start, end]);
|
|
190
188
|
}
|
|
191
189
|
});
|
|
@@ -214,8 +212,7 @@ var no_import_promises_as_default = createEslintRule({
|
|
|
214
212
|
},
|
|
215
213
|
defaultOptions: [],
|
|
216
214
|
create: (context) => {
|
|
217
|
-
const
|
|
218
|
-
const { text } = sourceCode;
|
|
215
|
+
const { text } = context.sourceCode;
|
|
219
216
|
return { ImportDeclaration(node) {
|
|
220
217
|
if (!POSSIBLE_IMPORT_SOURCES.includes(node.source.value)) return;
|
|
221
218
|
const promisesSpecifier = node.specifiers.find((s) => s.type === "ImportSpecifier" && s.imported.type === "Identifier" && s.imported.name === "promises" && s.local.name !== "promises");
|
|
@@ -249,35 +246,32 @@ var no_inline_type_import_default = createEslintRule({
|
|
|
249
246
|
messages: { noInlineTypeImport: "Expected no inline type import." }
|
|
250
247
|
},
|
|
251
248
|
defaultOptions: [],
|
|
252
|
-
create: (context) => {
|
|
253
|
-
const
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
});
|
|
279
|
-
} };
|
|
280
|
-
}
|
|
249
|
+
create: (context) => ({ ImportDeclaration: (node) => {
|
|
250
|
+
const { specifiers } = node;
|
|
251
|
+
const typeSpecifiers = specifiers.filter((s) => s.type === AST_NODE_TYPES.ImportSpecifier && s.importKind === "type");
|
|
252
|
+
const valueSpecifiers = specifiers.filter((s) => s.type === AST_NODE_TYPES.ImportSpecifier && s.importKind === "value");
|
|
253
|
+
const defaultImportSpecifier = specifiers.find((s) => s.type === AST_NODE_TYPES.ImportDefaultSpecifier);
|
|
254
|
+
if (typeSpecifiers.length > 0) if (valueSpecifiers.length > 0) context.report({
|
|
255
|
+
node,
|
|
256
|
+
messageId: "noInlineTypeImport",
|
|
257
|
+
fix(fixer) {
|
|
258
|
+
const typeSpecifiersText = typeSpecifiers.map((s) => s.local.name).join(", ");
|
|
259
|
+
const valueSpecifiersText = valueSpecifiers.map((s) => s.local.name).join(", ");
|
|
260
|
+
const defaultImportSpecifierText = defaultImportSpecifier?.local.name;
|
|
261
|
+
const defaultAndValueSpecifiersText = defaultImportSpecifier ? `import ${defaultImportSpecifierText}, { ${valueSpecifiersText} } from "${node.source.value}";` : `import { ${valueSpecifiersText} } from "${node.source.value}";`;
|
|
262
|
+
const texts = [`import type { ${typeSpecifiersText} } from "${node.source.value}";`, defaultAndValueSpecifiersText];
|
|
263
|
+
return fixer.replaceText(node, texts.join("\n"));
|
|
264
|
+
}
|
|
265
|
+
});
|
|
266
|
+
else context.report({
|
|
267
|
+
node,
|
|
268
|
+
messageId: "noInlineTypeImport",
|
|
269
|
+
fix(fixer) {
|
|
270
|
+
const typeSpecifiersText = typeSpecifiers.map((s) => s.local.name).join(", ");
|
|
271
|
+
return fixer.replaceText(node, `import type { ${typeSpecifiersText} } from "${node.source.value}";`);
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
} })
|
|
281
275
|
});
|
|
282
276
|
|
|
283
277
|
//#endregion
|
|
@@ -383,6 +377,47 @@ var pad_after_last_import_default = createEslintRule({
|
|
|
383
377
|
}
|
|
384
378
|
});
|
|
385
379
|
|
|
380
|
+
//#endregion
|
|
381
|
+
//#region src/rules/prefer-ts-expect-error.ts
|
|
382
|
+
var prefer_ts_expect_error_default = createEslintRule({
|
|
383
|
+
name: "prefer-ts-expect-error",
|
|
384
|
+
meta: {
|
|
385
|
+
type: "problem",
|
|
386
|
+
docs: { description: "Enforce using `@ts-expect-error` over `@ts-ignore`" },
|
|
387
|
+
fixable: "code",
|
|
388
|
+
messages: { preferExpectErrorComment: "Use \"@ts-expect-error\" to ensure an error is actually being suppressed." },
|
|
389
|
+
replacedBy: ["@typescript-eslint/ban-ts-comment"],
|
|
390
|
+
schema: []
|
|
391
|
+
},
|
|
392
|
+
defaultOptions: [],
|
|
393
|
+
create(context) {
|
|
394
|
+
const tsIgnoreRegExpSingleLine = /^\s*(?:\/\s*)?@ts-ignore/;
|
|
395
|
+
const tsIgnoreRegExpMultiLine = /^\s*(?:(?:\/|\*)+\s*)?@ts-ignore/;
|
|
396
|
+
const isLineComment = (comment) => comment.type === AST_TOKEN_TYPES.Line;
|
|
397
|
+
function getLastCommentLine(comment) {
|
|
398
|
+
if (isLineComment(comment)) return comment.value;
|
|
399
|
+
const commentlines = comment.value.split("\n");
|
|
400
|
+
return commentlines[commentlines.length - 1];
|
|
401
|
+
}
|
|
402
|
+
function isValidTsIgnorePresent(comment) {
|
|
403
|
+
const line = getLastCommentLine(comment);
|
|
404
|
+
return isLineComment(comment) ? tsIgnoreRegExpSingleLine.test(line) : tsIgnoreRegExpMultiLine.test(line);
|
|
405
|
+
}
|
|
406
|
+
return { Program() {
|
|
407
|
+
const comments = context.sourceCode.getAllComments();
|
|
408
|
+
for (const comment of comments) if (isValidTsIgnorePresent(comment)) {
|
|
409
|
+
const lineCommentRuleFixer = (fixer) => fixer.replaceText(comment, `//${comment.value.replace("@ts-ignore", "@ts-expect-error")}`);
|
|
410
|
+
const blockCommentRuleFixer = (fixer) => fixer.replaceText(comment, `/*${comment.value.replace("@ts-ignore", "@ts-expect-error")}*/`);
|
|
411
|
+
context.report({
|
|
412
|
+
node: comment,
|
|
413
|
+
messageId: "preferExpectErrorComment",
|
|
414
|
+
fix: isLineComment(comment) ? lineCommentRuleFixer : blockCommentRuleFixer
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
} };
|
|
418
|
+
}
|
|
419
|
+
});
|
|
420
|
+
|
|
386
421
|
//#endregion
|
|
387
422
|
//#region src/rules/require-async-with-await.ts
|
|
388
423
|
const RULE_NAME$1 = "require-async-with-await";
|
|
@@ -501,6 +536,7 @@ var src_default = { rules: {
|
|
|
501
536
|
"no-useless-template-string": no_useless_template_string_default,
|
|
502
537
|
"no-import-promises-as": no_import_promises_as_default,
|
|
503
538
|
"pad-after-last-import": pad_after_last_import_default,
|
|
539
|
+
"prefer-ts-expect-error": prefer_ts_expect_error_default,
|
|
504
540
|
"require-async-with-await": require_async_with_await_default,
|
|
505
541
|
"vue-root-element-sort-attributes": vue_root_element_sort_attributes_default
|
|
506
542
|
} };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@so1ve/eslint-plugin",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.10.0",
|
|
4
4
|
"author": "Ray <i@mk1.io> (https://github.com/so1ve/)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
@@ -33,8 +33,8 @@
|
|
|
33
33
|
"access": "public"
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
|
-
"@typescript-eslint/types": "^8.
|
|
37
|
-
"@typescript-eslint/utils": "^8.
|
|
36
|
+
"@typescript-eslint/types": "^8.46.1",
|
|
37
|
+
"@typescript-eslint/utils": "^8.46.1"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"vue-eslint-parser": "^10.2.0"
|