eslint 8.0.0-beta.0 → 8.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 (333) hide show
  1. package/README.md +4 -4
  2. package/bin/eslint.js +1 -1
  3. package/conf/eslint-recommended.js +1 -1
  4. package/conf/{category-list.json → rule-type-list.json} +4 -7
  5. package/lib/cli-engine/cli-engine.js +11 -3
  6. package/lib/cli-engine/file-enumerator.js +4 -3
  7. package/lib/cli-engine/formatters/html.js +1 -1
  8. package/lib/cli-engine/hash.js +2 -2
  9. package/lib/cli-engine/xml-escape.js +1 -1
  10. package/lib/config/flat-config-array.js +2 -2
  11. package/lib/config/flat-config-schema.js +1 -1
  12. package/lib/config/rule-validator.js +25 -8
  13. package/lib/eslint/eslint.js +4 -0
  14. package/lib/init/autoconfig.js +17 -18
  15. package/lib/init/config-file.js +3 -3
  16. package/lib/init/config-initializer.js +11 -10
  17. package/lib/init/config-rule.js +15 -16
  18. package/lib/init/npm-utils.js +16 -15
  19. package/lib/init/source-code-utils.js +6 -5
  20. package/lib/linter/apply-disable-directives.js +80 -11
  21. package/lib/linter/code-path-analysis/code-path-analyzer.js +115 -36
  22. package/lib/linter/code-path-analysis/code-path-segment.js +0 -1
  23. package/lib/linter/code-path-analysis/code-path-state.js +4 -1
  24. package/lib/linter/code-path-analysis/code-path.js +14 -5
  25. package/lib/linter/code-path-analysis/debug-helpers.js +2 -2
  26. package/lib/linter/code-path-analysis/fork-context.js +0 -1
  27. package/lib/linter/code-path-analysis/id-generator.js +0 -1
  28. package/lib/linter/config-comment-parser.js +1 -1
  29. package/lib/linter/linter.js +51 -22
  30. package/lib/linter/node-event-generator.js +0 -1
  31. package/lib/linter/report-translator.js +12 -12
  32. package/lib/linter/rules.js +3 -0
  33. package/lib/linter/safe-emitter.js +2 -2
  34. package/lib/linter/source-code-fixer.js +2 -2
  35. package/lib/linter/timing.js +2 -2
  36. package/lib/rule-tester/rule-tester.js +12 -2
  37. package/lib/rules/accessor-pairs.js +0 -1
  38. package/lib/rules/array-bracket-newline.js +0 -1
  39. package/lib/rules/array-bracket-spacing.js +0 -1
  40. package/lib/rules/array-callback-return.js +0 -1
  41. package/lib/rules/array-element-newline.js +0 -1
  42. package/lib/rules/arrow-body-style.js +0 -1
  43. package/lib/rules/arrow-parens.js +0 -1
  44. package/lib/rules/arrow-spacing.js +0 -1
  45. package/lib/rules/block-scoped-var.js +0 -1
  46. package/lib/rules/block-spacing.js +0 -1
  47. package/lib/rules/brace-style.js +0 -1
  48. package/lib/rules/callback-return.js +1 -1
  49. package/lib/rules/camelcase.js +17 -19
  50. package/lib/rules/capitalized-comments.js +0 -1
  51. package/lib/rules/class-methods-use-this.js +51 -9
  52. package/lib/rules/comma-dangle.js +0 -1
  53. package/lib/rules/comma-spacing.js +0 -1
  54. package/lib/rules/comma-style.js +0 -1
  55. package/lib/rules/complexity.js +47 -56
  56. package/lib/rules/computed-property-spacing.js +0 -1
  57. package/lib/rules/consistent-return.js +0 -1
  58. package/lib/rules/consistent-this.js +1 -2
  59. package/lib/rules/constructor-super.js +0 -1
  60. package/lib/rules/curly.js +0 -1
  61. package/lib/rules/default-case-last.js +0 -1
  62. package/lib/rules/default-case.js +2 -3
  63. package/lib/rules/default-param-last.js +1 -2
  64. package/lib/rules/dot-location.js +0 -1
  65. package/lib/rules/dot-notation.js +0 -1
  66. package/lib/rules/eol-last.js +6 -2
  67. package/lib/rules/eqeqeq.js +1 -2
  68. package/lib/rules/for-direction.js +0 -1
  69. package/lib/rules/func-call-spacing.js +0 -1
  70. package/lib/rules/func-name-matching.js +9 -6
  71. package/lib/rules/func-names.js +0 -1
  72. package/lib/rules/func-style.js +0 -1
  73. package/lib/rules/function-call-argument-newline.js +0 -1
  74. package/lib/rules/function-paren-newline.js +1 -1
  75. package/lib/rules/generator-star-spacing.js +0 -1
  76. package/lib/rules/getter-return.js +0 -1
  77. package/lib/rules/global-require.js +1 -1
  78. package/lib/rules/grouped-accessor-pairs.js +0 -1
  79. package/lib/rules/guard-for-in.js +0 -1
  80. package/lib/rules/handle-callback-err.js +1 -1
  81. package/lib/rules/id-blacklist.js +1 -1
  82. package/lib/rules/id-denylist.js +0 -1
  83. package/lib/rules/id-length.js +0 -1
  84. package/lib/rules/id-match.js +0 -1
  85. package/lib/rules/implicit-arrow-linebreak.js +0 -1
  86. package/lib/rules/indent-legacy.js +1 -1
  87. package/lib/rules/indent.js +7 -10
  88. package/lib/rules/index.js +1 -1
  89. package/lib/rules/init-declarations.js +0 -1
  90. package/lib/rules/jsx-quotes.js +0 -1
  91. package/lib/rules/key-spacing.js +4 -5
  92. package/lib/rules/keyword-spacing.js +19 -3
  93. package/lib/rules/line-comment-position.js +0 -1
  94. package/lib/rules/linebreak-style.js +0 -1
  95. package/lib/rules/lines-around-comment.js +0 -1
  96. package/lib/rules/lines-around-directive.js +1 -2
  97. package/lib/rules/lines-between-class-members.js +50 -3
  98. package/lib/rules/max-classes-per-file.js +31 -8
  99. package/lib/rules/max-depth.js +0 -1
  100. package/lib/rules/max-len.js +1 -2
  101. package/lib/rules/max-lines-per-function.js +1 -2
  102. package/lib/rules/max-lines.js +0 -1
  103. package/lib/rules/max-nested-callbacks.js +0 -1
  104. package/lib/rules/max-params.js +0 -1
  105. package/lib/rules/max-statements-per-line.js +0 -1
  106. package/lib/rules/max-statements.js +0 -1
  107. package/lib/rules/multiline-comment-style.js +0 -1
  108. package/lib/rules/multiline-ternary.js +0 -1
  109. package/lib/rules/new-cap.js +2 -2
  110. package/lib/rules/new-parens.js +0 -1
  111. package/lib/rules/newline-after-var.js +4 -5
  112. package/lib/rules/newline-before-return.js +2 -3
  113. package/lib/rules/newline-per-chained-call.js +1 -2
  114. package/lib/rules/no-alert.js +0 -1
  115. package/lib/rules/no-array-constructor.js +0 -1
  116. package/lib/rules/no-async-promise-executor.js +0 -1
  117. package/lib/rules/no-await-in-loop.js +0 -1
  118. package/lib/rules/no-bitwise.js +5 -6
  119. package/lib/rules/no-buffer-constructor.js +1 -1
  120. package/lib/rules/no-caller.js +0 -1
  121. package/lib/rules/no-case-declarations.js +0 -1
  122. package/lib/rules/no-catch-shadow.js +0 -1
  123. package/lib/rules/no-class-assign.js +0 -1
  124. package/lib/rules/no-compare-neg-zero.js +0 -1
  125. package/lib/rules/no-cond-assign.js +0 -1
  126. package/lib/rules/no-confusing-arrow.js +0 -1
  127. package/lib/rules/no-console.js +0 -1
  128. package/lib/rules/no-const-assign.js +0 -1
  129. package/lib/rules/no-constant-condition.js +0 -1
  130. package/lib/rules/no-constructor-return.js +0 -1
  131. package/lib/rules/no-continue.js +0 -1
  132. package/lib/rules/no-control-regex.js +0 -1
  133. package/lib/rules/no-debugger.js +0 -1
  134. package/lib/rules/no-delete-var.js +0 -1
  135. package/lib/rules/no-div-regex.js +0 -1
  136. package/lib/rules/no-dupe-args.js +0 -1
  137. package/lib/rules/no-dupe-class-members.js +0 -1
  138. package/lib/rules/no-dupe-else-if.js +0 -1
  139. package/lib/rules/no-dupe-keys.js +0 -2
  140. package/lib/rules/no-duplicate-case.js +0 -1
  141. package/lib/rules/no-duplicate-imports.js +0 -1
  142. package/lib/rules/no-else-return.js +0 -1
  143. package/lib/rules/no-empty-character-class.js +0 -1
  144. package/lib/rules/no-empty-function.js +0 -1
  145. package/lib/rules/no-empty-pattern.js +0 -1
  146. package/lib/rules/no-empty.js +0 -1
  147. package/lib/rules/no-eq-null.js +0 -1
  148. package/lib/rules/no-eval.js +0 -1
  149. package/lib/rules/no-ex-assign.js +0 -1
  150. package/lib/rules/no-extend-native.js +0 -1
  151. package/lib/rules/no-extra-bind.js +0 -1
  152. package/lib/rules/no-extra-boolean-cast.js +1 -1
  153. package/lib/rules/no-extra-label.js +0 -1
  154. package/lib/rules/no-extra-parens.js +0 -1
  155. package/lib/rules/no-extra-semi.js +0 -1
  156. package/lib/rules/no-fallthrough.js +0 -1
  157. package/lib/rules/no-floating-decimal.js +0 -1
  158. package/lib/rules/no-func-assign.js +0 -1
  159. package/lib/rules/no-global-assign.js +0 -1
  160. package/lib/rules/no-implicit-coercion.js +0 -1
  161. package/lib/rules/no-implicit-globals.js +0 -1
  162. package/lib/rules/no-implied-eval.js +0 -1
  163. package/lib/rules/no-import-assign.js +0 -1
  164. package/lib/rules/no-inline-comments.js +0 -1
  165. package/lib/rules/no-inner-declarations.js +0 -1
  166. package/lib/rules/no-invalid-regexp.js +0 -1
  167. package/lib/rules/no-invalid-this.js +0 -1
  168. package/lib/rules/no-irregular-whitespace.js +0 -1
  169. package/lib/rules/no-iterator.js +0 -1
  170. package/lib/rules/no-label-var.js +0 -1
  171. package/lib/rules/no-labels.js +0 -1
  172. package/lib/rules/no-lone-blocks.js +0 -1
  173. package/lib/rules/no-lonely-if.js +0 -1
  174. package/lib/rules/no-loop-func.js +1 -2
  175. package/lib/rules/no-loss-of-precision.js +0 -1
  176. package/lib/rules/no-magic-numbers.js +0 -1
  177. package/lib/rules/no-misleading-character-class.js +0 -1
  178. package/lib/rules/no-mixed-operators.js +1 -2
  179. package/lib/rules/no-mixed-requires.js +1 -1
  180. package/lib/rules/no-mixed-spaces-and-tabs.js +0 -1
  181. package/lib/rules/no-multi-assign.js +0 -1
  182. package/lib/rules/no-multi-spaces.js +0 -1
  183. package/lib/rules/no-multi-str.js +0 -1
  184. package/lib/rules/no-multiple-empty-lines.js +0 -1
  185. package/lib/rules/no-native-reassign.js +0 -1
  186. package/lib/rules/no-negated-condition.js +0 -1
  187. package/lib/rules/no-negated-in-lhs.js +0 -1
  188. package/lib/rules/no-nested-ternary.js +0 -1
  189. package/lib/rules/no-new-func.js +34 -7
  190. package/lib/rules/no-new-object.js +0 -1
  191. package/lib/rules/no-new-require.js +1 -1
  192. package/lib/rules/no-new-symbol.js +0 -1
  193. package/lib/rules/no-new-wrappers.js +0 -1
  194. package/lib/rules/no-new.js +0 -1
  195. package/lib/rules/no-nonoctal-decimal-escape.js +0 -1
  196. package/lib/rules/no-obj-calls.js +0 -1
  197. package/lib/rules/no-octal-escape.js +0 -1
  198. package/lib/rules/no-octal.js +0 -1
  199. package/lib/rules/no-param-reassign.js +0 -1
  200. package/lib/rules/no-path-concat.js +1 -1
  201. package/lib/rules/no-plusplus.js +0 -1
  202. package/lib/rules/no-process-env.js +1 -1
  203. package/lib/rules/no-process-exit.js +1 -1
  204. package/lib/rules/no-promise-executor-return.js +0 -1
  205. package/lib/rules/no-proto.js +0 -1
  206. package/lib/rules/no-prototype-builtins.js +0 -1
  207. package/lib/rules/no-redeclare.js +0 -1
  208. package/lib/rules/no-regex-spaces.js +0 -1
  209. package/lib/rules/no-restricted-exports.js +0 -1
  210. package/lib/rules/no-restricted-globals.js +1 -2
  211. package/lib/rules/no-restricted-imports.js +5 -6
  212. package/lib/rules/no-restricted-modules.js +3 -3
  213. package/lib/rules/no-restricted-properties.js +2 -3
  214. package/lib/rules/no-restricted-syntax.js +1 -2
  215. package/lib/rules/no-return-assign.js +0 -1
  216. package/lib/rules/no-return-await.js +0 -1
  217. package/lib/rules/no-script-url.js +1 -3
  218. package/lib/rules/no-self-assign.js +0 -1
  219. package/lib/rules/no-self-compare.js +0 -1
  220. package/lib/rules/no-sequences.js +0 -1
  221. package/lib/rules/no-setter-return.js +0 -1
  222. package/lib/rules/no-shadow-restricted-names.js +0 -1
  223. package/lib/rules/no-shadow.js +1 -2
  224. package/lib/rules/no-spaced-func.js +0 -1
  225. package/lib/rules/no-sparse-arrays.js +0 -1
  226. package/lib/rules/no-sync.js +1 -3
  227. package/lib/rules/no-tabs.js +0 -1
  228. package/lib/rules/no-template-curly-in-string.js +0 -1
  229. package/lib/rules/no-ternary.js +0 -1
  230. package/lib/rules/no-this-before-super.js +0 -1
  231. package/lib/rules/no-throw-literal.js +0 -1
  232. package/lib/rules/no-trailing-spaces.js +0 -1
  233. package/lib/rules/no-undef-init.js +9 -61
  234. package/lib/rules/no-undef.js +0 -1
  235. package/lib/rules/no-undefined.js +0 -1
  236. package/lib/rules/no-underscore-dangle.js +0 -1
  237. package/lib/rules/no-unexpected-multiline.js +0 -1
  238. package/lib/rules/no-unmodified-loop-condition.js +0 -1
  239. package/lib/rules/no-unneeded-ternary.js +0 -1
  240. package/lib/rules/no-unreachable-loop.js +0 -1
  241. package/lib/rules/no-unreachable.js +26 -25
  242. package/lib/rules/no-unsafe-finally.js +0 -1
  243. package/lib/rules/no-unsafe-negation.js +0 -1
  244. package/lib/rules/no-unsafe-optional-chaining.js +0 -1
  245. package/lib/rules/no-unused-expressions.js +4 -5
  246. package/lib/rules/no-unused-labels.js +0 -1
  247. package/lib/rules/no-unused-vars.js +26 -28
  248. package/lib/rules/no-use-before-define.js +0 -1
  249. package/lib/rules/no-useless-backreference.js +0 -1
  250. package/lib/rules/no-useless-call.js +0 -1
  251. package/lib/rules/no-useless-catch.js +0 -1
  252. package/lib/rules/no-useless-computed-key.js +1 -1
  253. package/lib/rules/no-useless-concat.js +0 -1
  254. package/lib/rules/no-useless-constructor.js +0 -1
  255. package/lib/rules/no-useless-escape.js +9 -9
  256. package/lib/rules/no-useless-rename.js +0 -1
  257. package/lib/rules/no-useless-return.js +0 -1
  258. package/lib/rules/no-var.js +0 -1
  259. package/lib/rules/no-void.js +0 -1
  260. package/lib/rules/no-warning-comments.js +0 -1
  261. package/lib/rules/no-whitespace-before-property.js +0 -1
  262. package/lib/rules/no-with.js +0 -1
  263. package/lib/rules/nonblock-statement-body-position.js +0 -1
  264. package/lib/rules/object-curly-newline.js +0 -1
  265. package/lib/rules/object-curly-spacing.js +0 -1
  266. package/lib/rules/object-property-newline.js +0 -1
  267. package/lib/rules/object-shorthand.js +3 -8
  268. package/lib/rules/one-var-declaration-per-line.js +0 -1
  269. package/lib/rules/one-var.js +1 -2
  270. package/lib/rules/operator-assignment.js +6 -7
  271. package/lib/rules/operator-linebreak.js +0 -1
  272. package/lib/rules/padded-blocks.js +1 -1
  273. package/lib/rules/padding-line-between-statements.js +0 -1
  274. package/lib/rules/prefer-arrow-callback.js +1 -1
  275. package/lib/rules/prefer-const.js +0 -1
  276. package/lib/rules/prefer-destructuring.js +1 -2
  277. package/lib/rules/prefer-exponentiation-operator.js +0 -1
  278. package/lib/rules/prefer-named-capture-group.js +0 -1
  279. package/lib/rules/prefer-numeric-literals.js +0 -1
  280. package/lib/rules/prefer-object-spread.js +0 -1
  281. package/lib/rules/prefer-promise-reject-errors.js +0 -1
  282. package/lib/rules/prefer-reflect.js +0 -1
  283. package/lib/rules/prefer-regex-literals.js +0 -1
  284. package/lib/rules/prefer-rest-params.js +0 -1
  285. package/lib/rules/prefer-spread.js +0 -1
  286. package/lib/rules/prefer-template.js +0 -1
  287. package/lib/rules/quote-props.js +8 -9
  288. package/lib/rules/quotes.js +0 -1
  289. package/lib/rules/radix.js +0 -1
  290. package/lib/rules/require-atomic-updates.js +24 -9
  291. package/lib/rules/require-await.js +0 -1
  292. package/lib/rules/require-jsdoc.js +1 -1
  293. package/lib/rules/require-unicode-regexp.js +0 -1
  294. package/lib/rules/require-yield.js +0 -1
  295. package/lib/rules/rest-spread-spacing.js +0 -1
  296. package/lib/rules/semi-spacing.js +0 -1
  297. package/lib/rules/semi-style.js +0 -1
  298. package/lib/rules/semi.js +66 -6
  299. package/lib/rules/sort-imports.js +0 -1
  300. package/lib/rules/sort-keys.js +0 -1
  301. package/lib/rules/sort-vars.js +0 -1
  302. package/lib/rules/space-before-blocks.js +14 -3
  303. package/lib/rules/space-before-function-paren.js +0 -1
  304. package/lib/rules/space-in-parens.js +0 -1
  305. package/lib/rules/space-infix-ops.js +0 -1
  306. package/lib/rules/space-unary-ops.js +0 -1
  307. package/lib/rules/spaced-comment.js +0 -1
  308. package/lib/rules/strict.js +0 -1
  309. package/lib/rules/switch-colon-spacing.js +1 -14
  310. package/lib/rules/symbol-description.js +0 -1
  311. package/lib/rules/template-curly-spacing.js +0 -1
  312. package/lib/rules/template-tag-spacing.js +0 -1
  313. package/lib/rules/unicode-bom.js +0 -1
  314. package/lib/rules/use-isnan.js +0 -1
  315. package/lib/rules/utils/ast-utils.js +29 -7
  316. package/lib/rules/utils/lazy-loading-rule-map.js +3 -3
  317. package/lib/rules/valid-jsdoc.js +1 -1
  318. package/lib/rules/valid-typeof.js +0 -1
  319. package/lib/rules/vars-on-top.js +1 -2
  320. package/lib/rules/wrap-iife.js +0 -1
  321. package/lib/rules/wrap-regex.js +0 -1
  322. package/lib/rules/yield-star-spacing.js +0 -1
  323. package/lib/rules/yoda.js +0 -1
  324. package/lib/shared/ajv.js +1 -1
  325. package/lib/shared/config-validator.js +10 -5
  326. package/lib/shared/logging.js +1 -1
  327. package/lib/shared/relative-module-resolver.js +1 -0
  328. package/lib/shared/runtime-info.js +3 -0
  329. package/lib/shared/traverser.js +2 -2
  330. package/lib/shared/types.js +2 -2
  331. package/lib/source-code/source-code.js +11 -5
  332. package/lib/source-code/token-store/cursor.js +1 -1
  333. package/package.json +5 -5
