eslint-plugin-complete 1.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.
Files changed (171) hide show
  1. package/LICENSE +9 -0
  2. package/README.md +114 -0
  3. package/dist/comments.d.ts +22 -0
  4. package/dist/comments.d.ts.map +1 -0
  5. package/dist/comments.js +66 -0
  6. package/dist/completeCommon.d.ts +25 -0
  7. package/dist/completeCommon.d.ts.map +1 -0
  8. package/dist/completeCommon.js +53 -0
  9. package/dist/completeSentence.d.ts +9 -0
  10. package/dist/completeSentence.d.ts.map +1 -0
  11. package/dist/completeSentence.js +267 -0
  12. package/dist/configs/recommended.d.ts +3 -0
  13. package/dist/configs/recommended.d.ts.map +1 -0
  14. package/dist/configs/recommended.js +63 -0
  15. package/dist/configs.d.ts +4 -0
  16. package/dist/configs.d.ts.map +1 -0
  17. package/dist/configs.js +4 -0
  18. package/dist/constants.d.ts +8 -0
  19. package/dist/constants.d.ts.map +1 -0
  20. package/dist/constants.js +73 -0
  21. package/dist/format.d.ts +18 -0
  22. package/dist/format.d.ts.map +1 -0
  23. package/dist/format.js +246 -0
  24. package/dist/index.d.ts +60 -0
  25. package/dist/index.d.ts.map +1 -0
  26. package/dist/index.js +49 -0
  27. package/dist/interfaces/MyPluginDocs.d.ts +6 -0
  28. package/dist/interfaces/MyPluginDocs.d.ts.map +1 -0
  29. package/dist/interfaces/MyPluginDocs.js +1 -0
  30. package/dist/jsdoc.d.ts +4 -0
  31. package/dist/jsdoc.d.ts.map +1 -0
  32. package/dist/jsdoc.js +24 -0
  33. package/dist/leadingLineComments.d.ts +32 -0
  34. package/dist/leadingLineComments.d.ts.map +1 -0
  35. package/dist/leadingLineComments.js +77 -0
  36. package/dist/list.d.ts +49 -0
  37. package/dist/list.d.ts.map +1 -0
  38. package/dist/list.js +140 -0
  39. package/dist/rules/complete-sentences-jsdoc.d.ts +4 -0
  40. package/dist/rules/complete-sentences-jsdoc.d.ts.map +1 -0
  41. package/dist/rules/complete-sentences-jsdoc.js +48 -0
  42. package/dist/rules/complete-sentences-line-comments.d.ts +4 -0
  43. package/dist/rules/complete-sentences-line-comments.d.ts.map +1 -0
  44. package/dist/rules/complete-sentences-line-comments.js +88 -0
  45. package/dist/rules/consistent-enum-values.d.ts +2 -0
  46. package/dist/rules/consistent-enum-values.d.ts.map +1 -0
  47. package/dist/rules/consistent-enum-values.js +46 -0
  48. package/dist/rules/consistent-named-tuples.d.ts +2 -0
  49. package/dist/rules/consistent-named-tuples.d.ts.map +1 -0
  50. package/dist/rules/consistent-named-tuples.js +34 -0
  51. package/dist/rules/eqeqeq-fix.d.ts +2 -0
  52. package/dist/rules/eqeqeq-fix.d.ts.map +1 -0
  53. package/dist/rules/eqeqeq-fix.js +173 -0
  54. package/dist/rules/format-jsdoc-comments.d.ts +8 -0
  55. package/dist/rules/format-jsdoc-comments.d.ts.map +1 -0
  56. package/dist/rules/format-jsdoc-comments.js +117 -0
  57. package/dist/rules/format-line-comments.d.ts +8 -0
  58. package/dist/rules/format-line-comments.d.ts.map +1 -0
  59. package/dist/rules/format-line-comments.js +118 -0
  60. package/dist/rules/jsdoc-code-block-language.d.ts +2 -0
  61. package/dist/rules/jsdoc-code-block-language.d.ts.map +1 -0
  62. package/dist/rules/jsdoc-code-block-language.js +52 -0
  63. package/dist/rules/newline-between-switch-case.d.ts +4 -0
  64. package/dist/rules/newline-between-switch-case.d.ts.map +1 -0
  65. package/dist/rules/newline-between-switch-case.js +63 -0
  66. package/dist/rules/no-confusing-set-methods.d.ts +5 -0
  67. package/dist/rules/no-confusing-set-methods.d.ts.map +1 -0
  68. package/dist/rules/no-confusing-set-methods.js +51 -0
  69. package/dist/rules/no-empty-jsdoc.d.ts +2 -0
  70. package/dist/rules/no-empty-jsdoc.d.ts.map +1 -0
  71. package/dist/rules/no-empty-jsdoc.js +45 -0
  72. package/dist/rules/no-empty-line-comments.d.ts +2 -0
  73. package/dist/rules/no-empty-line-comments.d.ts.map +1 -0
  74. package/dist/rules/no-empty-line-comments.js +40 -0
  75. package/dist/rules/no-explicit-array-loops.d.ts +5 -0
  76. package/dist/rules/no-explicit-array-loops.d.ts.map +1 -0
  77. package/dist/rules/no-explicit-array-loops.js +114 -0
  78. package/dist/rules/no-explicit-map-set-loops.d.ts +5 -0
  79. package/dist/rules/no-explicit-map-set-loops.d.ts.map +1 -0
  80. package/dist/rules/no-explicit-map-set-loops.js +74 -0
  81. package/dist/rules/no-for-in.d.ts +2 -0
  82. package/dist/rules/no-for-in.d.ts.map +1 -0
  83. package/dist/rules/no-for-in.js +27 -0
  84. package/dist/rules/no-let-any.d.ts +3 -0
  85. package/dist/rules/no-let-any.d.ts.map +1 -0
  86. package/dist/rules/no-let-any.js +45 -0
  87. package/dist/rules/no-mutable-return.d.ts +5 -0
  88. package/dist/rules/no-mutable-return.d.ts.map +1 -0
  89. package/dist/rules/no-mutable-return.js +63 -0
  90. package/dist/rules/no-number-enums.d.ts +2 -0
  91. package/dist/rules/no-number-enums.d.ts.map +1 -0
  92. package/dist/rules/no-number-enums.js +27 -0
  93. package/dist/rules/no-object-any.d.ts +3 -0
  94. package/dist/rules/no-object-any.d.ts.map +1 -0
  95. package/dist/rules/no-object-any.js +51 -0
  96. package/dist/rules/no-object-methods-with-map-set.d.ts +5 -0
  97. package/dist/rules/no-object-methods-with-map-set.d.ts.map +1 -0
  98. package/dist/rules/no-object-methods-with-map-set.js +84 -0
  99. package/dist/rules/no-string-length-0.d.ts +3 -0
  100. package/dist/rules/no-string-length-0.d.ts.map +1 -0
  101. package/dist/rules/no-string-length-0.js +52 -0
  102. package/dist/rules/no-template-curly-in-string-fix.d.ts +6 -0
  103. package/dist/rules/no-template-curly-in-string-fix.d.ts.map +1 -0
  104. package/dist/rules/no-template-curly-in-string-fix.js +39 -0
  105. package/dist/rules/no-undefined-return-type.d.ts +3 -0
  106. package/dist/rules/no-undefined-return-type.d.ts.map +1 -0
  107. package/dist/rules/no-undefined-return-type.js +40 -0
  108. package/dist/rules/no-unnecessary-assignment.d.ts +5 -0
  109. package/dist/rules/no-unnecessary-assignment.d.ts.map +1 -0
  110. package/dist/rules/no-unnecessary-assignment.js +255 -0
  111. package/dist/rules/no-unsafe-plusplus.d.ts +2 -0
  112. package/dist/rules/no-unsafe-plusplus.d.ts.map +1 -0
  113. package/dist/rules/no-unsafe-plusplus.js +34 -0
  114. package/dist/rules/no-useless-return.d.ts +2 -0
  115. package/dist/rules/no-useless-return.d.ts.map +1 -0
  116. package/dist/rules/no-useless-return.js +347 -0
  117. package/dist/rules/no-void-return-type.d.ts +2 -0
  118. package/dist/rules/no-void-return-type.d.ts.map +1 -0
  119. package/dist/rules/no-void-return-type.js +49 -0
  120. package/dist/rules/prefer-const.d.ts +2 -0
  121. package/dist/rules/prefer-const.d.ts.map +1 -0
  122. package/dist/rules/prefer-const.js +426 -0
  123. package/dist/rules/prefer-plusplus.d.ts +5 -0
  124. package/dist/rules/prefer-plusplus.d.ts.map +1 -0
  125. package/dist/rules/prefer-plusplus.js +49 -0
  126. package/dist/rules/prefer-postfix-plusplus.d.ts +2 -0
  127. package/dist/rules/prefer-postfix-plusplus.d.ts.map +1 -0
  128. package/dist/rules/prefer-postfix-plusplus.js +32 -0
  129. package/dist/rules/prefer-readonly-parameter-types.d.ts +13 -0
  130. package/dist/rules/prefer-readonly-parameter-types.d.ts.map +1 -0
  131. package/dist/rules/prefer-readonly-parameter-types.js +140 -0
  132. package/dist/rules/require-break.d.ts +5 -0
  133. package/dist/rules/require-break.d.ts.map +1 -0
  134. package/dist/rules/require-break.js +76 -0
  135. package/dist/rules/require-capital-const-assertions.d.ts +4 -0
  136. package/dist/rules/require-capital-const-assertions.d.ts.map +1 -0
  137. package/dist/rules/require-capital-const-assertions.js +112 -0
  138. package/dist/rules/require-capital-read-only.d.ts +5 -0
  139. package/dist/rules/require-capital-read-only.d.ts.map +1 -0
  140. package/dist/rules/require-capital-read-only.js +111 -0
  141. package/dist/rules/require-unannotated-const-assertions.d.ts +2 -0
  142. package/dist/rules/require-unannotated-const-assertions.d.ts.map +1 -0
  143. package/dist/rules/require-unannotated-const-assertions.js +27 -0
  144. package/dist/rules/require-variadic-function-argument.d.ts +5 -0
  145. package/dist/rules/require-variadic-function-argument.d.ts.map +1 -0
  146. package/dist/rules/require-variadic-function-argument.js +86 -0
  147. package/dist/rules/strict-array-methods.d.ts +3 -0
  148. package/dist/rules/strict-array-methods.d.ts.map +1 -0
  149. package/dist/rules/strict-array-methods.js +83 -0
  150. package/dist/rules/strict-enums.d.ts +5 -0
  151. package/dist/rules/strict-enums.d.ts.map +1 -0
  152. package/dist/rules/strict-enums.js +445 -0
  153. package/dist/rules/strict-undefined-functions.d.ts +5 -0
  154. package/dist/rules/strict-undefined-functions.d.ts.map +1 -0
  155. package/dist/rules/strict-undefined-functions.js +49 -0
  156. package/dist/rules/strict-void-functions.d.ts +2 -0
  157. package/dist/rules/strict-void-functions.d.ts.map +1 -0
  158. package/dist/rules/strict-void-functions.js +43 -0
  159. package/dist/rules.d.ts +49 -0
  160. package/dist/rules.d.ts.map +1 -0
  161. package/dist/rules.js +85 -0
  162. package/dist/template.d.ts +2 -0
  163. package/dist/template.d.ts.map +1 -0
  164. package/dist/template.js +29 -0
  165. package/dist/typeUtils.d.ts +28 -0
  166. package/dist/typeUtils.d.ts.map +1 -0
  167. package/dist/typeUtils.js +76 -0
  168. package/dist/utils.d.ts +13 -0
  169. package/dist/utils.d.ts.map +1 -0
  170. package/dist/utils.js +54 -0
  171. package/package.json +55 -0
