eslint 8.57.0 → 9.2.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 (156) hide show
  1. package/README.md +31 -28
  2. package/bin/eslint.js +4 -3
  3. package/conf/ecma-version.js +16 -0
  4. package/conf/globals.js +1 -0
  5. package/conf/rule-type-list.json +3 -1
  6. package/lib/api.js +7 -11
  7. package/lib/cli-engine/cli-engine.js +14 -3
  8. package/lib/cli-engine/formatters/formatters-meta.json +1 -29
  9. package/lib/cli-engine/lint-result-cache.js +2 -2
  10. package/lib/cli.js +115 -36
  11. package/lib/config/default-config.js +3 -0
  12. package/lib/config/flat-config-array.js +110 -24
  13. package/lib/config/flat-config-helpers.js +41 -20
  14. package/lib/config/flat-config-schema.js +1 -7
  15. package/lib/config/rule-validator.js +42 -6
  16. package/lib/eslint/eslint-helpers.js +116 -58
  17. package/lib/eslint/eslint.js +892 -377
  18. package/lib/eslint/index.js +2 -2
  19. package/lib/eslint/legacy-eslint.js +728 -0
  20. package/lib/linter/apply-disable-directives.js +59 -31
  21. package/lib/linter/code-path-analysis/code-path-analyzer.js +0 -1
  22. package/lib/linter/code-path-analysis/code-path.js +32 -30
  23. package/lib/linter/code-path-analysis/fork-context.js +1 -1
  24. package/lib/linter/config-comment-parser.js +8 -11
  25. package/lib/linter/index.js +1 -3
  26. package/lib/linter/interpolate.js +24 -2
  27. package/lib/linter/linter.js +428 -207
  28. package/lib/linter/report-translator.js +3 -3
  29. package/lib/linter/rules.js +6 -15
  30. package/lib/linter/source-code-fixer.js +1 -1
  31. package/lib/linter/timing.js +16 -8
  32. package/lib/options.js +35 -3
  33. package/lib/rule-tester/index.js +3 -1
  34. package/lib/rule-tester/rule-tester.js +424 -347
  35. package/lib/rules/array-bracket-newline.js +1 -1
  36. package/lib/rules/array-bracket-spacing.js +1 -1
  37. package/lib/rules/block-scoped-var.js +1 -1
  38. package/lib/rules/callback-return.js +2 -2
  39. package/lib/rules/camelcase.js +3 -5
  40. package/lib/rules/capitalized-comments.js +10 -7
  41. package/lib/rules/comma-dangle.js +1 -1
  42. package/lib/rules/comma-style.js +2 -2
  43. package/lib/rules/complexity.js +14 -1
  44. package/lib/rules/constructor-super.js +99 -100
  45. package/lib/rules/default-case.js +1 -1
  46. package/lib/rules/eol-last.js +2 -2
  47. package/lib/rules/function-paren-newline.js +2 -2
  48. package/lib/rules/indent-legacy.js +5 -5
  49. package/lib/rules/indent.js +5 -5
  50. package/lib/rules/index.js +1 -2
  51. package/lib/rules/key-spacing.js +2 -2
  52. package/lib/rules/line-comment-position.js +1 -1
  53. package/lib/rules/lines-around-directive.js +2 -2
  54. package/lib/rules/max-depth.js +1 -1
  55. package/lib/rules/max-len.js +3 -3
  56. package/lib/rules/max-lines.js +3 -3
  57. package/lib/rules/max-nested-callbacks.js +1 -1
  58. package/lib/rules/max-params.js +1 -1
  59. package/lib/rules/max-statements.js +1 -1
  60. package/lib/rules/multiline-comment-style.js +7 -7
  61. package/lib/rules/new-cap.js +1 -1
  62. package/lib/rules/newline-after-var.js +1 -1
  63. package/lib/rules/newline-before-return.js +1 -1
  64. package/lib/rules/no-case-declarations.js +13 -1
  65. package/lib/rules/no-constant-binary-expression.js +7 -8
  66. package/lib/rules/no-constant-condition.js +18 -7
  67. package/lib/rules/no-constructor-return.js +2 -2
  68. package/lib/rules/no-dupe-class-members.js +2 -2
  69. package/lib/rules/no-else-return.js +1 -1
  70. package/lib/rules/no-empty-function.js +2 -2
  71. package/lib/rules/no-empty-static-block.js +1 -1
  72. package/lib/rules/no-extend-native.js +1 -2
  73. package/lib/rules/no-extra-semi.js +1 -1
  74. package/lib/rules/no-fallthrough.js +41 -16
  75. package/lib/rules/no-implicit-coercion.js +66 -24
  76. package/lib/rules/no-inner-declarations.js +23 -2
  77. package/lib/rules/no-invalid-regexp.js +1 -1
  78. package/lib/rules/no-invalid-this.js +1 -1
  79. package/lib/rules/no-lone-blocks.js +3 -3
  80. package/lib/rules/no-loss-of-precision.js +1 -1
  81. package/lib/rules/no-misleading-character-class.js +225 -69
  82. package/lib/rules/no-mixed-spaces-and-tabs.js +1 -1
  83. package/lib/rules/no-multiple-empty-lines.js +1 -1
  84. package/lib/rules/no-new-native-nonconstructor.js +1 -1
  85. package/lib/rules/no-new-symbol.js +8 -1
  86. package/lib/rules/no-restricted-globals.js +1 -1
  87. package/lib/rules/no-restricted-imports.js +186 -40
  88. package/lib/rules/no-restricted-modules.js +2 -2
  89. package/lib/rules/no-return-await.js +1 -1
  90. package/lib/rules/no-sequences.js +1 -0
  91. package/lib/rules/no-this-before-super.js +45 -13
  92. package/lib/rules/no-trailing-spaces.js +2 -3
  93. package/lib/rules/no-unneeded-ternary.js +1 -1
  94. package/lib/rules/no-unsafe-optional-chaining.js +1 -1
  95. package/lib/rules/no-unused-private-class-members.js +1 -1
  96. package/lib/rules/no-unused-vars.js +197 -36
  97. package/lib/rules/no-useless-assignment.js +566 -0
  98. package/lib/rules/no-useless-backreference.js +1 -1
  99. package/lib/rules/no-useless-computed-key.js +2 -2
  100. package/lib/rules/no-useless-return.js +7 -2
  101. package/lib/rules/object-curly-spacing.js +3 -3
  102. package/lib/rules/object-property-newline.js +1 -1
  103. package/lib/rules/one-var.js +5 -5
  104. package/lib/rules/padded-blocks.js +7 -7
  105. package/lib/rules/prefer-arrow-callback.js +3 -3
  106. package/lib/rules/prefer-reflect.js +1 -1
  107. package/lib/rules/prefer-regex-literals.js +1 -1
  108. package/lib/rules/prefer-template.js +1 -1
  109. package/lib/rules/radix.js +2 -2
  110. package/lib/rules/semi-style.js +1 -1
  111. package/lib/rules/sort-imports.js +1 -1
  112. package/lib/rules/sort-keys.js +1 -1
  113. package/lib/rules/sort-vars.js +1 -1
  114. package/lib/rules/space-unary-ops.js +1 -1
  115. package/lib/rules/strict.js +1 -1
  116. package/lib/rules/use-isnan.js +101 -7
  117. package/lib/rules/utils/ast-utils.js +16 -7
  118. package/lib/rules/utils/char-source.js +240 -0
  119. package/lib/rules/utils/lazy-loading-rule-map.js +1 -1
  120. package/lib/rules/utils/unicode/index.js +9 -4
  121. package/lib/rules/yield-star-spacing.js +1 -1
  122. package/lib/shared/runtime-info.js +1 -0
  123. package/lib/shared/serialization.js +55 -0
  124. package/lib/shared/stats.js +30 -0
  125. package/lib/shared/string-utils.js +9 -11
  126. package/lib/shared/types.js +35 -1
  127. package/lib/source-code/index.js +3 -1
  128. package/lib/source-code/source-code.js +299 -85
  129. package/lib/source-code/token-store/backward-token-cursor.js +3 -3
  130. package/lib/source-code/token-store/cursors.js +4 -2
  131. package/lib/source-code/token-store/forward-token-comment-cursor.js +3 -3
  132. package/lib/source-code/token-store/forward-token-cursor.js +3 -3
  133. package/lib/source-code/token-store/index.js +2 -2
  134. package/lib/unsupported-api.js +3 -5
  135. package/messages/no-config-found.js +1 -1
  136. package/messages/plugin-conflict.js +1 -1
  137. package/messages/plugin-invalid.js +1 -1
  138. package/messages/plugin-missing.js +1 -1
  139. package/package.json +32 -29
  140. package/conf/config-schema.js +0 -93
  141. package/lib/cli-engine/formatters/checkstyle.js +0 -60
  142. package/lib/cli-engine/formatters/compact.js +0 -60
  143. package/lib/cli-engine/formatters/jslint-xml.js +0 -41
  144. package/lib/cli-engine/formatters/junit.js +0 -82
  145. package/lib/cli-engine/formatters/tap.js +0 -95
  146. package/lib/cli-engine/formatters/unix.js +0 -58
  147. package/lib/cli-engine/formatters/visualstudio.js +0 -63
  148. package/lib/cli-engine/xml-escape.js +0 -34
  149. package/lib/eslint/flat-eslint.js +0 -1155
  150. package/lib/rule-tester/flat-rule-tester.js +0 -1131
  151. package/lib/rules/require-jsdoc.js +0 -122
  152. package/lib/rules/utils/patterns/letters.js +0 -36
  153. package/lib/rules/valid-jsdoc.js +0 -516
  154. package/lib/shared/config-validator.js +0 -347
  155. package/lib/shared/deprecation-warnings.js +0 -58
  156. package/lib/shared/relative-module-resolver.js +0 -50
