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,347 @@
1
+ /* eslint-disable */
2
+ // @ts-nocheck
3
+ // cspell:ignore Katz
4
+ /**
5
+ * This rule is slightly modified from the original ESLint version in order to never apply the fix:
6
+ * https://github.com/eslint/eslint/blob/main/lib/rules/no-useless-return.js
7
+ *
8
+ * We disable type-checking, linting, and formatting in this file in order to keep the code as close
9
+ * as possible to the original.
10
+ */
11
+ import { createRule } from "../utils.js";
12
+ /**
13
+ * @fileoverview Disallow redundant return statements
14
+ * @author Teddy Katz
15
+ */
16
+ "use strict";
17
+ //------------------------------------------------------------------------------
18
+ // External code (copy pasted from elsewhere in the ESLint repository)
19
+ //------------------------------------------------------------------------------
20
+ // A set of node types that can contain a list of statements
21
+ const STATEMENT_LIST_PARENTS = new Set(["Program", "BlockStatement", "StaticBlock", "SwitchCase"]);
22
+ const anyFunctionPattern = /^(?:Function(?:Declaration|Expression)|ArrowFunctionExpression)$/u;
23
+ const anyLoopPattern = /^(?:DoWhile|For|ForIn|ForOf|While)Statement$/u;
24
+ /**
25
+ * Checks whether a given node is a function node or not.
26
+ * The following types are function nodes:
27
+ *
28
+ * - ArrowFunctionExpression
29
+ * - FunctionDeclaration
30
+ * - FunctionExpression
31
+ * @param {ASTNode|null} node A node to check.
32
+ * @returns {boolean} `true` if the node is a function node.
33
+ */
34
+ function isFunction(node) {
35
+ return Boolean(node && anyFunctionPattern.test(node.type));
36
+ }
37
+ /**
38
+ * Checks whether a given node is a loop node or not.
39
+ * The following types are loop nodes:
40
+ *
41
+ * - DoWhileStatement
42
+ * - ForInStatement
43
+ * - ForOfStatement
44
+ * - ForStatement
45
+ * - WhileStatement
46
+ * @param {ASTNode|null} node A node to check.
47
+ * @returns {boolean} `true` if the node is a loop node.
48
+ */
49
+ function isLoop(node) {
50
+ return Boolean(node && anyLoopPattern.test(node.type));
51
+ }
52
+ /**
53
+ * Checks whether the given node is in a loop or not.
54
+ * @param {ASTNode} node The node to check.
55
+ * @returns {boolean} `true` if the node is in a loop.
56
+ */
57
+ function isInLoop(node) {
58
+ for (let currentNode = node; currentNode && !isFunction(currentNode); currentNode = currentNode.parent) {
59
+ if (isLoop(currentNode)) {
60
+ return true;
61
+ }
62
+ }
63
+ return false;
64
+ }
65
+ //------------------------------------------------------------------------------
66
+ // Helpers
67
+ //------------------------------------------------------------------------------
68
+ /**
69
+ * Removes the given element from the array.
70
+ * @param {Array} array The source array to remove.
71
+ * @param {any} element The target item to remove.
72
+ * @returns {void}
73
+ */
74
+ function remove(array, element) {
75
+ const index = array.indexOf(element);
76
+ if (index !== -1) {
77
+ array.splice(index, 1);
78
+ }
79
+ }
80
+ /**
81
+ * Checks whether it can remove the given return statement or not.
82
+ * @param {ASTNode} node The return statement node to check.
83
+ * @returns {boolean} `true` if the node is removable.
84
+ */
85
+ function isRemovable(node) {
86
+ return STATEMENT_LIST_PARENTS.has(node.parent.type);
87
+ }
88
+ /**
89
+ * Checks whether the given return statement is in a `finally` block or not.
90
+ * @param {ASTNode} node The return statement node to check.
91
+ * @returns {boolean} `true` if the node is in a `finally` block.
92
+ */
93
+ function isInFinally(node) {
94
+ for (let currentNode = node; currentNode && currentNode.parent && !isFunction(currentNode); currentNode = currentNode.parent) {
95
+ if (currentNode.parent.type === "TryStatement" && currentNode.parent.finalizer === currentNode) {
96
+ return true;
97
+ }
98
+ }
99
+ return false;
100
+ }
101
+ /**
102
+ * Checks all segments in a set and returns true if any are reachable.
103
+ * @param {Set<CodePathSegment>} segments The segments to check.
104
+ * @returns {boolean} True if any segment is reachable; false otherwise.
105
+ */
106
+ function isAnySegmentReachable(segments) {
107
+ for (const segment of segments) {
108
+ if (segment.reachable) {
109
+ return true;
110
+ }
111
+ }
112
+ return false;
113
+ }
114
+ //------------------------------------------------------------------------------
115
+ // Rule Definition
116
+ //------------------------------------------------------------------------------
117
+ export const noUselessReturn = createRule({
118
+ name: "no-useless-return", // Added
119
+ defaultOptions: [], // Added; necessary for the `ruleCreator` helper function
120
+ meta: {
121
+ type: "suggestion",
122
+ docs: {
123
+ description: "Disallow redundant return statements (with no auto-fixer)", // Changed to add extra description
124
+ recommended: true, // Changed from true
125
+ // url: "https://eslint.org/docs/latest/rules/no-useless-return"
126
+ },
127
+ // fixable: "code",
128
+ schema: [],
129
+ messages: {
130
+ unnecessaryReturn: "Unnecessary return statement."
131
+ }
132
+ },
133
+ create(context) {
134
+ const segmentInfoMap = new WeakMap();
135
+ const sourceCode = context.sourceCode;
136
+ let scopeInfo = null;
137
+ /**
138
+ * Checks whether the given segment is terminated by a return statement or not.
139
+ * @param {CodePathSegment} segment The segment to check.
140
+ * @returns {boolean} `true` if the segment is terminated by a return statement, or if it's still a part of unreachable.
141
+ */
142
+ function isReturned(segment) {
143
+ const info = segmentInfoMap.get(segment);
144
+ return !info || info.returned;
145
+ }
146
+ /**
147
+ * Collects useless return statements from the given previous segments.
148
+ *
149
+ * A previous segment may be an unreachable segment.
150
+ * In that case, the information object of the unreachable segment is not
151
+ * initialized because `onCodePathSegmentStart` event is not notified for
152
+ * unreachable segments.
153
+ * This goes to the previous segments of the unreachable segment recursively
154
+ * if the unreachable segment was generated by a return statement. Otherwise,
155
+ * this ignores the unreachable segment.
156
+ *
157
+ * This behavior would simulate code paths for the case that the return
158
+ * statement does not exist.
159
+ * @param {ASTNode[]} uselessReturns The collected return statements.
160
+ * @param {CodePathSegment[]} prevSegments The previous segments to traverse.
161
+ * @param {WeakSet<CodePathSegment>} [providedTraversedSegments] A set of segments that have already been traversed in this call
162
+ * @returns {ASTNode[]} `uselessReturns`.
163
+ */
164
+ function getUselessReturns(uselessReturns, prevSegments, providedTraversedSegments) {
165
+ const traversedSegments = providedTraversedSegments || new WeakSet();
166
+ for (const segment of prevSegments) {
167
+ if (!segment.reachable) {
168
+ if (!traversedSegments.has(segment)) {
169
+ traversedSegments.add(segment);
170
+ getUselessReturns(uselessReturns, segment.allPrevSegments.filter(isReturned), traversedSegments);
171
+ }
172
+ continue;
173
+ }
174
+ if (segmentInfoMap.has(segment)) {
175
+ uselessReturns.push(...segmentInfoMap.get(segment).uselessReturns);
176
+ }
177
+ }
178
+ return uselessReturns;
179
+ }
180
+ /**
181
+ * Removes the return statements on the given segment from the useless return
182
+ * statement list.
183
+ *
184
+ * This segment may be an unreachable segment.
185
+ * In that case, the information object of the unreachable segment is not
186
+ * initialized because `onCodePathSegmentStart` event is not notified for
187
+ * unreachable segments.
188
+ * This goes to the previous segments of the unreachable segment recursively
189
+ * if the unreachable segment was generated by a return statement. Otherwise,
190
+ * this ignores the unreachable segment.
191
+ *
192
+ * This behavior would simulate code paths for the case that the return
193
+ * statement does not exist.
194
+ * @param {CodePathSegment} segment The segment to get return statements.
195
+ * @param {Set<CodePathSegment>} usedUnreachableSegments A set of segments that have already been traversed in this call.
196
+ * @returns {void}
197
+ */
198
+ function markReturnStatementsOnSegmentAsUsed(segment, usedUnreachableSegments) {
199
+ if (!segment.reachable) {
200
+ usedUnreachableSegments.add(segment);
201
+ segment.allPrevSegments
202
+ .filter(isReturned)
203
+ .filter(prevSegment => !usedUnreachableSegments.has(prevSegment))
204
+ .forEach(prevSegment => markReturnStatementsOnSegmentAsUsed(prevSegment, usedUnreachableSegments));
205
+ return;
206
+ }
207
+ const info = segmentInfoMap.get(segment);
208
+ if (!info) {
209
+ return;
210
+ }
211
+ info.uselessReturns = info.uselessReturns.filter(node => {
212
+ if (scopeInfo.traversedTryBlockStatements && scopeInfo.traversedTryBlockStatements.length > 0) {
213
+ const returnInitialRange = node.range[0];
214
+ const returnFinalRange = node.range[1];
215
+ const areBlocksInRange = scopeInfo.traversedTryBlockStatements.some(tryBlockStatement => {
216
+ const blockInitialRange = tryBlockStatement.range[0];
217
+ const blockFinalRange = tryBlockStatement.range[1];
218
+ return (returnInitialRange >= blockInitialRange &&
219
+ returnFinalRange <= blockFinalRange);
220
+ });
221
+ if (areBlocksInRange) {
222
+ return true;
223
+ }
224
+ }
225
+ remove(scopeInfo.uselessReturns, node);
226
+ return false;
227
+ });
228
+ }
229
+ /**
230
+ * Removes the return statements on the current segments from the useless
231
+ * return statement list.
232
+ *
233
+ * This function will be called at every statement except FunctionDeclaration,
234
+ * BlockStatement, and BreakStatement.
235
+ *
236
+ * - FunctionDeclarations are always executed whether it's returned or not.
237
+ * - BlockStatements do nothing.
238
+ * - BreakStatements go the next merely.
239
+ * @returns {void}
240
+ */
241
+ function markReturnStatementsOnCurrentSegmentsAsUsed() {
242
+ scopeInfo
243
+ .currentSegments
244
+ .forEach(segment => markReturnStatementsOnSegmentAsUsed(segment, new Set()));
245
+ }
246
+ //----------------------------------------------------------------------
247
+ // Public
248
+ //----------------------------------------------------------------------
249
+ return {
250
+ // Makes and pushes a new scope information.
251
+ onCodePathStart(codePath) {
252
+ scopeInfo = {
253
+ upper: scopeInfo,
254
+ uselessReturns: [],
255
+ traversedTryBlockStatements: [],
256
+ codePath,
257
+ currentSegments: new Set()
258
+ };
259
+ },
260
+ // Reports useless return statements if exist.
261
+ onCodePathEnd() {
262
+ for (const node of scopeInfo.uselessReturns) {
263
+ context.report({
264
+ node,
265
+ loc: node.loc,
266
+ messageId: "unnecessaryReturn",
267
+ });
268
+ }
269
+ scopeInfo = scopeInfo.upper;
270
+ },
271
+ /*
272
+ * Initializes segments.
273
+ * NOTE: This event is notified for only reachable segments.
274
+ */
275
+ onCodePathSegmentStart(segment) {
276
+ scopeInfo.currentSegments.add(segment);
277
+ const info = {
278
+ uselessReturns: getUselessReturns([], segment.allPrevSegments),
279
+ returned: false
280
+ };
281
+ // Stores the info.
282
+ segmentInfoMap.set(segment, info);
283
+ },
284
+ onUnreachableCodePathSegmentStart(segment) {
285
+ scopeInfo.currentSegments.add(segment);
286
+ },
287
+ onUnreachableCodePathSegmentEnd(segment) {
288
+ scopeInfo.currentSegments.delete(segment);
289
+ },
290
+ onCodePathSegmentEnd(segment) {
291
+ scopeInfo.currentSegments.delete(segment);
292
+ },
293
+ // Adds ReturnStatement node to check whether it's useless or not.
294
+ ReturnStatement(node) {
295
+ if (node.argument) {
296
+ markReturnStatementsOnCurrentSegmentsAsUsed();
297
+ }
298
+ if (node.argument ||
299
+ isInLoop(node) ||
300
+ isInFinally(node) ||
301
+ // Ignore `return` statements in unreachable places (https://github.com/eslint/eslint/issues/11647).
302
+ !isAnySegmentReachable(scopeInfo.currentSegments)) {
303
+ return;
304
+ }
305
+ for (const segment of scopeInfo.currentSegments) {
306
+ const info = segmentInfoMap.get(segment);
307
+ if (info) {
308
+ info.uselessReturns.push(node);
309
+ info.returned = true;
310
+ }
311
+ }
312
+ scopeInfo.uselessReturns.push(node);
313
+ },
314
+ "TryStatement > BlockStatement.block:exit"(node) {
315
+ scopeInfo.traversedTryBlockStatements.push(node);
316
+ },
317
+ "TryStatement:exit"() {
318
+ scopeInfo.traversedTryBlockStatements.pop();
319
+ },
320
+ /*
321
+ * Registers for all statement nodes except FunctionDeclaration, BlockStatement, BreakStatement.
322
+ * Removes return statements of the current segments from the useless return statement list.
323
+ */
324
+ ClassDeclaration: markReturnStatementsOnCurrentSegmentsAsUsed,
325
+ ContinueStatement: markReturnStatementsOnCurrentSegmentsAsUsed,
326
+ DebuggerStatement: markReturnStatementsOnCurrentSegmentsAsUsed,
327
+ DoWhileStatement: markReturnStatementsOnCurrentSegmentsAsUsed,
328
+ EmptyStatement: markReturnStatementsOnCurrentSegmentsAsUsed,
329
+ ExpressionStatement: markReturnStatementsOnCurrentSegmentsAsUsed,
330
+ ForInStatement: markReturnStatementsOnCurrentSegmentsAsUsed,
331
+ ForOfStatement: markReturnStatementsOnCurrentSegmentsAsUsed,
332
+ ForStatement: markReturnStatementsOnCurrentSegmentsAsUsed,
333
+ IfStatement: markReturnStatementsOnCurrentSegmentsAsUsed,
334
+ ImportDeclaration: markReturnStatementsOnCurrentSegmentsAsUsed,
335
+ LabeledStatement: markReturnStatementsOnCurrentSegmentsAsUsed,
336
+ SwitchStatement: markReturnStatementsOnCurrentSegmentsAsUsed,
337
+ ThrowStatement: markReturnStatementsOnCurrentSegmentsAsUsed,
338
+ TryStatement: markReturnStatementsOnCurrentSegmentsAsUsed,
339
+ VariableDeclaration: markReturnStatementsOnCurrentSegmentsAsUsed,
340
+ WhileStatement: markReturnStatementsOnCurrentSegmentsAsUsed,
341
+ WithStatement: markReturnStatementsOnCurrentSegmentsAsUsed,
342
+ ExportNamedDeclaration: markReturnStatementsOnCurrentSegmentsAsUsed,
343
+ ExportDefaultDeclaration: markReturnStatementsOnCurrentSegmentsAsUsed,
344
+ ExportAllDeclaration: markReturnStatementsOnCurrentSegmentsAsUsed
345
+ };
346
+ }
347
+ });
@@ -0,0 +1,2 @@
1
+ export declare const noVoidReturnType: import("@typescript-eslint/utils/ts-eslint").RuleModule<"voidReturnType", [], import("../interfaces/MyPluginDocs.js").MyPluginDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
2
+ //# sourceMappingURL=no-void-return-type.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"no-void-return-type.d.ts","sourceRoot":"","sources":["../../src/rules/no-void-return-type.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,gBAAgB,gMAmD3B,CAAC"}
@@ -0,0 +1,49 @@
1
+ import { AST_NODE_TYPES } from "@typescript-eslint/utils";
2
+ import { createRule } from "../utils.js";
3
+ export const noVoidReturnType = createRule({
4
+ name: "no-void-return-type",
5
+ meta: {
6
+ type: "problem",
7
+ docs: {
8
+ description: "Disallows `void` return types on non-exported functions",
9
+ recommended: true,
10
+ requiresTypeChecking: false,
11
+ },
12
+ schema: [],
13
+ messages: {
14
+ voidReturnType: "Non-exported functions cannot have a `void` return type. Remove the `void` keyword.",
15
+ },
16
+ fixable: "code",
17
+ },
18
+ defaultOptions: [],
19
+ create(context) {
20
+ return {
21
+ FunctionDeclaration(node) {
22
+ // Exported functions are exempt from this rule.
23
+ const { parent } = node;
24
+ if (
25
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
26
+ parent !== undefined &&
27
+ (parent.type === AST_NODE_TYPES.ExportNamedDeclaration ||
28
+ parent.type === AST_NODE_TYPES.ExportDefaultDeclaration)) {
29
+ return;
30
+ }
31
+ const { returnType } = node;
32
+ if (returnType === undefined) {
33
+ return;
34
+ }
35
+ const { typeAnnotation } = returnType;
36
+ if (typeAnnotation.type !== AST_NODE_TYPES.TSVoidKeyword) {
37
+ return;
38
+ }
39
+ context.report({
40
+ loc: typeAnnotation.loc,
41
+ messageId: "voidReturnType",
42
+ fix(fixer) {
43
+ return fixer.remove(returnType);
44
+ },
45
+ });
46
+ },
47
+ };
48
+ },
49
+ });
@@ -0,0 +1,2 @@
1
+ export declare const preferConst: import("@typescript-eslint/utils/ts-eslint").RuleModule<"useConst", [], import("../interfaces/MyPluginDocs.js").MyPluginDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
2
+ //# sourceMappingURL=prefer-const.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prefer-const.d.ts","sourceRoot":"","sources":["../../src/rules/prefer-const.ts"],"names":[],"mappings":"AAyWA,eAAO,MAAM,WAAW,0LAgKtB,CAAC"}