@@ -50,8 +50,8 @@ const parserSymbol = Symbol.for("eslint.RuleTester.parser");
50
50
  // Typedefs
51
51
  //------------------------------------------------------------------------------
52
52
 
53
- /** @typedef {InstanceType<import("../cli-engine/config-array")["ConfigArray"]>} ConfigArray */
54
- /** @typedef {InstanceType<import("../cli-engine/config-array")["ExtractedConfig"]>} ExtractedConfig */
53
+ /** @typedef {InstanceType<import("../cli-engine/config-array").ConfigArray>} ConfigArray */
54
+ /** @typedef {InstanceType<import("../cli-engine/config-array").ExtractedConfig>} ExtractedConfig */
55
55
  /** @typedef {import("../shared/types").ConfigData} ConfigData */
56
56
  /** @typedef {import("../shared/types").Environment} Environment */
57
57
  /** @typedef {import("../shared/types").GlobalConf} GlobalConf */
@@ -60,17 +60,19 @@ const parserSymbol = Symbol.for("eslint.RuleTester.parser");
60
60
  /** @typedef {import("../shared/types").Processor} Processor */
61
61
  /** @typedef {import("../shared/types").Rule} Rule */
62
62
 
63
+ /* eslint-disable jsdoc/valid-types -- https://github.com/jsdoc-type-pratt-parser/jsdoc-type-pratt-parser/issues/4#issuecomment-778805577 */
63
64
  /**
64
65
  * @template T
65
66
  * @typedef {{ [P in keyof T]-?: T[P] }} Required
66
67
  */