@@ -0,0 +1,45 @@
1
+ import { getJSDocComments } from "../jsdoc.js";
2
+ import { createRule } from "../utils.js";
3
+ export const noEmptyJSDoc = createRule({
4
+ name: "no-empty-jsdoc",
5
+ meta: {
6
+ type: "problem",
7
+ docs: {
8
+ description: "Disallows empty JSDoc comments",
9
+ recommended: true,
10
+ requiresTypeChecking: false,
11
+ },
12
+ schema: [],
13
+ messages: {
14
+ isEmpty: "Empty JSDoc comments are not allowed.",
15
+ },
16
+ fixable: "code",
17
+ },
18
+ defaultOptions: [],
19
+ /**
20
+ * We need to write the rule in such a way that it operates on the entire source code instead of
21
+ * individual AST nodes:
22
+ * https://stackoverflow.com/questions/47429792/is-it-possible-to-get-comments-as-nodes-in-the-ast-using-the-typescript-compiler
23
+ */
24
+ create(context) {
25
+ const comments = context.sourceCode.getAllComments();
26
+ // We only look at `/**` style comments on their own line.
27
+ const jsDocComments = getJSDocComments(comments);
28
+ for (const comment of jsDocComments) {
29
+ const text = comment.value.trim();
30
+ const textWithoutAsterisks = text.replaceAll("*", "");
31
+ const commentBody = textWithoutAsterisks.trim();
32
+ if (commentBody === "") {
33
+ context.report({
34
+ loc: {
35
+ start: comment.loc.start,
36
+ end: comment.loc.end,
37
+ },
38
+ messageId: "isEmpty",
39
+ fix: (fixer) => fixer.replaceTextRange(comment.range, ""),
40
+ });
41
+ }
42
+ }
43
+ return {};
44
+ },
45
+ });
@@ -0,0 +1,2 @@
1
+ export declare const noEmptyLineComments: import("@typescript-eslint/utils/ts-eslint").RuleModule<"isEmpty", [], import("../interfaces/MyPluginDocs.js").MyPluginDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
2
+ //# sourceMappingURL=no-empty-line-comments.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"no-empty-line-comments.d.ts","sourceRoot":"","sources":["../../src/rules/no-empty-line-comments.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,mBAAmB,yLA2C9B,CAAC"}
@@ -0,0 +1,40 @@
1
+ import { TSESTree } from "@typescript-eslint/utils";
2
+ import { createRule } from "../utils.js";
3
+ export const noEmptyLineComments = createRule({
4
+ name: "no-empty-line-comments",
5
+ meta: {
6
+ type: "problem",
7
+ docs: {
8
+ description: "Disallows empty line comments",
9
+ recommended: true,
10
+ requiresTypeChecking: false,
11
+ },
12
+ schema: [],
13
+ messages: {
14
+ isEmpty: "Empty line comments comments are not allowed.",
15
+ },
16
+ fixable: "code",
17
+ },
18
+ defaultOptions: [],
19
+ /**
20
+ * We need to write the rule in such a way that it operates on the entire source code instead of
21
+ * individual AST nodes:
22
+ * https://stackoverflow.com/questions/47429792/is-it-possible-to-get-comments-as-nodes-in-the-ast-using-the-typescript-compiler
23
+ */
24
+ create(context) {
25
+ const comments = context.sourceCode.getAllComments();
26
+ const emptyLeadingLineComments = comments.filter((comment) => comment.type === TSESTree.AST_TOKEN_TYPES.Line && // i.e. a "//" comment
27
+ comment.value.trim() === "");
28
+ for (const comment of emptyLeadingLineComments) {
29
+ context.report({
30
+ loc: {
31
+ start: comment.loc.start,
32
+ end: comment.loc.end,
33
+ },
34
+ messageId: "isEmpty",
35
+ fix: (fixer) => fixer.replaceTextRange(comment.range, ""),
36
+ });
37
+ }
38
+ return {};
39
+ },
40
+ });
@@ -0,0 +1,5 @@
1
+ import { ESLintUtils } from "@typescript-eslint/utils";
2
+ export type Options = [];
3
+ export type MessageIds = "noExplicitArray";
4
+ export declare const noExplicitArrayLoops: ESLintUtils.RuleModule<"noExplicitArray", [], import("../interfaces/MyPluginDocs.js").MyPluginDocs, ESLintUtils.RuleListener>;
5
+ //# sourceMappingURL=no-explicit-array-loops.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"no-explicit-array-loops.d.ts","sourceRoot":"","sources":["../../src/rules/no-explicit-array-loops.ts"],"names":[],"mappings":"AAEA,OAAO,EAAkB,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAIvE,MAAM,MAAM,OAAO,GAAG,EAAE,CAAC;AACzB,MAAM,MAAM,UAAU,GAAG,iBAAiB,CAAC;AAE3C,eAAO,MAAM,oBAAoB,+HAyJ/B,CAAC"}
@@ -0,0 +1,114 @@
1
+ import { getConstrainedTypeAtLocation } from "@typescript-eslint/type-utils";
2
+ import { AST_NODE_TYPES, ESLintUtils } from "@typescript-eslint/utils";
3
+ import { isTypeArrayTupleTypeOrUnionOfArrayTupleTypes } from "../typeUtils.js";
4
+ import { createRule } from "../utils.js";
5
+ export const noExplicitArrayLoops = createRule({
6
+ name: "no-explicit-array-loops",
7
+ meta: {
8
+ type: "problem",
9
+ docs: {
10
+ description: "Disallows explicit iteration for arrays",
11
+ recommended: true,
12
+ requiresTypeChecking: true,
13
+ },
14
+ schema: [],
15
+ messages: {
16
+ noExplicitArray: 'Explicit iteration over arrays is disallowed. (Get rid of the "Object.values()".)',
17
+ },
18
+ fixable: "code",
19
+ },
20
+ defaultOptions: [],
21
+ create(context) {
22
+ const parserServices = ESLintUtils.getParserServices(context);
23
+ const checker = parserServices.program.getTypeChecker();
24
+ /** Checks for `array.values()`. */
25
+ function checkArrayValuesForm(node) {
26
+ const callExpression = node.right;
27
+ if (callExpression.type !== AST_NODE_TYPES.CallExpression) {
28
+ return;
29
+ }
30
+ const memberExpression = callExpression.callee;
31
+ if (memberExpression.type !== AST_NODE_TYPES.MemberExpression) {
32
+ return;
33
+ }
34
+ if (memberExpression.object.type !== AST_NODE_TYPES.Identifier) {
35
+ return;
36
+ }
37
+ const potentialArrayType = getConstrainedTypeAtLocation(parserServices, memberExpression.object);
38
+ if (!isTypeArrayTupleTypeOrUnionOfArrayTupleTypes(potentialArrayType, checker)) {
39
+ return;
40
+ }
41
+ const methodIdentifier = memberExpression.property;
42
+ if (methodIdentifier.type !== AST_NODE_TYPES.Identifier) {
43
+ return;
44
+ }
45
+ const methodName = methodIdentifier.name;
46
+ if (methodName !== "values") {
47
+ return;
48
+ }
49
+ const callExpressionEnd = callExpression.range[1];
50
+ const replacementStart = callExpressionEnd - ".values()".length;
51
+ const replacementEnd = callExpressionEnd;
52
+ context.report({
53
+ loc: methodIdentifier.loc,
54
+ messageId: "noExplicitArray",
55
+ fix: (fixer) => fixer.replaceTextRange([replacementStart, replacementEnd], ""),
56
+ });
57
+ }
58
+ /** Checks for `Object.values(array)`. */
59
+ function checkObjectValuesForm(node) {
60
+ const callExpression = node.right;
61
+ if (callExpression.type !== AST_NODE_TYPES.CallExpression) {
62
+ return;
63
+ }
64
+ const memberExpression = callExpression.callee;
65
+ if (memberExpression.type !== AST_NODE_TYPES.MemberExpression) {
66
+ return;
67
+ }
68
+ if (memberExpression.object.type !== AST_NODE_TYPES.Identifier) {
69
+ return;
70
+ }
71
+ if (memberExpression.object.name !== "Object") {
72
+ return;
73
+ }
74
+ const methodIdentifier = memberExpression.property;
75
+ if (methodIdentifier.type !== AST_NODE_TYPES.Identifier) {
76
+ return;
77
+ }
78
+ const methodName = methodIdentifier.name;
79
+ if (methodName !== "values") {
80
+ return;
81
+ }
82
+ const firstArgument = callExpression.arguments[0];
83
+ if (firstArgument === undefined) {
84
+ return;
85
+ }
86
+ if (firstArgument.type !== AST_NODE_TYPES.Identifier) {
87
+ return;
88
+ }
89
+ const potentialArrayType = getConstrainedTypeAtLocation(parserServices, firstArgument);
90
+ if (!isTypeArrayTupleTypeOrUnionOfArrayTupleTypes(potentialArrayType, checker)) {
91
+ return;
92
+ }
93
+ const [callExpressionStart, callExpressionEnd] = callExpression.range;
94
+ const firstReplacementStart = callExpressionStart;
95
+ const firstReplacementEnd = callExpressionStart + "Object.values(".length;
96
+ const secondReplacementStart = callExpressionEnd - ")".length;
97
+ const secondReplacementEnd = callExpressionEnd;
98
+ context.report({
99
+ loc: methodIdentifier.loc,
100
+ messageId: "noExplicitArray",
101
+ fix: (fixer) => [
102
+ fixer.replaceTextRange([firstReplacementStart, firstReplacementEnd], ""),
103
+ fixer.replaceTextRange([secondReplacementStart, secondReplacementEnd], ""),
104
+ ],
105
+ });
106
+ }
107
+ return {
108
+ ForOfStatement(node) {
109
+ checkObjectValuesForm(node);
110
+ checkArrayValuesForm(node);
111
+ },
112
+ };
113
+ },
114
+ });
@@ -0,0 +1,5 @@
1
+ import { ESLintUtils } from "@typescript-eslint/utils";
2
+ type MessageIds = "noExplicitMap" | "noExplicitSet";
3
+ export declare const noExplicitMapSetLoops: ESLintUtils.RuleModule<MessageIds, [], import("../interfaces/MyPluginDocs.js").MyPluginDocs, ESLintUtils.RuleListener>;
4
+ export {};
5
+ //# sourceMappingURL=no-explicit-map-set-loops.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"no-explicit-map-set-loops.d.ts","sourceRoot":"","sources":["../../src/rules/no-explicit-map-set-loops.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAKvE,KAAK,UAAU,GAAG,eAAe,GAAG,eAAe,CAAC;AAEpD,eAAO,MAAM,qBAAqB,wHA6EhC,CAAC"}
@@ -0,0 +1,74 @@
1
+ import { AST_NODE_TYPES, ESLintUtils } from "@typescript-eslint/utils";
2
+ import { getTypeName } from "../typeUtils.js";
3
+ import { createRule } from "../utils.js";
4
+ export const noExplicitMapSetLoops = createRule({
5
+ name: "no-explicit-map-set-loops",
6
+ meta: {
7
+ type: "problem",
8
+ docs: {
9
+ description: "Disallows explicit iteration for maps and sets",
10
+ recommended: true,
11
+ requiresTypeChecking: true,
12
+ },
13
+ schema: [],
14
+ messages: {
15
+ noExplicitMap: 'Explicit iteration over maps is disallowed. (Get rid of the ".entries()".)',
16
+ noExplicitSet: 'Explicit iteration over sets is disallowed. (Get rid of the ".values()".)',
17
+ },
18
+ fixable: "code",
19
+ },
20
+ defaultOptions: [],
21
+ create(context) {
22
+ const parserServices = ESLintUtils.getParserServices(context);
23
+ const checker = parserServices.program.getTypeChecker();
24
+ return {
25
+ ForOfStatement(node) {
26
+ const callExpression = node.right;
27
+ if (callExpression.type !== AST_NODE_TYPES.CallExpression) {
28
+ return;
29
+ }
30
+ const memberExpression = callExpression.callee;
31
+ if (memberExpression.type !== AST_NODE_TYPES.MemberExpression) {
32
+ return;
33
+ }
34
+ const potentialMapOrSet = memberExpression.object;
35
+ const potentialMapOrSetTSNode = parserServices.esTreeNodeToTSNodeMap.get(potentialMapOrSet);
36
+ const potentialMapOrSetType = checker.getTypeAtLocation(potentialMapOrSetTSNode);
37
+ const potentialMapOrSetName = getTypeName(potentialMapOrSetType);
38
+ if (potentialMapOrSetName === undefined) {
39
+ return;
40
+ }
41
+ const typeTuple = getTypeTuple(potentialMapOrSetName);
42
+ if (typeTuple === undefined) {
43
+ return;
44
+ }
45
+ const [messageId, expectedMethodName] = typeTuple;
46
+ const methodIdentifier = memberExpression.property;
47
+ if (methodIdentifier.type !== AST_NODE_TYPES.Identifier) {
48
+ return;
49
+ }
50
+ const methodName = methodIdentifier.name;
51
+ if (methodName !== expectedMethodName) {
52
+ return;
53
+ }
54
+ const callExpressionEnd = callExpression.range[1];
55
+ const replacementStart = callExpressionEnd - `.${expectedMethodName}()`.length;
56
+ const replacementEnd = callExpressionEnd;
57
+ context.report({
58
+ loc: methodIdentifier.loc,
59
+ messageId,
60
+ fix: (fixer) => fixer.replaceTextRange([replacementStart, replacementEnd], ""),
61
+ });
62
+ },
63
+ };
64
+ },
65
+ });
66
+ function getTypeTuple(typeName) {
67
+ if (typeName === "Map" || typeName === "ReadonlyMap") {
68
+ return ["noExplicitMap", "entries"];
69
+ }
70
+ if (typeName === "Set" || typeName === "ReadonlySet") {
71
+ return ["noExplicitSet", "values"];
72
+ }
73
+ return undefined;
74
+ }
@@ -0,0 +1,2 @@
1
+ export declare const noForIn: import("@typescript-eslint/utils/ts-eslint").RuleModule<"noForIn", [], import("../interfaces/MyPluginDocs.js").MyPluginDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
2
+ //# sourceMappingURL=no-for-in.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"no-for-in.d.ts","sourceRoot":"","sources":["../../src/rules/no-for-in.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,OAAO,yLA0BlB,CAAC"}
@@ -0,0 +1,27 @@
1
+ import { createRule } from "../utils.js";
2
+ export const noForIn = createRule({
3
+ name: "no-for-in",
4
+ meta: {
5
+ type: "problem",
6
+ docs: {
7
+ description: 'Disallows "for x in y" statements',
8
+ recommended: true,
9
+ requiresTypeChecking: false,
10
+ },
11
+ schema: [],
12
+ messages: {
13
+ noForIn: 'for..in loops iterate over the entire prototype chain, which is virtually never what you want. Use a "for of" loop instead.',
14
+ },
15
+ },
16
+ defaultOptions: [],
17
+ create(context) {
18
+ return {
19
+ ForInStatement(node) {
20
+ context.report({
21
+ node,
22
+ messageId: "noForIn",
23
+ });
24
+ },
25
+ };
26
+ },
27
+ });
@@ -0,0 +1,3 @@
1
+ import { ESLintUtils } from "@typescript-eslint/utils";
2
+ export declare const noLetAny: ESLintUtils.RuleModule<"noType", [], import("../interfaces/MyPluginDocs.js").MyPluginDocs, ESLintUtils.RuleListener>;
3
+ //# sourceMappingURL=no-let-any.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"no-let-any.d.ts","sourceRoot":"","sources":["../../src/rules/no-let-any.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAIvD,eAAO,MAAM,QAAQ,sHA8CnB,CAAC"}
@@ -0,0 +1,45 @@
1
+ import { ESLintUtils } from "@typescript-eslint/utils";
2
+ import { isAny } from "../typeUtils.js";
3
+ import { createRule } from "../utils.js";
4
+ export const noLetAny = createRule({
5
+ name: "no-let-any",
6
+ meta: {
7
+ type: "problem",
8
+ docs: {
9
+ description: "Disallows declaring variables with let that do not have a type",
10
+ recommended: true,
11
+ requiresTypeChecking: true,
12
+ },
13
+ schema: [],
14
+ messages: {
15
+ noType: "Variables must be declared with a type.",
16
+ },
17
+ },
18
+ defaultOptions: [],
19
+ create(context) {
20
+ const parserServices = ESLintUtils.getParserServices(context);
21
+ const checker = parserServices.program.getTypeChecker();
22
+ return {
23
+ VariableDeclaration(node) {
24
+ if (node.kind !== "let") {
25
+ return;
26
+ }
27
+ for (const declaration of node.declarations) {
28
+ const tsNode = parserServices.esTreeNodeToTSNodeMap.get(declaration);
29
+ /**
30
+ * We have to use `leftTSNode.name` instead of `leftTSNode` to avoid run-time errors
31
+ * because the `typeChecker.getTypeAtLocation` method expects a `ts.BindingName` instead
32
+ * of a `ts.VariableDeclaration`: https://github.com/microsoft/TypeScript/issues/48878
33
+ */
34
+ const type = checker.getTypeAtLocation(tsNode.name);
35
+ if (isAny(type)) {
36
+ context.report({
37
+ node,
38
+ messageId: "noType",
39
+ });
40
+ }
41
+ }
42
+ },
43
+ };
44
+ },
45
+ });
@@ -0,0 +1,5 @@
1
+ import { ESLintUtils } from "@typescript-eslint/utils";
2
+ type MessageIds = "mutableArray" | "mutableMap" | "mutableSet";
3
+ export declare const noMutableReturn: ESLintUtils.RuleModule<MessageIds, [], import("../interfaces/MyPluginDocs.js").MyPluginDocs, ESLintUtils.RuleListener>;
4
+ export {};
5
+ //# sourceMappingURL=no-mutable-return.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"no-mutable-return.d.ts","sourceRoot":"","sources":["../../src/rules/no-mutable-return.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAMvD,KAAK,UAAU,GAAG,cAAc,GAAG,YAAY,GAAG,YAAY,CAAC;AAE/D,eAAO,MAAM,eAAe,wHA6C1B,CAAC"}
@@ -0,0 +1,63 @@
1
+ import { ESLintUtils } from "@typescript-eslint/utils";
2
+ import { getTypeName, unionTypeParts } from "../typeUtils.js";
3
+ import { createRule } from "../utils.js";
4
+ export const noMutableReturn = createRule({
5
+ name: "no-mutable-return",
6
+ meta: {
7
+ type: "problem",
8
+ docs: {
9
+ description: "Disallows returning mutable arrays, maps, and sets from functions",
10
+ recommended: true,
11
+ requiresTypeChecking: true,
12
+ },
13
+ schema: [],
14
+ messages: {
15
+ mutableArray: "Arrays that are returned from functions must be read-only. (Use the `readonly` keyword prefix or the `Readonly` utility type.)",
16
+ mutableMap: "Maps that are returned from functions must be read-only. (Annotate the function using the `ReadonlyMap` type.)",
17
+ mutableSet: "Sets that are returned from functions must be read-only. (Annotate the function using the `ReadonlySet` type.)",
18
+ },
19
+ },
20
+ defaultOptions: [],
21
+ create(context) {
22
+ const parserServices = ESLintUtils.getParserServices(context);
23
+ const checker = parserServices.program.getTypeChecker();
24
+ return {
25
+ FunctionDeclaration(node) {
26
+ const tsNode = parserServices.esTreeNodeToTSNodeMap.get(node);
27
+ const type = checker.getTypeAtLocation(tsNode);
28
+ const signatures = type.getCallSignatures();
29
+ for (const signature of signatures) {
30
+ const returnType = signature.getReturnType();
31
+ for (const t of unionTypeParts(returnType)) {
32
+ const messageId = getErrorMessageId(t);
33
+ if (messageId !== undefined) {
34
+ context.report({
35
+ loc: node.loc,
36
+ messageId,
37
+ });
38
+ }
39
+ }
40
+ }
41
+ },
42
+ };
43
+ },
44
+ });
45
+ function getErrorMessageId(type) {
46
+ const typeName = getTypeName(type);
47
+ if (typeName === undefined) {
48
+ return undefined;
49
+ }
50
+ // This would be "ReadonlyMap" if it was the read-only version.
51
+ if (typeName === "Map") {
52
+ return "mutableMap";
53
+ }
54
+ // This would be "ReadonlySet" if it was the read-only version.
55
+ if (typeName === "Set") {
56
+ return "mutableSet";
57
+ }
58
+ // This would be "ReadonlyArray" if it was the read-only version.
59
+ if (typeName === "Array") {
60
+ return "mutableArray";
61
+ }
62
+ return undefined;
63
+ }
@@ -0,0 +1,2 @@
1
+ export declare const noNumberEnums: import("@typescript-eslint/utils/ts-eslint").RuleModule<"noNumberEnums", [], import("../interfaces/MyPluginDocs.js").MyPluginDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
2
+ //# sourceMappingURL=no-number-enums.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"no-number-enums.d.ts","sourceRoot":"","sources":["../../src/rules/no-number-enums.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,aAAa,+LA2BxB,CAAC"}
@@ -0,0 +1,27 @@
1
+ import { createRule } from "../utils.js";
2
+ export const noNumberEnums = createRule({
3
+ name: "no-number-enums",
4
+ meta: {
5
+ type: "problem",
6
+ docs: {
7
+ description: "Disallows number enums",
8
+ recommended: true,
9
+ requiresTypeChecking: false,
10
+ },
11
+ schema: [],
12
+ messages: {
13
+ noNumberEnums: "Number enums are disallowed; use a string enum instead because they are safer.",
14
+ },
15
+ },
16
+ defaultOptions: [],
17
+ create(context) {
18
+ return {
19
+ "TSEnumMember > :matches(Literal[raw>=0].initializer, UnaryExpression.initializer)": (node) => {
20
+ context.report({
21
+ node,
22
+ messageId: "noNumberEnums",
23
+ });
24
+ },
25
+ };
26
+ },
27
+ });
@@ -0,0 +1,3 @@
1
+ import { ESLintUtils } from "@typescript-eslint/utils";
2
+ export declare const noObjectAny: ESLintUtils.RuleModule<"noType", [], import("../interfaces/MyPluginDocs.js").MyPluginDocs, ESLintUtils.RuleListener>;
3
+ //# sourceMappingURL=no-object-any.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"no-object-any.d.ts","sourceRoot":"","sources":["../../src/rules/no-object-any.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAIvD,eAAO,MAAM,WAAW,sHAoDtB,CAAC"}
@@ -0,0 +1,51 @@
1
+ import { isTypeReferenceType } from "@typescript-eslint/type-utils";
2
+ import { ESLintUtils } from "@typescript-eslint/utils";
3
+ import { isAny } from "../typeUtils.js";
4
+ import { createRule, getOrdinalSuffix } from "../utils.js";
5
+ export const noObjectAny = createRule({
6
+ name: "no-object-any",
7
+ meta: {
8
+ type: "problem",
9
+ docs: {
10
+ description: "Disallows declaring objects and arrays that do not have a type",
11
+ recommended: true,
12
+ requiresTypeChecking: true,
13
+ },
14
+ schema: [],
15
+ messages: {
16
+ noType: "Objects/arrays must be declared with a type. (The {{ ordinal }} type parameter is `any`.)",
17
+ },
18
+ },
19
+ defaultOptions: [],
20
+ create(context) {
21
+ const parserServices = ESLintUtils.getParserServices(context);
22
+ const checker = parserServices.program.getTypeChecker();
23
+ return {
24
+ VariableDeclarator(node) {
25
+ // From: https://github.com/typescript-eslint/typescript-eslint/issues/781
26
+ const tsNode = parserServices.esTreeNodeToTSNodeMap.get(node);
27
+ /**
28
+ * We have to use `leftTSNode.name` instead of `leftTSNode` to avoid run-time errors because
29
+ * the `typeChecker.getTypeAtLocation` method expects a `ts.BindingName` instead
30
+ * of a`ts.VariableDeclaration`: https://github.com/microsoft/TypeScript/issues/48878
31
+ */
32
+ const type = checker.getTypeAtLocation(tsNode.name);
33
+ if (!isTypeReferenceType(type)) {
34
+ return;
35
+ }
36
+ const typeArguments = checker.getTypeArguments(type);
37
+ for (const [i, typeArgument] of typeArguments.entries()) {
38
+ if (isAny(typeArgument)) {
39
+ context.report({
40
+ node,
41
+ messageId: "noType",
42
+ data: {
43
+ ordinal: getOrdinalSuffix(i + 1), // e.g. 0 --> 1st
44
+ },
45
+ });
46
+ }
47
+ }
48
+ },
49
+ };
50
+ },
51
+ });
@@ -0,0 +1,5 @@
1
+ import { ESLintUtils } from "@typescript-eslint/utils";
2
+ type MessageIds = "noObjectEntriesMap" | "noObjectKeysMap" | "noObjectValuesMap" | "noObjectEntriesSet" | "noObjectKeysSet" | "noObjectValuesSet";
3
+ export declare const noObjectMethodsWithMapSet: ESLintUtils.RuleModule<MessageIds, [], import("../interfaces/MyPluginDocs.js").MyPluginDocs, ESLintUtils.RuleListener>;
4
+ export {};
5
+ //# sourceMappingURL=no-object-methods-with-map-set.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"no-object-methods-with-map-set.d.ts","sourceRoot":"","sources":["../../src/rules/no-object-methods-with-map-set.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAOvE,KAAK,UAAU,GACX,oBAAoB,GACpB,iBAAiB,GACjB,mBAAmB,GACnB,oBAAoB,GACpB,iBAAiB,GACjB,mBAAmB,CAAC;AAexB,eAAO,MAAM,yBAAyB,wHAwFpC,CAAC"}