@virmator/lint 14.26.0 → 14.27.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.
Files changed (42) hide show
  1. package/configs/eslint.config.base.ts +36 -0
  2. package/dist/rules/error-name-as-class-field.lint.d.ts +3 -0
  3. package/dist/rules/error-name-as-class-field.lint.js +165 -0
  4. package/dist/rules/no-raw-date.lint.d.ts +3 -0
  5. package/dist/rules/no-raw-date.lint.js +42 -0
  6. package/dist/rules/no-readonly-primitive.lint.d.ts +3 -0
  7. package/dist/rules/no-readonly-primitive.lint.js +68 -0
  8. package/dist/rules/no-relative-import-outside-package.lint.js +5 -2
  9. package/dist/rules/no-should-in-test-description.lint.d.ts +3 -0
  10. package/dist/rules/no-should-in-test-description.lint.js +84 -0
  11. package/dist/rules/no-underscore-variable.lint.d.ts +3 -0
  12. package/dist/rules/no-underscore-variable.lint.js +60 -0
  13. package/dist/rules/prefer-arrow-object-block-body.lint.d.ts +3 -0
  14. package/dist/rules/prefer-arrow-object-block-body.lint.js +51 -0
  15. package/dist/rules/prefer-ensure-error.lint.d.ts +3 -0
  16. package/dist/rules/prefer-ensure-error.lint.js +74 -0
  17. package/dist/rules/prefer-if-else-chain.lint.js +5 -0
  18. package/dist/rules/prefer-map-enum-to-object.lint.d.ts +3 -0
  19. package/dist/rules/prefer-map-enum-to-object.lint.js +68 -0
  20. package/dist/rules/prefer-params-object.lint.d.ts +3 -0
  21. package/dist/rules/prefer-params-object.lint.js +117 -0
  22. package/dist/rules/prefer-protected-over-private.lint.d.ts +3 -0
  23. package/dist/rules/prefer-protected-over-private.lint.js +53 -0
  24. package/dist/rules/prefer-remove-duplicates.lint.d.ts +3 -0
  25. package/dist/rules/prefer-remove-duplicates.lint.js +142 -0
  26. package/dist/rules/prefer-to-sorted.lint.d.ts +3 -0
  27. package/dist/rules/prefer-to-sorted.lint.js +58 -0
  28. package/package.json +2 -2
  29. package/src/rules/error-name-as-class-field.lint.ts +211 -0
  30. package/src/rules/no-raw-date.lint.ts +52 -0
  31. package/src/rules/no-readonly-primitive.lint.ts +85 -0
  32. package/src/rules/no-relative-import-outside-package.lint.ts +7 -2
  33. package/src/rules/no-should-in-test-description.lint.ts +106 -0
  34. package/src/rules/no-underscore-variable.lint.ts +73 -0
  35. package/src/rules/prefer-arrow-object-block-body.lint.ts +66 -0
  36. package/src/rules/prefer-ensure-error.lint.ts +91 -0
  37. package/src/rules/prefer-if-else-chain.lint.ts +5 -0
  38. package/src/rules/prefer-map-enum-to-object.lint.ts +86 -0
  39. package/src/rules/prefer-params-object.lint.ts +190 -0
  40. package/src/rules/prefer-protected-over-private.lint.ts +71 -0
  41. package/src/rules/prefer-remove-duplicates.lint.ts +225 -0
  42. package/src/rules/prefer-to-sorted.lint.ts +79 -0
@@ -0,0 +1,79 @@
1
+ import {type Rule} from 'eslint';
2
+ import type {CallExpression} from 'estree';
3
+
4
+ const rule: Rule.RuleModule = {
5
+ meta: {
6
+ type: 'suggestion',
7
+ fixable: 'code',
8
+ messages: {
9
+ preferToSorted:
10
+ 'Use `.toSorted(...)` instead of `[...array].sort(...)` for a non-mutating sort.',
11
+ },
12
+ schema: [],
13
+ },
14
+ create(context) {
15
+ return {
16
+ CallExpression(node: CallExpression & Rule.NodeParentExtension) {
17
+ const callee = node.callee;
18
+ if (
19
+ callee.type !== 'MemberExpression' ||
20
+ callee.computed ||
21
+ callee.property.type !== 'Identifier' ||
22
+ callee.property.name !== 'sort'
23
+ ) {
24
+ return;
25
+ }
26
+
27
+ const object = callee.object;
28
+ if (
29
+ object.type !== 'ArrayExpression' ||
30
+ object.elements.length !== 1 ||
31
+ object.elements[0]?.type !== 'SpreadElement'
32
+ ) {
33
+ return;
34
+ }
35
+
36
+ const spreadArgument = object.elements[0].argument;
37
+
38
+ context.report({
39
+ node,
40
+ messageId: 'preferToSorted',
41
+ fix(fixer) {
42
+ const argumentSourceTexts = node.arguments.map((argument) =>
43
+ context.sourceCode.getText(argument as unknown as Rule.Node),
44
+ );
45
+ const sourceText = context.sourceCode.getText(
46
+ spreadArgument as unknown as Rule.Node,
47
+ );
48
+
49
+ /**
50
+ * Member access binds tighter than most expression forms, so a receiver
51
+ * like `await fn()` or `a ? b : c` must be wrapped in parentheses;
52
+ * otherwise `.toSorted(...)` would attach to the wrong sub-expression.
53
+ * Identifiers, member/call/array expressions are already tight enough to
54
+ * leave bare.
55
+ */
56
+ const tightReceiverTypes = [
57
+ 'Identifier',
58
+ 'MemberExpression',
59
+ 'CallExpression',
60
+ 'NewExpression',
61
+ 'ArrayExpression',
62
+ 'ThisExpression',
63
+ ];
64
+ const receiverText = tightReceiverTypes.includes(spreadArgument.type)
65
+ ? sourceText
66
+ : `(${sourceText})`;
67
+
68
+ return fixer.replaceText(
69
+ node,
70
+ `${receiverText}.toSorted(${argumentSourceTexts.join(', ')})`,
71
+ );
72
+ },
73
+ });
74
+ },
75
+ };
76
+ },
77
+ };
78
+
79
+ export default rule;