68
+ /* eslint-enable jsdoc/valid-types -- https://github.com/jsdoc-type-pratt-parser/jsdoc-type-pratt-parser/issues/4#issuecomment-778805577 */
67
69
 
68
70
  /**
69
71
  * @typedef {Object} DisableDirective
70
- * @property {("disable"|"enable"|"disable-line"|"disable-next-line")} type
71
- * @property {number} line
72
- * @property {number} column
73
- * @property {(string|null)} ruleId
72
+ * @property {("disable"|"enable"|"disable-line"|"disable-next-line")} type Type of directive
73
+ * @property {number} line The line number
74
+ * @property {number} column The column number
75
+ * @property {(string|null)} ruleId The rule ID
74
76
  */
75
77
 
76
78
  /**
@@ -98,12 +100,12 @@ const parserSymbol = Symbol.for("eslint.RuleTester.parser");
98
100
  * @typedef {Object} ProcessorOptions
99
101
  * @property {(filename:string, text:string) => boolean} [filterCodeBlock] the
100
102
  * predicate function that selects adopt code blocks.
101
- * @property {Processor["postprocess"]} [postprocess] postprocessor for report
103
+ * @property {Processor.postprocess} [postprocess] postprocessor for report
102
104
  * messages. If provided, this should accept an array of the message lists
103
105
  * for each code block returned from the preprocessor, apply a mapping to
104
106
  * the messages as appropriate, and return a one-dimensional array of
105
107
  * messages.
106
- * @property {Processor["preprocess"]} [preprocess] preprocessor for source text.
108
+ * @property {Processor.preprocess} [preprocess] preprocessor for source text.
107
109
  * If provided, this should accept a string of source text, and return an
108
110
  * array of code blocks to lint.
109
111
  */
