@so1ve/eslint-plugin 3.9.1 → 3.11.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 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);
@@ -183,7 +183,7 @@ var import_dedupe_default = createEslintRule({
183
183
  const start = n.range[0];
184
184
  let end = n.range[1];
185
185
  const nextToken = context.sourceCode.getTokenAfter(n);
186
- if (nextToken && nextToken.value === ",") end = nextToken.range[1];
186
+ if (nextToken?.value === ",") end = nextToken.range[1];
187
187
  return fixer.removeRange([start, end]);
188
188
  }
189
189
  });
@@ -246,35 +246,32 @@ var no_inline_type_import_default = createEslintRule({
246
246
  messages: { noInlineTypeImport: "Expected no inline type import." }
247
247
  },
248
248
  defaultOptions: [],
249
- create: (context) => {
250
- const sourceCode = context.sourceCode;
251
- return { ImportDeclaration: (node) => {
252
- const { specifiers } = node;
253
- const typeSpecifiers = specifiers.filter((s) => s.type === AST_NODE_TYPES.ImportSpecifier && s.importKind === "type");
254
- const valueSpecifiers = specifiers.filter((s) => s.type === AST_NODE_TYPES.ImportSpecifier && s.importKind === "value");
255
- const defaultImportSpecifier = specifiers.find((s) => s.type === AST_NODE_TYPES.ImportDefaultSpecifier);
256
- if (typeSpecifiers.length > 0 && valueSpecifiers.length > 0) context.report({
257
- node,
258
- messageId: "noInlineTypeImport",
259
- fix(fixer) {
260
- const typeSpecifiersText = typeSpecifiers.map((s) => sourceCode.getText(s).replace("type ", "")).join(", ");
261
- const valueSpecifiersText = valueSpecifiers.map((s) => sourceCode.getText(s)).join(", ");
262
- const defaultImportSpecifierText = sourceCode.getText(defaultImportSpecifier);
263
- const defaultAndValueSpecifiersText = defaultImportSpecifier ? `import ${defaultImportSpecifierText}, { ${valueSpecifiersText} } from "${node.source.value}";` : `import { ${valueSpecifiersText} } from "${node.source.value}";`;
264
- const texts = [`import type { ${typeSpecifiersText} } from "${node.source.value}";`, defaultAndValueSpecifiersText];
265
- return fixer.replaceText(node, texts.join("\n"));
266
- }
267
- });
268
- else if (typeSpecifiers.length > 0) context.report({
269
- node,
270
- messageId: "noInlineTypeImport",
271
- fix(fixer) {
272
- const typeSpecifiersText = typeSpecifiers.map((s) => sourceCode.getText(s).replace("type ", "")).join(", ");
273
- return fixer.replaceText(node, `import type { ${typeSpecifiersText} } from "${node.source.value}";`);
274
- }
275
- });
276
- } };
277
- }
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
+ } })
278
275
  });
279
276
 
280
277
  //#endregion
@@ -380,6 +377,47 @@ var pad_after_last_import_default = createEslintRule({
380
377
  }
381
378
  });
382
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
+
383
421
  //#endregion
384
422
  //#region src/rules/require-async-with-await.ts
385
423
  const RULE_NAME$1 = "require-async-with-await";
@@ -498,6 +536,7 @@ var src_default = { rules: {
498
536
  "no-useless-template-string": no_useless_template_string_default,
499
537
  "no-import-promises-as": no_import_promises_as_default,
500
538
  "pad-after-last-import": pad_after_last_import_default,
539
+ "prefer-ts-expect-error": prefer_ts_expect_error_default,
501
540
  "require-async-with-await": require_async_with_await_default,
502
541
  "vue-root-element-sort-attributes": vue_root_element_sort_attributes_default
503
542
  } };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@so1ve/eslint-plugin",
3
- "version": "3.9.1",
3
+ "version": "3.11.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.44.0",
37
- "@typescript-eslint/utils": "^8.44.0"
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"