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,173 @@
1
+ /* eslint-disable */
2
+ // @ts-nocheck
3
+ // cspell:ignore Zakas
4
+ /**
5
+ * This rule is slightly modified from the original ESLint version in order to always apply the fix:
6
+ * https://github.com/eslint/eslint/blob/main/lib/rules/eqeqeq.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 Rule to flag statements that use != and == instead of !== and ===
14
+ * @author Nicholas C. Zakas
15
+ */
16
+ "use strict";
17
+ //------------------------------------------------------------------------------
18
+ // External code (copy pasted from elsewhere in the ESLint repository)
19
+ //------------------------------------------------------------------------------
20
+ /**
21
+ * Determines whether the given node is a `null` literal.
22
+ * @param {ASTNode} node The node to check
23
+ * @returns {boolean} `true` if the node is a `null` literal
24
+ */
25
+ function isNullLiteral(node) {
26
+ /*
27
+ * Checking `node.value === null` does not guarantee that a literal is a null literal.
28
+ * When parsing values that cannot be represented in the current environment (e.g. unicode
29
+ * regexes in Node 4), `node.value` is set to `null` because it wouldn't be possible to
30
+ * set `node.value` to a unicode regex. To make sure a literal is actually `null`, check
31
+ * `node.regex` instead. Also see: https://github.com/eslint/eslint/issues/8020
32
+ */
33
+ return node.type === "Literal" && node.value === null && !node.regex && !node.bigint;
34
+ }
35
+ export const eqeqeqFix = createRule({
36
+ name: "eqeqeq-fix", // Added
37
+ defaultOptions: [], // Added; necessary for the `ruleCreator` helper function
38
+ meta: {
39
+ type: "suggestion",
40
+ docs: {
41
+ description: "Requires the use of `===` and `!==` (and automatically fixes)",
42
+ recommended: true, // Changed from false
43
+ // url: "https://eslint.org/docs/latest/rules/eqeqeq"
44
+ },
45
+ schema: {
46
+ anyOf: [
47
+ {
48
+ type: "array",
49
+ items: [
50
+ {
51
+ enum: ["always"]
52
+ },
53
+ {
54
+ type: "object",
55
+ properties: {
56
+ null: {
57
+ enum: ["always", "never", "ignore"]
58
+ }
59
+ },
60
+ additionalProperties: false
61
+ }
62
+ ],
63
+ additionalItems: false
64
+ },
65
+ {
66
+ type: "array",
67
+ items: [
68
+ {
69
+ enum: ["smart", "allow-null"]
70
+ }
71
+ ],
72
+ additionalItems: false
73
+ }
74
+ ]
75
+ },
76
+ fixable: "code",
77
+ messages: {
78
+ unexpected: "Expected '{{expectedOperator}}' and instead saw '{{actualOperator}}'.",
79
+ },
80
+ },
81
+ create(context) {
82
+ const config = context.options[0] || "always";
83
+ const options = context.options[1] || {};
84
+ const sourceCode = context.sourceCode;
85
+ const nullOption = (config === "always")
86
+ ? options.null || "always"
87
+ : "ignore";
88
+ const enforceRuleForNull = (nullOption === "always");
89
+ const enforceInverseRuleForNull = (nullOption === "never");
90
+ /**
91
+ * Checks if an expression is a typeof expression
92
+ * @param {ASTNode} node The node to check
93
+ * @returns {boolean} if the node is a typeof expression
94
+ */
95
+ function isTypeOf(node) {
96
+ return node.type === "UnaryExpression" && node.operator === "typeof";
97
+ }
98
+ /**
99
+ * Checks if either operand of a binary expression is a typeof operation
100
+ * @param {ASTNode} node The node to check
101
+ * @returns {boolean} if one of the operands is typeof
102
+ * @private
103
+ */
104
+ function isTypeOfBinary(node) {
105
+ return isTypeOf(node.left) || isTypeOf(node.right);
106
+ }
107
+ /**
108
+ * Checks if operands are literals of the same type (via typeof)
109
+ * @param {ASTNode} node The node to check
110
+ * @returns {boolean} if operands are of same type
111
+ * @private
112
+ */
113
+ function areLiteralsAndSameType(node) {
114
+ return node.left.type === "Literal" && node.right.type === "Literal" &&
115
+ typeof node.left.value === typeof node.right.value;
116
+ }
117
+ /**
118
+ * Checks if one of the operands is a literal null
119
+ * @param {ASTNode} node The node to check
120
+ * @returns {boolean} if operands are null
121
+ * @private
122
+ */
123
+ function isNullCheck(node) {
124
+ return isNullLiteral(node.right) || isNullLiteral(node.left);
125
+ }
126
+ /**
127
+ * Reports a message for this rule.
128
+ * @param {ASTNode} node The binary expression node that was checked
129
+ * @param {string} expectedOperator The operator that was expected (either '==', '!=', '===', or '!==')
130
+ * @returns {void}
131
+ * @private
132
+ */
133
+ function report(node, expectedOperator) {
134
+ const operatorToken = sourceCode.getFirstTokenBetween(node.left, node.right, token => token.value === node.operator);
135
+ context.report({
136
+ node,
137
+ loc: operatorToken.loc,
138
+ messageId: "unexpected",
139
+ data: { expectedOperator, actualOperator: node.operator },
140
+ fix(fixer) {
141
+ /*
142
+ // If the comparison is a `typeof` comparison or both sides are literals with the same type, then it's safe to fix.
143
+ if (isTypeOfBinary(node) || areLiteralsAndSameType(node)) {
144
+ return fixer.replaceText(operatorToken, expectedOperator);
145
+ }
146
+ return null;
147
+ */
148
+ // Fix everything regardless of whether it is safe to fix.
149
+ return fixer.replaceText(operatorToken, expectedOperator);
150
+ }
151
+ });
152
+ }
153
+ return {
154
+ BinaryExpression(node) {
155
+ const isNull = isNullCheck(node);
156
+ if (node.operator !== "==" && node.operator !== "!=") {
157
+ if (enforceInverseRuleForNull && isNull) {
158
+ report(node, node.operator.slice(0, -1));
159
+ }
160
+ return;
161
+ }
162
+ if (config === "smart" && (isTypeOfBinary(node) ||
163
+ areLiteralsAndSameType(node) || isNull)) {
164
+ return;
165
+ }
166
+ if (!enforceRuleForNull && isNull) {
167
+ return;
168
+ }
169
+ report(node, `${node.operator}=`);
170
+ }
171
+ };
172
+ }
173
+ });
@@ -0,0 +1,8 @@
1
+ export type Options = [
2
+ {
3
+ maxLength: number;
4
+ }
5
+ ];
6
+ export type MessageIds = "incorrectlyFormatted";
7
+ export declare const formatJSDocComments: import("@typescript-eslint/utils/ts-eslint").RuleModule<"incorrectlyFormatted", Options, import("../interfaces/MyPluginDocs.js").MyPluginDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
8
+ //# sourceMappingURL=format-jsdoc-comments.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format-jsdoc-comments.d.ts","sourceRoot":"","sources":["../../src/rules/format-jsdoc-comments.ts"],"names":[],"mappings":"AAWA,MAAM,MAAM,OAAO,GAAG;IACpB;QACE,SAAS,EAAE,MAAM,CAAC;KACnB;CACF,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,sBAAsB,CAAC;AAEhD,eAAO,MAAM,mBAAmB,2MAuG9B,CAAC"}
@@ -0,0 +1,117 @@
1
+ import { trimPrefix } from "../completeCommon.js";
2
+ import { formatText } from "../format.js";
3
+ import { getJSDocComments, getTextFromJSDocComment } from "../jsdoc.js";
4
+ import { areStringsEqualExcludingTrailingSpaces, createRule, } from "../utils.js";
5
+ const EXTRA_NUM_CHARACTERS_TO_FIT_ON_JSDOC_SINGLE_LINE = 4;
6
+ const DEBUG = false;
7
+ export const formatJSDocComments = createRule({
8
+ name: "format-jsdoc-comments",
9
+ meta: {
10
+ type: "layout",
11
+ docs: {
12
+ description: "Disallows `/**` comments longer than N characters and multi-line comments that can be merged together",
13
+ recommended: true,
14
+ requiresTypeChecking: false,
15
+ },
16
+ schema: [
17
+ {
18
+ type: "object",
19
+ properties: {
20
+ maxLength: { type: "number" },
21
+ },
22
+ additionalProperties: false,
23
+ },
24
+ ],
25
+ messages: {
26
+ incorrectlyFormatted: "Comment is not formatted correctly.",
27
+ },
28
+ fixable: "whitespace",
29
+ },
30
+ defaultOptions: [
31
+ {
32
+ /**
33
+ * Matches the Airbnb style guide, which is the most popular JavaScript style guide in the
34
+ * world.
35
+ */
36
+ maxLength: 100,
37
+ },
38
+ ],
39
+ /**
40
+ * We need to write the rule in such a way that it operates on the entire source code instead of
41
+ * individual AST nodes:
42
+ * https://stackoverflow.com/questions/47429792/is-it-possible-to-get-comments-as-nodes-in-the-ast-using-the-typescript-compiler
43
+ */
44
+ create(context, [options]) {
45
+ const { maxLength } = options;
46
+ const comments = context.sourceCode.getAllComments();
47
+ // We only look at `/**` style comments on their own line.
48
+ const jsDocComments = getJSDocComments(comments);
49
+ for (const comment of jsDocComments) {
50
+ const leftWhitespaceLength = comment.loc.start.column;
51
+ const leftWhitespace = " ".repeat(leftWhitespaceLength);
52
+ const originalComment = `${leftWhitespace}/*${comment.value}*/`;
53
+ const text = getTextFromJSDocComment(comment.value);
54
+ const effectiveMaxLength = maxLength - leftWhitespaceLength - " * ".length;
55
+ let formattedText = formatText(text, effectiveMaxLength);
56
+ // - Disallow comments like: `/** *foo */`
57
+ // - We must escape the asterisk to avoid a run-time error.
58
+ formattedText = trimPrefix(formattedText, String.raw `\*`, true);
59
+ const canFitOnSingleLine = canFitOnSingleJSDocLine(formattedText, effectiveMaxLength);
60
+ const formattedComment = canFitOnSingleLine
61
+ ? getJSDocCommentSingleLine(formattedText, leftWhitespace)
62
+ : getJSDocCommentMultiLine(formattedText, leftWhitespace);
63
+ if (DEBUG && originalComment !== formattedComment) {
64
+ console.log("originalComment:");
65
+ console.log(originalComment);
66
+ console.log("formattedComment:");
67
+ console.log(formattedComment);
68
+ }
69
+ if (!areStringsEqualExcludingTrailingSpaces(originalComment, formattedComment)) {
70
+ context.report({
71
+ loc: {
72
+ start: comment.loc.start,
73
+ end: comment.loc.end,
74
+ },
75
+ messageId: "incorrectlyFormatted",
76
+ fix: (fixer) => {
77
+ const [commentStart, commentEnd] = comment.range;
78
+ const commentBeginningOfLine = commentStart - comment.loc.start.column;
79
+ const range = [commentBeginningOfLine, commentEnd];
80
+ return fixer.replaceTextRange(range, formattedComment);
81
+ },
82
+ });
83
+ }
84
+ }
85
+ return {};
86
+ },
87
+ });
88
+ /**
89
+ * JSDoc can be either single-line or multi-line. For example:
90
+ *
91
+ * ```ts
92
+ * /** This is a single-line JSDoc comment. * /
93
+ *
94
+ * /**
95
+ * * This is a multi-line JSDoc comment.
96
+ * * /
97
+ * ```
98
+ */
99
+ function canFitOnSingleJSDocLine(text, effectiveMaxLength) {
100
+ const textLines = text.split("\n");
101
+ return (textLines.length === 1 &&
102
+ text.length + EXTRA_NUM_CHARACTERS_TO_FIT_ON_JSDOC_SINGLE_LINE <=
103
+ effectiveMaxLength);
104
+ }
105
+ function getJSDocCommentSingleLine(text, leftWhitespace) {
106
+ return `${leftWhitespace}/** ${text} */`;
107
+ }
108
+ function getJSDocCommentMultiLine(text, leftWhitespace) {
109
+ const header = `${leftWhitespace}/**`;
110
+ const emptyLine = `${leftWhitespace} *`;
111
+ const footer = `${leftWhitespace} */`;
112
+ const linePrefix = `${emptyLine} `;
113
+ const lines = text.split("\n");
114
+ const commentLines = lines.map((line) => line.trim() === "" ? emptyLine : `${linePrefix}${line}`);
115
+ const comments = commentLines.join("\n");
116
+ return `${header}\n${comments}\n${footer}`;
117
+ }
@@ -0,0 +1,8 @@
1
+ export type Options = [
2
+ {
3
+ maxLength: number;
4
+ }
5
+ ];
6
+ export type MessageIds = "incorrectlyFormatted";
7
+ export declare const formatLineComments: import("@typescript-eslint/utils/ts-eslint").RuleModule<"incorrectlyFormatted", Options, import("../interfaces/MyPluginDocs.js").MyPluginDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
8
+ //# sourceMappingURL=format-line-comments.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"format-line-comments.d.ts","sourceRoot":"","sources":["../../src/rules/format-line-comments.ts"],"names":[],"mappings":"AAgBA,MAAM,MAAM,OAAO,GAAG;IACpB;QACE,SAAS,EAAE,MAAM,CAAC;KACnB;CACF,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG,sBAAsB,CAAC;AAEhD,eAAO,MAAM,kBAAkB,2MAqH7B,CAAC"}
@@ -0,0 +1,118 @@
1
+ import { assertDefined } from "../completeCommon.js";
2
+ import { formatText } from "../format.js";
3
+ import { allCommentsInBlockAreCommentedOutArrayElements, getCommentBlocks, getLeadingLineComments, } from "../leadingLineComments.js";
4
+ import { areStringsEqualExcludingTrailingSpaces, createRule, } from "../utils.js";
5
+ const SLASH_SLASH = "//";
6
+ const DEBUG = false;
7
+ export const formatLineComments = createRule({
8
+ name: "format-line-comments",
9
+ meta: {
10
+ type: "layout",
11
+ docs: {
12
+ description: "Disallows `//` comments longer than N characters and multi-line comments that can be merged together",
13
+ recommended: true,
14
+ requiresTypeChecking: false,
15
+ },
16
+ schema: [
17
+ {
18
+ type: "object",
19
+ properties: {
20
+ maxLength: { type: "number" },
21
+ },
22
+ additionalProperties: false,
23
+ },
24
+ ],
25
+ messages: {
26
+ incorrectlyFormatted: "Comment is not formatted correctly.",
27
+ },
28
+ fixable: "whitespace",
29
+ },
30
+ defaultOptions: [
31
+ {
32
+ /**
33
+ * Matches the Airbnb style guide, which is the most popular JavaScript style guide in the
34
+ * world.
35
+ */
36
+ maxLength: 100,
37
+ },
38
+ ],
39
+ /**
40
+ * We need to write the rule in such a way that it operates on the entire source code instead of
41
+ * individual AST nodes:
42
+ * https://stackoverflow.com/questions/47429792/is-it-possible-to-get-comments-as-nodes-in-the-ast-using-the-typescript-compiler
43
+ */
44
+ create(context, [options]) {
45
+ const { maxLength } = options;
46
+ const { sourceCode } = context;
47
+ const comments = sourceCode.getAllComments();
48
+ // We only look at `//` style comments on their own line.
49
+ const leadingLineComments = getLeadingLineComments(sourceCode, comments);
50
+ // Sort the comments by blocks.
51
+ const commentBlocks = getCommentBlocks(leadingLineComments);
52
+ for (const commentBlock of commentBlocks) {
53
+ const firstComment = commentBlock.originalComments.at(0);
54
+ assertDefined(firstComment, "Failed to get the first comment.");
55
+ const lastComment = commentBlock.originalComments.at(-1);
56
+ assertDefined(lastComment, "Failed to get the last comment.");
57
+ // Commented out array elements are whitelisted.
58
+ if (allCommentsInBlockAreCommentedOutArrayElements(commentBlock)) {
59
+ continue;
60
+ }
61
+ const leftWhitespaceLength = firstComment.loc.start.column;
62
+ const leftWhitespace = " ".repeat(leftWhitespaceLength);
63
+ const originalText = getTextFromComments(commentBlock.originalComments, leftWhitespace);
64
+ const effectiveMaxLength = maxLength - leftWhitespaceLength - "// ".length;
65
+ const formattedTextRaw = formatText(commentBlock.mergedText, effectiveMaxLength, false);
66
+ const formattedText = convertTextToLeadingLineComments(formattedTextRaw, leftWhitespace);
67
+ if (DEBUG && originalText !== formattedText) {
68
+ console.log("originalText:");
69
+ console.log(originalText);
70
+ console.log("formattedText:");
71
+ console.log(formattedText);
72
+ }
73
+ if (!areStringsEqualExcludingTrailingSpaces(originalText, formattedText)) {
74
+ context.report({
75
+ loc: {
76
+ start: firstComment.loc.start,
77
+ end: lastComment.loc.end,
78
+ },
79
+ messageId: "incorrectlyFormatted",
80
+ fix: (fixer) => {
81
+ const [firstCommentStart, _firstCommentEnd] = firstComment.range;
82
+ const [_lastCommentStart, lastCommentEnd] = lastComment.range;
83
+ const firstCommentBeginningOfLine = firstCommentStart - firstComment.loc.start.column;
84
+ const range = [
85
+ firstCommentBeginningOfLine,
86
+ lastCommentEnd,
87
+ ];
88
+ return fixer.replaceTextRange(range, formattedText);
89
+ },
90
+ });
91
+ }
92
+ }
93
+ return {};
94
+ },
95
+ });
96
+ /**
97
+ * Given an array of comments, transform the text back into how it would look in the real source
98
+ * code.
99
+ *
100
+ * Note that this should not include the left whitespace before the comment actually begins, because
101
+ * we need to compare the vanilla source code to the formatted source code without worrying about
102
+ * any leading whitespace.
103
+ */
104
+ function getTextFromComments(comments, leftWhitespace) {
105
+ const lines = comments.map(
106
+ // `comment.value` will almost always have a leading leading space, due to Prettier changing
107
+ // `//Comment` to `// Comment`. But it is also possible that the rule is running before Prettier
108
+ // has had a chance to format the code. Either way, we want this function to represent the text
109
+ // as it really is in the source code.
110
+ (comment) => `${leftWhitespace}${SLASH_SLASH}${comment.value}`);
111
+ return lines.join("\n");
112
+ }
113
+ /** Converts "Foo" to "// Foo". */
114
+ function convertTextToLeadingLineComments(text, leftWhitespace) {
115
+ const lines = text.split("\n");
116
+ const linesWithPrefix = lines.map((line) => `${leftWhitespace}${SLASH_SLASH} ${line}`);
117
+ return linesWithPrefix.join("\n");
118
+ }
@@ -0,0 +1,2 @@
1
+ export declare const jsdocCodeBlockLanguage: import("@typescript-eslint/utils/ts-eslint").RuleModule<"noLanguage", [], import("../interfaces/MyPluginDocs.js").MyPluginDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
2
+ //# sourceMappingURL=jsdoc-code-block-language.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jsdoc-code-block-language.d.ts","sourceRoot":"","sources":["../../src/rules/jsdoc-code-block-language.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,sBAAsB,4LAyDjC,CAAC"}
@@ -0,0 +1,52 @@
1
+ import { getJSDocComments, getTextFromJSDocComment } from "../jsdoc.js";
2
+ import { createRule } from "../utils.js";
3
+ export const jsdocCodeBlockLanguage = createRule({
4
+ name: "jsdoc-code-block-language",
5
+ meta: {
6
+ type: "problem",
7
+ docs: {
8
+ description: "Requires a language specification for every JSDoc code block",
9
+ recommended: true,
10
+ requiresTypeChecking: false,
11
+ },
12
+ schema: [],
13
+ messages: {
14
+ noLanguage: "You must specify a language for the code block.",
15
+ },
16
+ },
17
+ defaultOptions: [],
18
+ /**
19
+ * We need to write the rule in such a way that it operates on the entire source code instead of
20
+ * individual AST nodes:
21
+ * https://stackoverflow.com/questions/47429792/is-it-possible-to-get-comments-as-nodes-in-the-ast-using-the-typescript-compiler
22
+ */
23
+ create(context) {
24
+ const comments = context.sourceCode.getAllComments();
25
+ // We only look at `/**` style comments.
26
+ const jsDocComments = getJSDocComments(comments);
27
+ for (const comment of jsDocComments) {
28
+ const text = getTextFromJSDocComment(comment.value);
29
+ const lines = text.split("\n");
30
+ // We only want to match the opening backticks of a code block.
31
+ let insideCodeBlock = false;
32
+ for (const line of lines) {
33
+ if (line.includes("```")) {
34
+ insideCodeBlock = !insideCodeBlock;
35
+ }
36
+ if (!insideCodeBlock) {
37
+ continue;
38
+ }
39
+ if (line.endsWith("```")) {
40
+ context.report({
41
+ loc: {
42
+ start: comment.loc.start,
43
+ end: comment.loc.end,
44
+ },
45
+ messageId: "noLanguage",
46
+ });
47
+ }
48
+ }
49
+ }
50
+ return {};
51
+ },
52
+ });
@@ -0,0 +1,4 @@
1
+ export type Options = [];
2
+ export type MessageIds = "noNewline";
3
+ export declare const newlineBetweenSwitchCase: import("@typescript-eslint/utils/ts-eslint").RuleModule<"noNewline", [], import("../interfaces/MyPluginDocs.js").MyPluginDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
4
+ //# sourceMappingURL=newline-between-switch-case.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"newline-between-switch-case.d.ts","sourceRoot":"","sources":["../../src/rules/newline-between-switch-case.ts"],"names":[],"mappings":"AAMA,MAAM,MAAM,OAAO,GAAG,EAAE,CAAC;AACzB,MAAM,MAAM,UAAU,GAAG,WAAW,CAAC;AAErC,eAAO,MAAM,wBAAwB,2LAsDnC,CAAC"}
@@ -0,0 +1,63 @@
1
+ // The code here needs to detect the "fall through" switch case. Thus, we borrow heavily from the
2
+ // source code for the "no-fallthrough" rule.
3
+ import { createRule } from "../utils.js";
4
+ export const newlineBetweenSwitchCase = createRule({
5
+ name: "newline-between-switch-case",
6
+ meta: {
7
+ type: "layout",
8
+ docs: {
9
+ description: "Requires newlines between switch cases",
10
+ recommended: true,
11
+ requiresTypeChecking: false,
12
+ },
13
+ schema: [],
14
+ messages: {
15
+ noNewline: "Newline required between switch cases.",
16
+ },
17
+ fixable: "whitespace",
18
+ },
19
+ defaultOptions: [],
20
+ create(context) {
21
+ const { sourceCode } = context;
22
+ return {
23
+ SwitchCase(node) {
24
+ const { parent } = node;
25
+ // Ignore switch cases without a consequent (i.e. no brackets), as those should not have
26
+ // newlines after them.
27
+ if (node.consequent.length === 0) {
28
+ return;
29
+ }
30
+ // Ignore the final case, as there should not be a newline between the final case and the
31
+ // end of the switch statement.
32
+ const finalCase = parent.cases.at(-1);
33
+ const isFinalCase = node === finalCase;
34
+ if (isFinalCase) {
35
+ return;
36
+ }
37
+ const nextToken = sourceCode.getTokenAfter(node);
38
+ if (nextToken === null) {
39
+ return;
40
+ }
41
+ if (!hasBlankLinesBetween(node, nextToken)) {
42
+ context.report({
43
+ node,
44
+ fix(fixer) {
45
+ return fixer.insertTextAfter(node, "\n");
46
+ },
47
+ messageId: "noNewline",
48
+ });
49
+ }
50
+ },
51
+ };
52
+ },
53
+ });
54
+ /**
55
+ * Checks whether a node and a token are separated by blank lines.
56
+ *
57
+ * @param node The node to check.
58
+ * @param token The token to compare against.
59
+ * @returns `true` if there are blank lines between node and token.
60
+ */
61
+ function hasBlankLinesBetween(node, token) {
62
+ return token.loc.start.line > node.loc.end.line + 1;
63
+ }
@@ -0,0 +1,5 @@
1
+ import { ESLintUtils } from "@typescript-eslint/utils";
2
+ type MessageIds = "noKeys" | "noEntries";
3
+ export declare const noConfusingSetMethods: ESLintUtils.RuleModule<MessageIds, [], import("../interfaces/MyPluginDocs.js").MyPluginDocs, ESLintUtils.RuleListener>;
4
+ export {};
5
+ //# sourceMappingURL=no-confusing-set-methods.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"no-confusing-set-methods.d.ts","sourceRoot":"","sources":["../../src/rules/no-confusing-set-methods.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,WAAW,EAAE,MAAM,0BAA0B,CAAC;AAMvE,KAAK,UAAU,GAAG,QAAQ,GAAG,WAAW,CAAC;AAOzC,eAAO,MAAM,qBAAqB,wHAkDhC,CAAC"}
@@ -0,0 +1,51 @@
1
+ import { AST_NODE_TYPES, ESLintUtils } from "@typescript-eslint/utils";
2
+ import { getTypeName } from "../typeUtils.js";
3
+ import { createRule } from "../utils.js";
4
+ const METHOD_NAME_TO_MESSAGE_ID = new Map([
5
+ ["keys", "noKeys"],
6
+ ["entries", "noEntries"],
7
+ ]);
8
+ export const noConfusingSetMethods = createRule({
9
+ name: "no-confusing-set-methods",
10
+ meta: {
11
+ type: "problem",
12
+ docs: {
13
+ description: "Disallows confusing methods for sets",
14
+ recommended: true,
15
+ requiresTypeChecking: true,
16
+ },
17
+ schema: [],
18
+ messages: {
19
+ noKeys: "Using the `Set.keys` method is confusing, since sets do not have keys. Use the `Set.values` method instead.",
20
+ noEntries: "Using the `Set.entries` method is confusing, since sets only have values. Use the `Set.values` method instead.",
21
+ },
22
+ },
23
+ defaultOptions: [],
24
+ create(context) {
25
+ const parserServices = ESLintUtils.getParserServices(context);
26
+ const checker = parserServices.program.getTypeChecker();
27
+ return {
28
+ MemberExpression(node) {
29
+ const tsNode = parserServices.esTreeNodeToTSNodeMap.get(node.object);
30
+ const type = checker.getTypeAtLocation(tsNode);
31
+ const typeName = getTypeName(type);
32
+ if (typeName !== "Set" && typeName !== "ReadonlySet") {
33
+ return;
34
+ }
35
+ const { property } = node;
36
+ if (property.type !== AST_NODE_TYPES.Identifier) {
37
+ return;
38
+ }
39
+ const methodName = property.name;
40
+ const messageId = METHOD_NAME_TO_MESSAGE_ID.get(methodName);
41
+ if (messageId === undefined) {
42
+ return;
43
+ }
44
+ context.report({
45
+ loc: node.loc,
46
+ messageId,
47
+ });
48
+ },
49
+ };
50
+ },
51
+ });
@@ -0,0 +1,2 @@
1
+ export declare const noEmptyJSDoc: import("@typescript-eslint/utils/ts-eslint").RuleModule<"isEmpty", [], import("../interfaces/MyPluginDocs.js").MyPluginDocs, import("@typescript-eslint/utils/ts-eslint").RuleListener>;
2
+ //# sourceMappingURL=no-empty-jsdoc.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"no-empty-jsdoc.d.ts","sourceRoot":"","sources":["../../src/rules/no-empty-jsdoc.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,YAAY,yLA+CvB,CAAC"}