@@ -313,7 +315,11 @@ function getDirectiveComments(filename, ast, ruleMapper, warnInlineConfig) {
313
315
  return;
314
316
  }
315
317
  const directiveText = match[1];
316
- const mustBeOnSingleLine = /^eslint-disable-(next-)?line$/u.test(directiveText);
318
+ const lineCommentSupported = /^eslint-disable-(next-)?line$/u.test(directiveText);
319
+
320
+ if (comment.type === "Line" && !lineCommentSupported) {
321
+ return;
322
+ }
317
323
 
318
324
  if (warnInlineConfig) {
319
325
  const kind = comment.type === "Block" ? `/*${directiveText}*/` : `//${directiveText}`;
@@ -327,7 +333,7 @@ function getDirectiveComments(filename, ast, ruleMapper, warnInlineConfig) {
327
333
  return;
328
334
  }
329
335
 
330
- if (mustBeOnSingleLine && comment.loc.start.line !== comment.loc.end.line) {
336
+ if (lineCommentSupported && comment.loc.start.line !== comment.loc.end.line) {
331
337
  const message = `${directiveText} comment should not span multiple lines.`;
332
338
 
333
339
  problems.push(createLintingProblem({
@@ -454,10 +460,7 @@ function normalizeEcmaVersion(parser, ecmaVersion) {
454
460
  return ecmaVersion >= 2015 ? ecmaVersion - 2009 : ecmaVersion;
455
461
  }
456
462
 
457
- const eslintEnvPatterns = [
458
- /\/\*\s*eslint-env\s(.+?)\*\//gsu, // block comments
459
- /\/\/[^\S\r\n\u2028\u2029]*eslint-env[^\S\r\n\u2028\u2029](.+)/gu // line comments
460
- ];
463
+ const eslintEnvPattern = /\/\*\s*eslint-env\s(.+?)(?:\*\/|$)/gsu;
461
464
 
462
465
  /**
463
466
  * Checks whether or not there is a comment which has "eslint-env *" in a given text.
@@ -467,16 +470,17 @@ const eslintEnvPatterns = [
467
470
  function findEslintEnv(text) {
468
471
  let match, retv;
469
472
 
470
- for (const eslintEnvPattern of eslintEnvPatterns) {
471
- eslintEnvPattern.lastIndex = 0;
473
+ eslintEnvPattern.lastIndex = 0;
472
474
 
473
- while ((match = eslintEnvPattern.exec(text)) !== null) {
475
+ while ((match = eslintEnvPattern.exec(text)) !== null) {
476
+ if (match[0].endsWith("*/")) {
474
477
  retv = Object.assign(
475
478
  retv || {},
476
479
  commentParser.parseListConfig(stripDirectiveComment(match[1]))
477
480
  );
478
481
  }
479
482
  }
483
+
480
484
  return retv;
481
485
  }
482
486
 
@@ -764,6 +768,7 @@ function markVariableAsUsed(scopeManager, currentNode, parserOptions, name) {
764
768
  * Runs a rule, and gets its listeners
765
769
  * @param {Rule} rule A normalized rule with a `create` method
766
770
  * @param {Context} ruleContext The context that should be passed to the rule
771
+ * @throws {any} Any error during the rule's `create`
767
772
  * @returns {Object} A map of selector listeners provided by the rule
768
773
  */
769
774
  function createRuleListeners(rule, ruleContext) {
@@ -950,13 +955,31 @@ function runRules(sourceCode, configuredRules, ruleMapper, parserOptions, parser
950
955
 
951
956
  const ruleListeners = createRuleListeners(rule, ruleContext);
952
957
 
958
+ /**
959
+ * Include `ruleId` in error logs
960
+ * @param {Function} ruleListener A rule method that listens for a node.
961
+ * @returns {Function} ruleListener wrapped in error handler
962
+ */
963
+ function addRuleErrorHandler(ruleListener) {
964
+ return function ruleErrorHandler(...listenerArgs) {
965
+ try {
966
+ return ruleListener(...listenerArgs);
967
+ } catch (e) {
968
+ e.ruleId = ruleId;
969
+ throw e;
970
+ }
971
+ };
972
+ }
973
+
953
974
  // add all the selectors from the rule as listeners
954
975
  Object.keys(ruleListeners).forEach(selector => {
976
+ const ruleListener = timing.enabled
977
+ ? timing.time(ruleId, ruleListeners[selector])
978
+ : ruleListeners[selector];
979
+
955
980
  emitter.on(
956
981
  selector,
957
- timing.enabled
958
- ? timing.time(ruleId, ruleListeners[selector])
959
- : ruleListeners[selector]
982
+ addRuleErrorHandler(ruleListener)
960
983
  );
961
984
  });
962
985
  });
@@ -1041,7 +1064,7 @@ function normalizeCwd(cwd) {
1041
1064
  }
1042
1065
 
1043
1066
  // It's more explicit to assign the undefined
1044
- // eslint-disable-next-line no-undefined
1067
+ // eslint-disable-next-line no-undefined -- Consistently returning a value
1045
1068
  return undefined;
1046
1069
  }
1047
1070
 
@@ -1064,7 +1087,7 @@ class Linter {
1064
1087
  /**
1065
1088
  * Initialize the Linter.
1066
1089
  * @param {Object} [config] the config object
1067
- * @param {string} [config.cwd] path to a directory that should be considered as the current working directory, can be undefined.
1090
+ * @param {string} [config.cwd] path to a directory that should be considered as the current working directory, can be undefined.
1068
1091
  */
1069
1092
  constructor({ cwd } = {}) {
1070
1093
  internalSlotsMap.set(this, {
@@ -1092,6 +1115,7 @@ class Linter {
1092
1115
  * @param {string|SourceCode} textOrSourceCode The text to parse or a SourceCode object.
1093
1116
  * @param {ConfigData} providedConfig An ESLintConfig instance to configure everything.
1094
1117
  * @param {VerifyOptions} [providedOptions] The optional filename of the file being checked.
1118
+ * @throws {Error} If during rule execution.
1095
1119
  * @returns {LintMessage[]} The results as an array of messages or an empty array if no messages.
1096
1120
  */
1097
1121
  _verifyWithoutProcessors(textOrSourceCode, providedConfig, providedOptions) {
@@ -1217,6 +1241,11 @@ class Linter {
1217
1241
  debug("Parser Options:", parserOptions);
1218
1242
  debug("Parser Path:", parserName);
1219
1243
  debug("Settings:", settings);
1244
+
1245
+ if (err.ruleId) {
1246
+ err.message += `\nRule: "${err.ruleId}"`;
1247
+ }
1248
+
1220
1249
  throw err;
1221
1250
  }
1222
1251
 
@@ -237,7 +237,6 @@ function parseSelector(rawSelector) {
237
237
  */
238
238
  class NodeEventGenerator {
239
239
 
240
- // eslint-disable-next-line jsdoc/require-description
241
240
  /**
242
241
  * @param {SafeEmitter} emitter
243
242
  * An SafeEmitter which is the destination of events. This emitter must already
@@ -32,18 +32,18 @@ const interpolate = require("./interpolate");
32
32
  /**
33
33
  * Information about the report
34
34
  * @typedef {Object} ReportInfo
35
- * @property {string} ruleId
36
- * @property {(0|1|2)} severity
37
- * @property {(string|undefined)} message
38
- * @property {(string|undefined)} [messageId]
39
- * @property {number} line
40
- * @property {number} column
41
- * @property {(number|undefined)} [endLine]
42
- * @property {(number|undefined)} [endColumn]
43
- * @property {(string|null)} nodeType
44
- * @property {string} source
45
- * @property {({text: string, range: (number[]|null)}|null)} [fix]
46
- * @property {Array<{text: string, range: (number[]|null)}|null>} [suggestions]
35
+ * @property {string} ruleId The rule ID
36
+ * @property {(0|1|2)} severity Severity of the error
37
+ * @property {(string|undefined)} message The message
38
+ * @property {(string|undefined)} [messageId] The message ID
39
+ * @property {number} line The line number
40
+ * @property {number} column The column number
41
+ * @property {(number|undefined)} [endLine] The ending line number
42
+ * @property {(number|undefined)} [endColumn] The ending column number
43
+ * @property {(string|null)} nodeType Type of node
44
+ * @property {string} source Source text
45
+ * @property {({text: string, range: (number[]|null)}|null)} [fix] The fix object
46
+ * @property {Array<{text: string, range: (number[]|null)}|null>} [suggestions] Suggestion info
47
47
  */
48
48
 
49
49
  //------------------------------------------------------------------------------
@@ -30,6 +30,9 @@ function normalizeRule(rule) {
30
30
  // Public Interface
31
31
  //------------------------------------------------------------------------------
32
32
 
33
+ /**
34
+ * A storage for rules.
35
+ */
33
36
  class Rules {
34
37
  constructor() {
35
38
  this._rules = Object.create(null);
@@ -12,8 +12,8 @@
12
12
  /**
13
13
  * An event emitter
14
14
  * @typedef {Object} SafeEmitter
15
- * @property {function(eventName: string, listenerFunc: Function): void} on Adds a listener for a given event name
16
- * @property {function(eventName: string, arg1?: any, arg2?: any, arg3?: any)} emit Emits an event with a given name.
15
+ * @property {(eventName: string, listenerFunc: Function) => void} on Adds a listener for a given event name
16
+ * @property {(eventName: string, arg1?: any, arg2?: any, arg3?: any) => void} emit Emits an event with a given name.
17
17
  * This calls all the listeners that were listening for that name, with `arg1`, `arg2`, and `arg3` as arguments.
18
18
  * @property {function(): string[]} eventNames Gets the list of event names that have registered listeners.
19
19
  */
@@ -80,8 +80,8 @@ SourceCodeFixer.applyFixes = function(sourceText, messages, shouldFix) {
80
80
 
81
81
  /**
82
82
  * Try to use the 'fix' from a problem.
83
- * @param {Message} problem The message object to apply fixes from
84
- * @returns {boolean} Whether fix was successfully applied
83
+ * @param {Message} problem The message object to apply fixes from
84
+ * @returns {boolean} Whether fix was successfully applied
85
85
  */
86
86
  function attemptFix(problem) {
87
87
  const fix = problem.fix;
@@ -116,7 +116,7 @@ function display(data) {
116
116
  return ALIGN[index](":", width + extraAlignment, "-");
117
117
  }).join("|"));
118
118
 
119
- console.log(table.join("\n")); // eslint-disable-line no-console
119
+ console.log(table.join("\n")); // eslint-disable-line no-console -- Debugging function
120
120
  }
121
121
 
122
122
  /* istanbul ignore next */
@@ -126,7 +126,7 @@ module.exports = (function() {
126
126
 
127
127
  /**
128
128
  * Time the run
129
- * @param {*} key key from the data object
129
+ * @param {any} key key from the data object
130
130
  * @param {Function} fn function to be called
131
131
  * @returns {Function} function to be executed
132
132
  * @private
@@ -4,7 +4,7 @@
4
4
  */
5
5
  "use strict";
6
6
 
7
- /* global describe, it */
7
+ /* eslint-env mocha -- Mocha wrapper */
8
8
 
9
9
  /*
10
10
  * This is a wrapper around mocha to allow for DRY unittests for eslint
@@ -63,6 +63,7 @@ const { SourceCode } = require("../source-code");
63
63
 
64
64
  /** @typedef {import("../shared/types").Parser} Parser */
65
65
 
66
+ /* eslint-disable jsdoc/valid-types -- https://github.com/jsdoc-type-pratt-parser/jsdoc-type-pratt-parser/issues/4#issuecomment-778805577 */
66
67
  /**
67
68
  * A test case that is expected to pass lint.
68
69
  * @typedef {Object} ValidTestCase
@@ -105,6 +106,7 @@ const { SourceCode } = require("../source-code");
105
106
  * @property {number} [endLine] The 1-based line number of the reported end location.
106
107
  * @property {number} [endColumn] The 1-based column number of the reported end location.
107
108
  */
109
+ /* eslint-enable jsdoc/valid-types -- https://github.com/jsdoc-type-pratt-parser/jsdoc-type-pratt-parser/issues/4#issuecomment-778805577 */
108
110
 
109
111
  //------------------------------------------------------------------------------
110
112
  // Private Members
@@ -212,7 +214,7 @@ function freezeDeeply(x) {
212
214
  */
213
215
  function sanitize(text) {
214
216
  return text.replace(
215
- /[\u0000-\u0009\u000b-\u001a]/gu, // eslint-disable-line no-control-regex
217
+ /[\u0000-\u0009\u000b-\u001a]/gu, // eslint-disable-line no-control-regex -- Escaping controls
216
218
  c => `\\u${c.codePointAt(0).toString(16).padStart(4, "0")}`
217
219
  );
218
220
  }
@@ -311,6 +313,7 @@ const IT_ONLY = Symbol("itOnly");
311
313
  * @this {Mocha}
312
314
  * @param {string} text The description of the test case.
313
315
  * @param {Function} method The logic of the test case.
316
+ * @throws {Error} Any error upon execution of `method`.
314
317
  * @returns {any} Returned value of `method`.
315
318
  */
316
319
  function itDefaultHandler(text, method) {
@@ -335,6 +338,9 @@ function describeDefaultHandler(text, method) {
335
338
  return method.call(this);
336
339
  }
337
340
 
341
+ /**
342
+ * Mocha test wrapper.
343
+ */
338
344
  class RuleTester {
339
345
 
340
346
  /**
@@ -366,6 +372,7 @@ class RuleTester {
366
372
  /**
367
373
  * Set the configuration to use for all future tests
368
374
  * @param {Object} config the configuration to use.
375
+ * @throws {TypeError} If non-object config.
369
376
  * @returns {void}
370
377
  */
371
378
  static setDefaultConfig(config) {
@@ -481,6 +488,8 @@ class RuleTester {
481
488
  * valid: (ValidTestCase | string)[],
482
489
  * invalid: InvalidTestCase[]
483
490
  * }} test The collection of tests to run.
491
+ * @throws {TypeError|Error} If non-object `test`, or if a required
492
+ * scenario of the given type is missing.
484
493
  * @returns {void}
485
494
  */
486
495
  run(ruleName, rule, test) {
@@ -524,6 +533,7 @@ class RuleTester {
524
533
  /**
525
534
  * Run the rule for the given item
526
535
  * @param {string|Object} item Item to run the rule against
536
+ * @throws {Error} If an invalid schema.
527
537
  * @returns {Object} Eslint run result
528
538
  * @private
529
539
  */
@@ -140,7 +140,6 @@ module.exports = {
140
140
 
141
141
  docs: {
142
142
  description: "enforce getter and setter pairs in objects and classes",
143
- category: "Best Practices",
144
143
  recommended: false,
145
144
  url: "https://eslint.org/docs/rules/accessor-pairs"
146
145
  },
@@ -17,7 +17,6 @@ module.exports = {
17
17
 
18
18
  docs: {
19
19
  description: "enforce linebreaks after opening and before closing array brackets",
20
- category: "Stylistic Issues",
21
20
  recommended: false,
22
21
  url: "https://eslint.org/docs/rules/array-bracket-newline"
23
22
  },
@@ -16,7 +16,6 @@ module.exports = {
16
16
 
17
17
  docs: {
18
18
  description: "enforce consistent spacing inside array brackets",
19
- category: "Stylistic Issues",
20
19
  recommended: false,
21
20
  url: "https://eslint.org/docs/rules/array-bracket-spacing"
22
21
  },
@@ -139,7 +139,6 @@ module.exports = {
139
139
 
140
140
  docs: {
141
141
  description: "enforce `return` statements in callbacks of array methods",
142
- category: "Best Practices",
143
142
  recommended: false,
144
143
  url: "https://eslint.org/docs/rules/array-callback-return"
145
144
  },
@@ -17,7 +17,6 @@ module.exports = {
17
17
 
18
18
  docs: {
19
19
  description: "enforce line breaks after each array element",
20
- category: "Stylistic Issues",
21
20
  recommended: false,
22
21
  url: "https://eslint.org/docs/rules/array-element-newline"
23
22
  },
@@ -20,7 +20,6 @@ module.exports = {
20
20
 
21
21
  docs: {
22
22
  description: "require braces around arrow function bodies",
23
- category: "ECMAScript 6",
24
23
  recommended: false,
25
24
  url: "https://eslint.org/docs/rules/arrow-body-style"
26
25
  },
@@ -33,7 +33,6 @@ module.exports = {
33
33
 
34
34
  docs: {
35
35
  description: "require parentheses around arrow function arguments",
36
- category: "ECMAScript 6",
37
36
  recommended: false,
38
37
  url: "https://eslint.org/docs/rules/arrow-parens"
39
38
  },
@@ -20,7 +20,6 @@ module.exports = {
20
20
 
21
21
  docs: {
22
22
  description: "enforce consistent spacing before and after the arrow in arrow functions",
23
- category: "ECMAScript 6",
24
23
  recommended: false,
25
24
  url: "https://eslint.org/docs/rules/arrow-spacing"
26
25
  },
@@ -14,7 +14,6 @@ module.exports = {
14
14
 
15
15
  docs: {
16
16
  description: "enforce the use of variables within the scope they are defined",
17
- category: "Best Practices",
18
17
  recommended: false,
19
18
  url: "https://eslint.org/docs/rules/block-scoped-var"
20
19
  },
@@ -17,7 +17,6 @@ module.exports = {
17
17
 
18
18
  docs: {
19
19
  description: "disallow or enforce spaces inside of blocks after opening block and before closing block",
20
- category: "Stylistic Issues",
21
20
  recommended: false,
22
21
  url: "https://eslint.org/docs/rules/block-spacing"
23
22
  },
@@ -17,7 +17,6 @@ module.exports = {
17
17
 
18
18
  docs: {
19
19
  description: "enforce consistent brace style for blocks",
20
- category: "Stylistic Issues",
21
20
  recommended: false,
22
21
  url: "https://eslint.org/docs/rules/brace-style"
23
22
  },
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * @fileoverview Enforce return after a callback.
3
3
  * @author Jamund Ferguson
4
+ * @deprecated in ESLint v7.0.0
4
5
  */
5
6
  "use strict";
6
7
 
@@ -18,7 +19,6 @@ module.exports = {
18
19
 
19
20
  docs: {
20
21
  description: "require `return` statements after callbacks",
21
- category: "Node.js and CommonJS",
22
22
  recommended: false,
23
23
  url: "https://eslint.org/docs/rules/callback-return"
24
24
  },
@@ -15,7 +15,6 @@ module.exports = {
15
15
 
16
16
  docs: {
17
17
  description: "enforce camelcase naming convention",
18
- category: "Stylistic Issues",
19
18
  recommended: false,
20
19
  url: "https://eslint.org/docs/rules/camelcase"
21
20
  },
@@ -240,27 +239,26 @@ module.exports = {
240
239
 
241
240
  // Report camelcase of global variable references ------------------
242
241
  Program() {
243
- if (ignoreGlobals) {
244
- return;
245
- }
246
-
247
242
  const scope = context.getScope();
248
243
 
249
- // Defined globals in config files or directive comments.
250
- for (const variable of scope.variables) {
251
- if (
252
- variable.identifiers.length > 0 ||
253
- isGoodName(variable.name)
254
- ) {
255
- continue;
256
- }
257
- for (const reference of variable.references) {
244
+ if (!ignoreGlobals) {
258
245
 
259
- /*
260
- * For backward compatibility, this rule reports read-only
261
- * references as well.
262
- */
263
- reportReferenceId(reference.identifier);
246
+ // Defined globals in config files or directive comments.
247
+ for (const variable of scope.variables) {
248
+ if (
249
+ variable.identifiers.length > 0 ||
250
+ isGoodName(variable.name)
251
+ ) {
252
+ continue;
253
+ }
254
+ for (const reference of variable.references) {
255
+
256
+ /*
257
+ * For backward compatibility, this rule reports read-only
258
+ * references as well.
259
+ */
260
+ reportReferenceId(reference.identifier);
261
+ }
264
262
  }
265
263
  }
266
264
 
@@ -105,7 +105,6 @@ module.exports = {
105
105
 
106
106
  docs: {
107
107
  description: "enforce or disallow capitalization of the first letter of a comment",
108
- category: "Stylistic Issues",
109
108
  recommended: false,
110
109
  url: "https://eslint.org/docs/rules/capitalized-comments"
111
110
  },
@@ -21,7 +21,6 @@ module.exports = {
21
21
 
22
22
  docs: {
23
23
  description: "enforce that class methods utilize `this`",
24
- category: "Best Practices",
25
24
  recommended: false,
26
25
  url: "https://eslint.org/docs/rules/class-methods-use-this"
27
26
  },
@@ -34,6 +33,10 @@ module.exports = {
34
33
  items: {
35
34
  type: "string"
36
35
  }
36
+ },
37
+ enforceForClassFields: {
38
+ type: "boolean",
39
+ default: true
37
40
  }
38
41
  },
39
42
  additionalProperties: false
@@ -45,10 +48,27 @@ module.exports = {
45
48
  },
46
49
  create(context) {
47
50
  const config = Object.assign({}, context.options[0]);
51
+ const enforceForClassFields = config.enforceForClassFields !== false;
48
52
  const exceptMethods = new Set(config.exceptMethods || []);
49
53
 
50
54
  const stack = [];
51
55
 
56
+ /**
57
+ * Push `this` used flag initialized with `false` onto the stack.
58
+ * @returns {void}
59
+ */
60
+ function pushContext() {
61
+ stack.push(false);
62
+ }
63
+
64
+ /**
65
+ * Pop `this` used flag from the stack.
66
+ * @returns {boolean | undefined} `this` used flag
67
+ */
68
+ function popContext() {
69
+ return stack.pop();
70
+ }
71
+
52
72
  /**
53
73
  * Initializes the current context to false and pushes it onto the stack.
54
74
  * These booleans represent whether 'this' has been used in the context.
@@ -56,7 +76,7 @@ module.exports = {
56
76
  * @private
57
77
  */
58
78
  function enterFunction() {
59
- stack.push(false);
79
+ pushContext();
60
80
  }
61
81
 
62
82
  /**
@@ -70,7 +90,7 @@ module.exports = {
70
90
  case "MethodDefinition":
71
91
  return !node.static && node.kind !== "constructor";
72
92
  case "PropertyDefinition":
73
- return !node.static;
93
+ return !node.static && enforceForClassFields;
74
94
  default:
75
95
  return false;
76
96
  }
@@ -83,8 +103,19 @@ module.exports = {
83
103
  * @private
84
104
  */
85
105
  function isIncludedInstanceMethod(node) {
86
- return isInstanceMethod(node) &&
87
- (node.computed || !exceptMethods.has(node.key.name));
106
+ if (isInstanceMethod(node)) {
107
+ if (node.computed) {
108
+ return true;
109
+ }
110
+
111
+ const hashIfNeeded = node.key.type === "PrivateIdentifier" ? "#" : "";
112
+ const name = node.key.type === "Literal"
113
+ ? astUtils.getStaticStringValue(node.key)
114
+ : (node.key.name || "");
115
+
116
+ return !exceptMethods.has(hashIfNeeded + name);
117
+ }
118
+ return false;
88
119
  }
89
120
 
90
121
  /**
@@ -96,7 +127,7 @@ module.exports = {
96
127
  * @private
97
128
  */
98
129
  function exitFunction(node) {
99
- const methodUsesThis = stack.pop();
130
+ const methodUsesThis = popContext();
100
131
 
101
132
  if (isIncludedInstanceMethod(node.parent) && !methodUsesThis) {
102
133
  context.report({
@@ -126,10 +157,21 @@ module.exports = {
126
157
  "FunctionDeclaration:exit": exitFunction,
127
158
  FunctionExpression: enterFunction,
128
159
  "FunctionExpression:exit": exitFunction,
129
- "PropertyDefinition > ArrowFunctionExpression.value": enterFunction,
130
- "PropertyDefinition > ArrowFunctionExpression.value:exit": exitFunction,
160
+
161
+ /*
162
+ * Class field value are implicit functions.
163
+ */
164
+ "PropertyDefinition:exit": popContext,
165
+ "PropertyDefinition > *.key:exit": pushContext,
166
+
131
167
  ThisExpression: markThisUsed,
132
- Super: markThisUsed
168
+ Super: markThisUsed,
169
+ ...(
170
+ enforceForClassFields && {
171
+ "PropertyDefinition > ArrowFunctionExpression.value": enterFunction,
172
+ "PropertyDefinition > ArrowFunctionExpression.value:exit": exitFunction
173
+ }
174
+ )
133
175
  };
134
176
  }
135
177
  };
@@ -76,7 +76,6 @@ module.exports = {
76
76
 
77
77
  docs: {
78
78
  description: "require or disallow trailing commas",
79
- category: "Stylistic Issues",
80
79
  recommended: false,
81
80
  url: "https://eslint.org/docs/rules/comma-dangle"
82
81
  },