@@ -1,122 +0,0 @@
1
- /**
2
- * @fileoverview Rule to check for jsdoc presence.
3
- * @author Gyandeep Singh
4
- * @deprecated in ESLint v5.10.0
5
- */
6
- "use strict";
7
-
8
- /** @type {import('../shared/types').Rule} */
9
- module.exports = {
10
- meta: {
11
- type: "suggestion",
12
-
13
- docs: {
14
- description: "Require JSDoc comments",
15
- recommended: false,
16
- url: "https://eslint.org/docs/latest/rules/require-jsdoc"
17
- },
18
-
19
- schema: [
20
- {
21
- type: "object",
22
- properties: {
23
- require: {
24
- type: "object",
25
- properties: {
26
- ClassDeclaration: {
27
- type: "boolean",
28
- default: false
29
- },
30
- MethodDefinition: {
31
- type: "boolean",
32
- default: false
33
- },
34
- FunctionDeclaration: {
35
- type: "boolean",
36
- default: true
37
- },
38
- ArrowFunctionExpression: {
39
- type: "boolean",
40
- default: false
41
- },
42
- FunctionExpression: {
43
- type: "boolean",
44
- default: false
45
- }
46
- },
47
- additionalProperties: false,
48
- default: {}
49
- }
50
- },
51
- additionalProperties: false
52
- }
53
- ],
54
-
55
- deprecated: true,
56
- replacedBy: [],
57
-
58
- messages: {
59
- missingJSDocComment: "Missing JSDoc comment."
60
- }
61
- },
62
-
63
- create(context) {
64
- const source = context.sourceCode;
65
- const DEFAULT_OPTIONS = {
66
- FunctionDeclaration: true,
67
- MethodDefinition: false,
68
- ClassDeclaration: false,
69
- ArrowFunctionExpression: false,
70
- FunctionExpression: false
71
- };
72
- const options = Object.assign(DEFAULT_OPTIONS, context.options[0] && context.options[0].require);
73
-
74
- /**
75
- * Report the error message
76
- * @param {ASTNode} node node to report
77
- * @returns {void}
78
- */
79
- function report(node) {
80
- context.report({ node, messageId: "missingJSDocComment" });
81
- }
82
-
83
- /**
84
- * Check if the jsdoc comment is present or not.
85
- * @param {ASTNode} node node to examine
86
- * @returns {void}
87
- */
88
- function checkJsDoc(node) {
89
- const jsdocComment = source.getJSDocComment(node);
90
-
91
- if (!jsdocComment) {
92
- report(node);
93
- }
94
- }
95
-
96
- return {
97
- FunctionDeclaration(node) {
98
- if (options.FunctionDeclaration) {
99
- checkJsDoc(node);
100
- }
101
- },
102
- FunctionExpression(node) {
103
- if (
104
- (options.MethodDefinition && node.parent.type === "MethodDefinition") ||
105
- (options.FunctionExpression && (node.parent.type === "VariableDeclarator" || (node.parent.type === "Property" && node === node.parent.value)))
106
- ) {
107
- checkJsDoc(node);
108
- }
109
- },
110
- ClassDeclaration(node) {
111
- if (options.ClassDeclaration) {
112
- checkJsDoc(node);
113
- }
114
- },
115
- ArrowFunctionExpression(node) {
116
- if (options.ArrowFunctionExpression && node.parent.type === "VariableDeclarator") {
117
- checkJsDoc(node);
118
- }
119
- }
120
- };
121
- }
122
- };
@@ -1,36 +0,0 @@
1
- /**
2
- * @fileoverview Pattern for detecting any letter (even letters outside of ASCII).
3
- * NOTE: This file was generated using this script in JSCS based on the Unicode 7.0.0 standard: https://github.com/jscs-dev/node-jscs/blob/f5ed14427deb7e7aac84f3056a5aab2d9f3e563e/publish/helpers/generate-patterns.js
4
- * Do not edit this file by hand-- please use https://github.com/mathiasbynens/regenerate to regenerate the regular expression exported from this file.
5
- * @author Kevin Partington
6
- * @license MIT License (from JSCS). See below.
7
- */
8
-
9
- /*
10
- * The MIT License (MIT)
11
- *
12
- * Copyright 2013-2016 Dulin Marat and other contributors
13
- *
14
- * Permission is hereby granted, free of charge, to any person obtaining
15
- * a copy of this software and associated documentation files (the
16
- * "Software"), to deal in the Software without restriction, including
17
- * without limitation the rights to use, copy, modify, merge, publish,
18
- * distribute, sublicense, and/or sell copies of the Software, and to
19
- * permit persons to whom the Software is furnished to do so, subject to
20
- * the following conditions:
21
- *
22
- * The above copyright notice and this permission notice shall be
23
- * included in all copies or substantial portions of the Software.
24
- *
25
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
26
- * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
27
- * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
28
- * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
29
- * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
30
- * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
31
- * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
32
- */
33
-
34
- "use strict";
35
-
36
- module.exports = /[A-Za-z\xAA\xB5\xBA\xC0-\xD6\xD8-\xF6\xF8-\u02C1\u02C6-\u02D1\u02E0-\u02E4\u02EC\u02EE\u0370-\u0374\u0376\u0377\u037A-\u037D\u037F\u0386\u0388-\u038A\u038C\u038E-\u03A1\u03A3-\u03F5\u03F7-\u0481\u048A-\u052F\u0531-\u0556\u0559\u0561-\u0587\u05D0-\u05EA\u05F0-\u05F2\u0620-\u064A\u066E\u066F\u0671-\u06D3\u06D5\u06E5\u06E6\u06EE\u06EF\u06FA-\u06FC\u06FF\u0710\u0712-\u072F\u074D-\u07A5\u07B1\u07CA-\u07EA\u07F4\u07F5\u07FA\u0800-\u0815\u081A\u0824\u0828\u0840-\u0858\u08A0-\u08B2\u0904-\u0939\u093D\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098C\u098F\u0990\u0993-\u09A8\u09AA-\u09B0\u09B2\u09B6-\u09B9\u09BD\u09CE\u09DC\u09DD\u09DF-\u09E1\u09F0\u09F1\u0A05-\u0A0A\u0A0F\u0A10\u0A13-\u0A28\u0A2A-\u0A30\u0A32\u0A33\u0A35\u0A36\u0A38\u0A39\u0A59-\u0A5C\u0A5E\u0A72-\u0A74\u0A85-\u0A8D\u0A8F-\u0A91\u0A93-\u0AA8\u0AAA-\u0AB0\u0AB2\u0AB3\u0AB5-\u0AB9\u0ABD\u0AD0\u0AE0\u0AE1\u0B05-\u0B0C\u0B0F\u0B10\u0B13-\u0B28\u0B2A-\u0B30\u0B32\u0B33\u0B35-\u0B39\u0B3D\u0B5C\u0B5D\u0B5F-\u0B61\u0B71\u0B83\u0B85-\u0B8A\u0B8E-\u0B90\u0B92-\u0B95\u0B99\u0B9A\u0B9C\u0B9E\u0B9F\u0BA3\u0BA4\u0BA8-\u0BAA\u0BAE-\u0BB9\u0BD0\u0C05-\u0C0C\u0C0E-\u0C10\u0C12-\u0C28\u0C2A-\u0C39\u0C3D\u0C58\u0C59\u0C60\u0C61\u0C85-\u0C8C\u0C8E-\u0C90\u0C92-\u0CA8\u0CAA-\u0CB3\u0CB5-\u0CB9\u0CBD\u0CDE\u0CE0\u0CE1\u0CF1\u0CF2\u0D05-\u0D0C\u0D0E-\u0D10\u0D12-\u0D3A\u0D3D\u0D4E\u0D60\u0D61\u0D7A-\u0D7F\u0D85-\u0D96\u0D9A-\u0DB1\u0DB3-\u0DBB\u0DBD\u0DC0-\u0DC6\u0E01-\u0E30\u0E32\u0E33\u0E40-\u0E46\u0E81\u0E82\u0E84\u0E87\u0E88\u0E8A\u0E8D\u0E94-\u0E97\u0E99-\u0E9F\u0EA1-\u0EA3\u0EA5\u0EA7\u0EAA\u0EAB\u0EAD-\u0EB0\u0EB2\u0EB3\u0EBD\u0EC0-\u0EC4\u0EC6\u0EDC-\u0EDF\u0F00\u0F40-\u0F47\u0F49-\u0F6C\u0F88-\u0F8C\u1000-\u102A\u103F\u1050-\u1055\u105A-\u105D\u1061\u1065\u1066\u106E-\u1070\u1075-\u1081\u108E\u10A0-\u10C5\u10C7\u10CD\u10D0-\u10FA\u10FC-\u1248\u124A-\u124D\u1250-\u1256\u1258\u125A-\u125D\u1260-\u1288\u128A-\u128D\u1290-\u12B0\u12B2-\u12B5\u12B8-\u12BE\u12C0\u12C2-\u12C5\u12C8-\u12D6\u12D8-\u1310\u1312-\u1315\u1318-\u135A\u1380-\u138F\u13A0-\u13F4\u1401-\u166C\u166F-\u167F\u1681-\u169A\u16A0-\u16EA\u16F1-\u16F8\u1700-\u170C\u170E-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176C\u176E-\u1770\u1780-\u17B3\u17D7\u17DC\u1820-\u1877\u1880-\u18A8\u18AA\u18B0-\u18F5\u1900-\u191E\u1950-\u196D\u1970-\u1974\u1980-\u19AB\u19C1-\u19C7\u1A00-\u1A16\u1A20-\u1A54\u1AA7\u1B05-\u1B33\u1B45-\u1B4B\u1B83-\u1BA0\u1BAE\u1BAF\u1BBA-\u1BE5\u1C00-\u1C23\u1C4D-\u1C4F\u1C5A-\u1C7D\u1CE9-\u1CEC\u1CEE-\u1CF1\u1CF5\u1CF6\u1D00-\u1DBF\u1E00-\u1F15\u1F18-\u1F1D\u1F20-\u1F45\u1F48-\u1F4D\u1F50-\u1F57\u1F59\u1F5B\u1F5D\u1F5F-\u1F7D\u1F80-\u1FB4\u1FB6-\u1FBC\u1FBE\u1FC2-\u1FC4\u1FC6-\u1FCC\u1FD0-\u1FD3\u1FD6-\u1FDB\u1FE0-\u1FEC\u1FF2-\u1FF4\u1FF6-\u1FFC\u2071\u207F\u2090-\u209C\u2102\u2107\u210A-\u2113\u2115\u2119-\u211D\u2124\u2126\u2128\u212A-\u212D\u212F-\u2139\u213C-\u213F\u2145-\u2149\u214E\u2183\u2184\u2C00-\u2C2E\u2C30-\u2C5E\u2C60-\u2CE4\u2CEB-\u2CEE\u2CF2\u2CF3\u2D00-\u2D25\u2D27\u2D2D\u2D30-\u2D67\u2D6F\u2D80-\u2D96\u2DA0-\u2DA6\u2DA8-\u2DAE\u2DB0-\u2DB6\u2DB8-\u2DBE\u2DC0-\u2DC6\u2DC8-\u2DCE\u2DD0-\u2DD6\u2DD8-\u2DDE\u2E2F\u3005\u3006\u3031-\u3035\u303B\u303C\u3041-\u3096\u309D-\u309F\u30A1-\u30FA\u30FC-\u30FF\u3105-\u312D\u3131-\u318E\u31A0-\u31BA\u31F0-\u31FF\u3400-\u4DB5\u4E00-\u9FCC\uA000-\uA48C\uA4D0-\uA4FD\uA500-\uA60C\uA610-\uA61F\uA62A\uA62B\uA640-\uA66E\uA67F-\uA69D\uA6A0-\uA6E5\uA717-\uA71F\uA722-\uA788\uA78B-\uA78E\uA790-\uA7AD\uA7B0\uA7B1\uA7F7-\uA801\uA803-\uA805\uA807-\uA80A\uA80C-\uA822\uA840-\uA873\uA882-\uA8B3\uA8F2-\uA8F7\uA8FB\uA90A-\uA925\uA930-\uA946\uA960-\uA97C\uA984-\uA9B2\uA9CF\uA9E0-\uA9E4\uA9E6-\uA9EF\uA9FA-\uA9FE\uAA00-\uAA28\uAA40-\uAA42\uAA44-\uAA4B\uAA60-\uAA76\uAA7A\uAA7E-\uAAAF\uAAB1\uAAB5\uAAB6\uAAB9-\uAABD\uAAC0\uAAC2\uAADB-\uAADD\uAAE0-\uAAEA\uAAF2-\uAAF4\uAB01-\uAB06\uAB09-\uAB0E\uAB11-\uAB16\uAB20-\uAB26\uAB28-\uAB2E\uAB30-\uAB5A\uAB5C-\uAB5F\uAB64\uAB65\uABC0-\uABE2\uAC00-\uD7A3\uD7B0-\uD7C6\uD7CB-\uD7FB\uF900-\uFA6D\uFA70-\uFAD9\uFB00-\uFB06\uFB13-\uFB17\uFB1D\uFB1F-\uFB28\uFB2A-\uFB36\uFB38-\uFB3C\uFB3E\uFB40\uFB41\uFB43\uFB44\uFB46-\uFBB1\uFBD3-\uFD3D\uFD50-\uFD8F\uFD92-\uFDC7\uFDF0-\uFDFB\uFE70-\uFE74\uFE76-\uFEFC\uFF21-\uFF3A\uFF41-\uFF5A\uFF66-\uFFBE\uFFC2-\uFFC7\uFFCA-\uFFCF\uFFD2-\uFFD7\uFFDA-\uFFDC]|\uD800[\uDC00-\uDC0B\uDC0D-\uDC26\uDC28-\uDC3A\uDC3C\uDC3D\uDC3F-\uDC4D\uDC50-\uDC5D\uDC80-\uDCFA\uDE80-\uDE9C\uDEA0-\uDED0\uDF00-\uDF1F\uDF30-\uDF40\uDF42-\uDF49\uDF50-\uDF75\uDF80-\uDF9D\uDFA0-\uDFC3\uDFC8-\uDFCF]|\uD801[\uDC00-\uDC9D\uDD00-\uDD27\uDD30-\uDD63\uDE00-\uDF36\uDF40-\uDF55\uDF60-\uDF67]|\uD802[\uDC00-\uDC05\uDC08\uDC0A-\uDC35\uDC37\uDC38\uDC3C\uDC3F-\uDC55\uDC60-\uDC76\uDC80-\uDC9E\uDD00-\uDD15\uDD20-\uDD39\uDD80-\uDDB7\uDDBE\uDDBF\uDE00\uDE10-\uDE13\uDE15-\uDE17\uDE19-\uDE33\uDE60-\uDE7C\uDE80-\uDE9C\uDEC0-\uDEC7\uDEC9-\uDEE4\uDF00-\uDF35\uDF40-\uDF55\uDF60-\uDF72\uDF80-\uDF91]|\uD803[\uDC00-\uDC48]|\uD804[\uDC03-\uDC37\uDC83-\uDCAF\uDCD0-\uDCE8\uDD03-\uDD26\uDD50-\uDD72\uDD76\uDD83-\uDDB2\uDDC1-\uDDC4\uDDDA\uDE00-\uDE11\uDE13-\uDE2B\uDEB0-\uDEDE\uDF05-\uDF0C\uDF0F\uDF10\uDF13-\uDF28\uDF2A-\uDF30\uDF32\uDF33\uDF35-\uDF39\uDF3D\uDF5D-\uDF61]|\uD805[\uDC80-\uDCAF\uDCC4\uDCC5\uDCC7\uDD80-\uDDAE\uDE00-\uDE2F\uDE44\uDE80-\uDEAA]|\uD806[\uDCA0-\uDCDF\uDCFF\uDEC0-\uDEF8]|\uD808[\uDC00-\uDF98]|[\uD80C\uD840-\uD868\uD86A-\uD86C][\uDC00-\uDFFF]|\uD80D[\uDC00-\uDC2E]|\uD81A[\uDC00-\uDE38\uDE40-\uDE5E\uDED0-\uDEED\uDF00-\uDF2F\uDF40-\uDF43\uDF63-\uDF77\uDF7D-\uDF8F]|\uD81B[\uDF00-\uDF44\uDF50\uDF93-\uDF9F]|\uD82C[\uDC00\uDC01]|\uD82F[\uDC00-\uDC6A\uDC70-\uDC7C\uDC80-\uDC88\uDC90-\uDC99]|\uD835[\uDC00-\uDC54\uDC56-\uDC9C\uDC9E\uDC9F\uDCA2\uDCA5\uDCA6\uDCA9-\uDCAC\uDCAE-\uDCB9\uDCBB\uDCBD-\uDCC3\uDCC5-\uDD05\uDD07-\uDD0A\uDD0D-\uDD14\uDD16-\uDD1C\uDD1E-\uDD39\uDD3B-\uDD3E\uDD40-\uDD44\uDD46\uDD4A-\uDD50\uDD52-\uDEA5\uDEA8-\uDEC0\uDEC2-\uDEDA\uDEDC-\uDEFA\uDEFC-\uDF14\uDF16-\uDF34\uDF36-\uDF4E\uDF50-\uDF6E\uDF70-\uDF88\uDF8A-\uDFA8\uDFAA-\uDFC2\uDFC4-\uDFCB]|\uD83A[\uDC00-\uDCC4]|\uD83B[\uDE00-\uDE03\uDE05-\uDE1F\uDE21\uDE22\uDE24\uDE27\uDE29-\uDE32\uDE34-\uDE37\uDE39\uDE3B\uDE42\uDE47\uDE49\uDE4B\uDE4D-\uDE4F\uDE51\uDE52\uDE54\uDE57\uDE59\uDE5B\uDE5D\uDE5F\uDE61\uDE62\uDE64\uDE67-\uDE6A\uDE6C-\uDE72\uDE74-\uDE77\uDE79-\uDE7C\uDE7E\uDE80-\uDE89\uDE8B-\uDE9B\uDEA1-\uDEA3\uDEA5-\uDEA9\uDEAB-\uDEBB]|\uD869[\uDC00-\uDED6\uDF00-\uDFFF]|\uD86D[\uDC00-\uDF34\uDF40-\uDFFF]|\uD86E[\uDC00-\uDC1D]|\uD87E[\uDC00-\uDE1D]/u;
@@ -1,516 +0,0 @@
1
- /**
2
- * @fileoverview Validates JSDoc comments are syntactically correct
3
- * @author Nicholas C. Zakas
4
- * @deprecated in ESLint v5.10.0
5
- */
6
- "use strict";
7
-
8
- //------------------------------------------------------------------------------
9
- // Requirements
10
- //------------------------------------------------------------------------------
11
-
12
- const doctrine = require("doctrine");
13
-
14
- //------------------------------------------------------------------------------
15
- // Rule Definition
16
- //------------------------------------------------------------------------------
17
-
18
- /** @type {import('../shared/types').Rule} */
19
- module.exports = {
20
- meta: {
21
- type: "suggestion",
22
-
23
- docs: {
24
- description: "Enforce valid JSDoc comments",
25
- recommended: false,
26
- url: "https://eslint.org/docs/latest/rules/valid-jsdoc"
27
- },
28
-
29
- schema: [
30
- {
31
- type: "object",
32
- properties: {
33
- prefer: {
34
- type: "object",
35
- additionalProperties: {
36
- type: "string"
37
- }
38
- },
39
- preferType: {
40
- type: "object",
41
- additionalProperties: {
42
- type: "string"
43
- }
44
- },
45
- requireReturn: {
46
- type: "boolean",
47
- default: true
48
- },
49
- requireParamDescription: {
50
- type: "boolean",
51
- default: true
52
- },
53
- requireReturnDescription: {
54
- type: "boolean",
55
- default: true
56
- },
57
- matchDescription: {
58
- type: "string"
59
- },
60
- requireReturnType: {
61
- type: "boolean",
62
- default: true
63
- },
64
- requireParamType: {
65
- type: "boolean",
66
- default: true
67
- }
68
- },
69
- additionalProperties: false
70
- }
71
- ],
72
-
73
- fixable: "code",
74
- messages: {
75
- unexpectedTag: "Unexpected @{{title}} tag; function has no return statement.",
76
- expected: "Expected JSDoc for '{{name}}' but found '{{jsdocName}}'.",
77
- use: "Use @{{name}} instead.",
78
- useType: "Use '{{expectedTypeName}}' instead of '{{currentTypeName}}'.",
79
- syntaxError: "JSDoc syntax error.",
80
- missingBrace: "JSDoc type missing brace.",
81
- missingParamDesc: "Missing JSDoc parameter description for '{{name}}'.",
82
- missingParamType: "Missing JSDoc parameter type for '{{name}}'.",
83
- missingReturnType: "Missing JSDoc return type.",
84
- missingReturnDesc: "Missing JSDoc return description.",
85
- missingReturn: "Missing JSDoc @{{returns}} for function.",
86
- missingParam: "Missing JSDoc for parameter '{{name}}'.",
87
- duplicateParam: "Duplicate JSDoc parameter '{{name}}'.",
88
- unsatisfiedDesc: "JSDoc description does not satisfy the regex pattern."
89
- },
90
-
91
- deprecated: true,
92
- replacedBy: []
93
- },
94
-
95
- create(context) {
96
-
97
- const options = context.options[0] || {},
98
- prefer = options.prefer || {},
99
- sourceCode = context.sourceCode,
100
-
101
- // these both default to true, so you have to explicitly make them false
102
- requireReturn = options.requireReturn !== false,
103
- requireParamDescription = options.requireParamDescription !== false,
104
- requireReturnDescription = options.requireReturnDescription !== false,
105
- requireReturnType = options.requireReturnType !== false,
106
- requireParamType = options.requireParamType !== false,
107
- preferType = options.preferType || {},
108
- checkPreferType = Object.keys(preferType).length !== 0;
109
-
110
- //--------------------------------------------------------------------------
111
- // Helpers
112
- //--------------------------------------------------------------------------
113
-
114
- // Using a stack to store if a function returns or not (handling nested functions)
115
- const fns = [];
116
-
117
- /**
118
- * Check if node type is a Class
119
- * @param {ASTNode} node node to check.
120
- * @returns {boolean} True is its a class
121
- * @private
122
- */
123
- function isTypeClass(node) {
124
- return node.type === "ClassExpression" || node.type === "ClassDeclaration";
125
- }
126
-
127
- /**
128
- * When parsing a new function, store it in our function stack.
129
- * @param {ASTNode} node A function node to check.
130
- * @returns {void}
131
- * @private
132
- */
133
- function startFunction(node) {
134
- fns.push({
135
- returnPresent: (node.type === "ArrowFunctionExpression" && node.body.type !== "BlockStatement") ||
136
- isTypeClass(node) || node.async
137
- });
138
- }
139
-
140
- /**
141
- * Indicate that return has been found in the current function.
142
- * @param {ASTNode} node The return node.
143
- * @returns {void}
144
- * @private
145
- */
146
- function addReturn(node) {
147
- const functionState = fns[fns.length - 1];
148
-
149
- if (functionState && node.argument !== null) {
150
- functionState.returnPresent = true;
151
- }
152
- }
153
-
154
- /**
155
- * Check if return tag type is void or undefined
156
- * @param {Object} tag JSDoc tag
157
- * @returns {boolean} True if its of type void or undefined
158
- * @private
159
- */
160
- function isValidReturnType(tag) {
161
- return tag.type === null || tag.type.name === "void" || tag.type.type === "UndefinedLiteral";
162
- }
163
-
164
- /**
165
- * Check if type should be validated based on some exceptions
166
- * @param {Object} type JSDoc tag
167
- * @returns {boolean} True if it can be validated
168
- * @private
169
- */
170
- function canTypeBeValidated(type) {
171
- return type !== "UndefinedLiteral" && // {undefined} as there is no name property available.
172
- type !== "NullLiteral" && // {null}
173
- type !== "NullableLiteral" && // {?}
174
- type !== "FunctionType" && // {function(a)}
175
- type !== "AllLiteral"; // {*}
176
- }
177
-
178
- /**
179
- * Extract the current and expected type based on the input type object
180
- * @param {Object} type JSDoc tag
181
- * @returns {{currentType: Doctrine.Type, expectedTypeName: string}} The current type annotation and
182
- * the expected name of the annotation
183
- * @private
184
- */
185
- function getCurrentExpectedTypes(type) {
186
- let currentType;
187
-
188
- if (type.name) {
189
- currentType = type;
190
- } else if (type.expression) {
191
- currentType = type.expression;
192
- }
193
-
194
- return {
195
- currentType,
196
- expectedTypeName: currentType && preferType[currentType.name]
197
- };
198
- }
199
-
200
- /**
201
- * Gets the location of a JSDoc node in a file
202
- * @param {Token} jsdocComment The comment that this node is parsed from
203
- * @param {{range: number[]}} parsedJsdocNode A tag or other node which was parsed from this comment
204
- * @returns {{start: SourceLocation, end: SourceLocation}} The 0-based source location for the tag
205
- */
206
- function getAbsoluteRange(jsdocComment, parsedJsdocNode) {
207
- return {
208
- start: sourceCode.getLocFromIndex(jsdocComment.range[0] + 2 + parsedJsdocNode.range[0]),
209
- end: sourceCode.getLocFromIndex(jsdocComment.range[0] + 2 + parsedJsdocNode.range[1])
210
- };
211
- }
212
-
213
- /**
214
- * Validate type for a given JSDoc node
215
- * @param {Object} jsdocNode JSDoc node
216
- * @param {Object} type JSDoc tag
217
- * @returns {void}
218
- * @private
219
- */
220
- function validateType(jsdocNode, type) {
221
- if (!type || !canTypeBeValidated(type.type)) {
222
- return;
223
- }
224
-
225
- const typesToCheck = [];
226
- let elements = [];
227
-
228
- switch (type.type) {
229
- case "TypeApplication": // {Array.<String>}
230
- elements = type.applications[0].type === "UnionType" ? type.applications[0].elements : type.applications;
231
- typesToCheck.push(getCurrentExpectedTypes(type));
232
- break;
233
- case "RecordType": // {{20:String}}
234
- elements = type.fields;
235
- break;
236
- case "UnionType": // {String|number|Test}
237
- case "ArrayType": // {[String, number, Test]}
238
- elements = type.elements;
239
- break;
240
- case "FieldType": // Array.<{count: number, votes: number}>
241
- if (type.value) {
242
- typesToCheck.push(getCurrentExpectedTypes(type.value));
243
- }
244
- break;
245
- default:
246
- typesToCheck.push(getCurrentExpectedTypes(type));
247
- }
248
-
249
- elements.forEach(validateType.bind(null, jsdocNode));
250
-
251
- typesToCheck.forEach(typeToCheck => {
252
- if (typeToCheck.expectedTypeName &&
253
- typeToCheck.expectedTypeName !== typeToCheck.currentType.name) {
254
- context.report({
255
- node: jsdocNode,
256
- messageId: "useType",
257
- loc: getAbsoluteRange(jsdocNode, typeToCheck.currentType),
258
- data: {
259
- currentTypeName: typeToCheck.currentType.name,
260
- expectedTypeName: typeToCheck.expectedTypeName
261
- },
262
- fix(fixer) {
263
- return fixer.replaceTextRange(
264
- typeToCheck.currentType.range.map(indexInComment => jsdocNode.range[0] + 2 + indexInComment),
265
- typeToCheck.expectedTypeName
266
- );
267
- }
268
- });
269
- }
270
- });
271
- }
272
-
273
- /**
274
- * Validate the JSDoc node and output warnings if anything is wrong.
275
- * @param {ASTNode} node The AST node to check.
276
- * @returns {void}
277
- * @private
278
- */
279
- function checkJSDoc(node) {
280
- const jsdocNode = sourceCode.getJSDocComment(node),
281
- functionData = fns.pop(),
282
- paramTagsByName = Object.create(null),
283
- paramTags = [];
284
- let hasReturns = false,
285
- returnsTag,
286
- hasConstructor = false,
287
- isInterface = false,
288
- isOverride = false,
289
- isAbstract = false;
290
-
291
- // make sure only to validate JSDoc comments
292
- if (jsdocNode) {
293
- let jsdoc;
294
-
295
- try {
296
- jsdoc = doctrine.parse(jsdocNode.value, {
297
- strict: true,
298
- unwrap: true,
299
- sloppy: true,
300
- range: true
301
- });
302
- } catch (ex) {
303
-
304
- if (/braces/iu.test(ex.message)) {
305
- context.report({ node: jsdocNode, messageId: "missingBrace" });
306
- } else {
307
- context.report({ node: jsdocNode, messageId: "syntaxError" });
308
- }
309
-
310
- return;
311
- }
312
-
313
- jsdoc.tags.forEach(tag => {
314
-
315
- switch (tag.title.toLowerCase()) {
316
-
317
- case "param":
318
- case "arg":
319
- case "argument":
320
- paramTags.push(tag);
321
- break;
322
-
323
- case "return":
324
- case "returns":
325
- hasReturns = true;
326
- returnsTag = tag;
327
- break;
328
-
329
- case "constructor":
330
- case "class":
331
- hasConstructor = true;
332
- break;
333
-
334
- case "override":
335
- case "inheritdoc":
336
- isOverride = true;
337
- break;
338
-
339
- case "abstract":
340
- case "virtual":
341
- isAbstract = true;
342
- break;
343
-
344
- case "interface":
345
- isInterface = true;
346
- break;
347
-
348
- // no default
349
- }
350
-
351
- // check tag preferences
352
- if (Object.prototype.hasOwnProperty.call(prefer, tag.title) && tag.title !== prefer[tag.title]) {
353
- const entireTagRange = getAbsoluteRange(jsdocNode, tag);
354
-
355
- context.report({
356
- node: jsdocNode,
357
- messageId: "use",
358
- loc: {
359
- start: entireTagRange.start,
360
- end: {
361
- line: entireTagRange.start.line,
362
- column: entireTagRange.start.column + `@${tag.title}`.length
363
- }
364
- },
365
- data: { name: prefer[tag.title] },
366
- fix(fixer) {
367
- return fixer.replaceTextRange(
368
- [
369
- jsdocNode.range[0] + tag.range[0] + 3,
370
- jsdocNode.range[0] + tag.range[0] + tag.title.length + 3
371
- ],
372
- prefer[tag.title]
373
- );
374
- }
375
- });
376
- }
377
-
378
- // validate the types
379
- if (checkPreferType && tag.type) {
380
- validateType(jsdocNode, tag.type);
381
- }
382
- });
383
-
384
- paramTags.forEach(param => {
385
- if (requireParamType && !param.type) {
386
- context.report({
387
- node: jsdocNode,
388
- messageId: "missingParamType",
389
- loc: getAbsoluteRange(jsdocNode, param),
390
- data: { name: param.name }
391
- });
392
- }
393
- if (!param.description && requireParamDescription) {
394
- context.report({
395
- node: jsdocNode,
396
- messageId: "missingParamDesc",
397
- loc: getAbsoluteRange(jsdocNode, param),
398
- data: { name: param.name }
399
- });
400
- }
401
- if (paramTagsByName[param.name]) {
402
- context.report({
403
- node: jsdocNode,
404
- messageId: "duplicateParam",
405
- loc: getAbsoluteRange(jsdocNode, param),
406
- data: { name: param.name }
407
- });
408
- } else if (!param.name.includes(".")) {
409
- paramTagsByName[param.name] = param;
410
- }
411
- });
412
-
413
- if (hasReturns) {
414
- if (!requireReturn && !functionData.returnPresent && (returnsTag.type === null || !isValidReturnType(returnsTag)) && !isAbstract) {
415
- context.report({
416
- node: jsdocNode,
417
- messageId: "unexpectedTag",
418
- loc: getAbsoluteRange(jsdocNode, returnsTag),
419
- data: {
420
- title: returnsTag.title
421
- }
422
- });
423
- } else {
424
- if (requireReturnType && !returnsTag.type) {
425
- context.report({ node: jsdocNode, messageId: "missingReturnType" });
426
- }
427
-
428
- if (!isValidReturnType(returnsTag) && !returnsTag.description && requireReturnDescription) {
429
- context.report({ node: jsdocNode, messageId: "missingReturnDesc" });
430
- }
431
- }
432
- }
433
-
434
- // check for functions missing @returns
435
- if (!isOverride && !hasReturns && !hasConstructor && !isInterface &&
436
- node.parent.kind !== "get" && node.parent.kind !== "constructor" &&
437
- node.parent.kind !== "set" && !isTypeClass(node)) {
438
- if (requireReturn || (functionData.returnPresent && !node.async)) {
439
- context.report({
440
- node: jsdocNode,
441
- messageId: "missingReturn",
442
- data: {
443
- returns: prefer.returns || "returns"
444
- }
445
- });
446
- }
447
- }
448
-
449
- // check the parameters
450
- const jsdocParamNames = Object.keys(paramTagsByName);
451
-
452
- if (node.params) {
453
- node.params.forEach((param, paramsIndex) => {
454
- const bindingParam = param.type === "AssignmentPattern"
455
- ? param.left
456
- : param;
457
-
458
- // TODO(nzakas): Figure out logical things to do with destructured, default, rest params
459
- if (bindingParam.type === "Identifier") {
460
- const name = bindingParam.name;
461
-
462
- if (jsdocParamNames[paramsIndex] && (name !== jsdocParamNames[paramsIndex])) {
463
- context.report({
464
- node: jsdocNode,
465
- messageId: "expected",
466
- loc: getAbsoluteRange(jsdocNode, paramTagsByName[jsdocParamNames[paramsIndex]]),
467
- data: {
468
- name,
469
- jsdocName: jsdocParamNames[paramsIndex]
470
- }
471
- });
472
- } else if (!paramTagsByName[name] && !isOverride) {
473
- context.report({
474
- node: jsdocNode,
475
- messageId: "missingParam",
476
- data: {
477
- name
478
- }
479
- });
480
- }
481
- }
482
- });
483
- }
484
-
485
- if (options.matchDescription) {
486
- const regex = new RegExp(options.matchDescription, "u");
487
-
488
- if (!regex.test(jsdoc.description)) {
489
- context.report({ node: jsdocNode, messageId: "unsatisfiedDesc" });
490
- }
491
- }
492
-
493
- }
494
-
495
- }
496
-
497
- //--------------------------------------------------------------------------
498
- // Public
499
- //--------------------------------------------------------------------------
500
-
501
- return {
502
- ArrowFunctionExpression: startFunction,
503
- FunctionExpression: startFunction,
504
- FunctionDeclaration: startFunction,
505
- ClassExpression: startFunction,
506
- ClassDeclaration: startFunction,
507
- "ArrowFunctionExpression:exit": checkJSDoc,
508
- "FunctionExpression:exit": checkJSDoc,
509
- "FunctionDeclaration:exit": checkJSDoc,
510
- "ClassExpression:exit": checkJSDoc,
511
- "ClassDeclaration:exit": checkJSDoc,
512
- ReturnStatement: addReturn
513
- };
514
-
515
- }
516
- };