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
@@ -139,7 +139,6 @@ module.exports = {
139
139
 
140
140
  docs: {
141
141
  description: "enforce consistent spacing between keys and values in object literal properties",
142
- category: "Stylistic Issues",
143
142
  recommended: false,
144
143
  url: "https://eslint.org/docs/rules/key-spacing"
145
144
  },
@@ -531,8 +530,8 @@ module.exports = {
531
530
 
532
531
  /**
533
532
  * Creates groups of properties.
534
- * @param {ASTNode} node ObjectExpression node being evaluated.
535
- * @returns {Array.<ASTNode[]>} Groups of property AST node lists.
533
+ * @param {ASTNode} node ObjectExpression node being evaluated.
534
+ * @returns {Array<ASTNode[]>} Groups of property AST node lists.
536
535
  */
537
536
  function createGroups(node) {
538
537
  if (node.properties.length === 1) {
@@ -600,7 +599,7 @@ module.exports = {
600
599
 
601
600
  /**
602
601
  * Verifies spacing of property conforms to specified options.
603
- * @param {ASTNode} node Property node being evaluated.
602
+ * @param {ASTNode} node Property node being evaluated.
604
603
  * @param {Object} lineOptions Configured singleLine or multiLine options
605
604
  * @returns {void}
606
605
  */
@@ -629,7 +628,7 @@ module.exports = {
629
628
 
630
629
  /**
631
630
  * Verifies vertical alignment, taking into account groups of properties.
632
- * @param {ASTNode} node ObjectExpression node being evaluated.
631
+ * @param {ASTNode} node ObjectExpression node being evaluated.
633
632
  * @returns {void}
634
633
  */
635
634
  function verifyAlignment(node) {
@@ -67,7 +67,6 @@ module.exports = {
67
67
 
68
68
  docs: {
69
69
  description: "enforce consistent spacing before and after keywords",
70
- category: "Stylistic Issues",
71
70
  recommended: false,
72
71
  url: "https://eslint.org/docs/rules/keyword-spacing"
73
72
  },
@@ -403,7 +402,15 @@ module.exports = {
403
402
  */
404
403
  function checkSpacingForForInStatement(node) {
405
404
  checkSpacingAroundFirstToken(node);
406
- checkSpacingAroundTokenBefore(node.right);
405
+
406
+ const inToken = sourceCode.getTokenBefore(node.right, astUtils.isNotOpeningParenToken);
407
+ const previousToken = sourceCode.getTokenBefore(inToken);
408
+
409
+ if (previousToken.type !== "PrivateIdentifier") {
410
+ checkSpacingBefore(inToken);
411
+ }
412
+
413
+ checkSpacingAfter(inToken);
407
414
  }
408
415
 
409
416
  /**
@@ -419,7 +426,15 @@ module.exports = {
419
426
  } else {
420
427
  checkSpacingAroundFirstToken(node);
421
428
  }
422
- checkSpacingAround(sourceCode.getTokenBefore(node.right, astUtils.isNotOpeningParenToken));
429
+
430
+ const ofToken = sourceCode.getTokenBefore(node.right, astUtils.isNotOpeningParenToken);
431
+ const previousToken = sourceCode.getTokenBefore(ofToken);
432
+
433
+ if (previousToken.type !== "PrivateIdentifier") {
434
+ checkSpacingBefore(ofToken);
435
+ }
436
+
437
+ checkSpacingAfter(ofToken);
423
438
  }
424
439
 
425
440
  /**
@@ -473,6 +488,7 @@ module.exports = {
473
488
  * Reports `static`, `get`, and `set` keywords of a given node if usage of
474
489
  * spacing around those keywords is invalid.
475
490
  * @param {ASTNode} node A node to report.
491
+ * @throws {Error} If unable to find token get, set, or async beside method name.
476
492
  * @returns {void}
477
493
  */
478
494
  function checkSpacingForProperty(node) {
@@ -16,7 +16,6 @@ module.exports = {
16
16
 
17
17
  docs: {
18
18
  description: "enforce position of line comments",
19
- category: "Stylistic Issues",
20
19
  recommended: false,
21
20
  url: "https://eslint.org/docs/rules/line-comment-position"
22
21
  },
@@ -21,7 +21,6 @@ module.exports = {
21
21
 
22
22
  docs: {
23
23
  description: "enforce consistent linebreak style",
24
- category: "Stylistic Issues",
25
24
  recommended: false,
26
25
  url: "https://eslint.org/docs/rules/linebreak-style"
27
26
  },
@@ -55,7 +55,6 @@ module.exports = {
55
55
 
56
56
  docs: {
57
57
  description: "require empty lines around comments",
58
- category: "Stylistic Issues",
59
58
  recommended: false,
60
59
  url: "https://eslint.org/docs/rules/lines-around-comment"
61
60
  },
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @fileoverview Require or disallow newlines around directives.
3
3
  * @author Kai Cataldo
4
- * @deprecated
4
+ * @deprecated in ESLint v4.0.0
5
5
  */
6
6
 
7
7
  "use strict";
@@ -18,7 +18,6 @@ module.exports = {
18
18
 
19
19
  docs: {
20
20
  description: "require or disallow newlines around directives",
21
- category: "Stylistic Issues",
22
21
  recommended: false,
23
22
  url: "https://eslint.org/docs/rules/lines-around-directive"
24
23
  },
@@ -4,6 +4,10 @@
4
4
  */
5
5
  "use strict";
6
6
 
7
+ //------------------------------------------------------------------------------
8
+ // Requirements
9
+ //------------------------------------------------------------------------------
10
+
7
11
  const astUtils = require("./utils/ast-utils");
8
12
 
9
13
  //------------------------------------------------------------------------------
@@ -16,7 +20,6 @@ module.exports = {
16
20
 
17
21
  docs: {
18
22
  description: "require or disallow an empty line between class members",
19
- category: "Stylistic Issues",
20
23
  recommended: false,
21
24
  url: "https://eslint.org/docs/rules/lines-between-class-members"
22
25
  },
@@ -53,6 +56,51 @@ module.exports = {
53
56
 
54
57
  const sourceCode = context.getSourceCode();
55
58
 
59
+ /**
60
+ * Gets a pair of tokens that should be used to check lines between two class member nodes.
61
+ *
62
+ * In most cases, this returns the very last token of the current node and
63
+ * the very first token of the next node.
64
+ * For example:
65
+ *
66
+ * class C {
67
+ * x = 1; // curLast: `;` nextFirst: `in`
68
+ * in = 2
69
+ * }
70
+ *
71
+ * There is only one exception. If the given node ends with a semicolon, and it looks like
72
+ * a semicolon-less style's semicolon - one that is not on the same line as the preceding
73
+ * token, but is on the line where the next class member starts - this returns the preceding
74
+ * token and the semicolon as boundary tokens.
75
+ * For example:
76
+ *
77
+ * class C {
78
+ * x = 1 // curLast: `1` nextFirst: `;`
79
+ * ;in = 2
80
+ * }
81
+ * When determining the desired layout of the code, we should treat this semicolon as
82
+ * a part of the next class member node instead of the one it technically belongs to.
83
+ * @param {ASTNode} curNode Current class member node.
84
+ * @param {ASTNode} nextNode Next class member node.
85
+ * @returns {Token} The actual last token of `node`.
86
+ * @private
87
+ */
88
+ function getBoundaryTokens(curNode, nextNode) {
89
+ const lastToken = sourceCode.getLastToken(curNode);
90
+ const prevToken = sourceCode.getTokenBefore(lastToken);
91
+ const nextToken = sourceCode.getFirstToken(nextNode); // skip possible lone `;` between nodes
92
+
93
+ const isSemicolonLessStyle = (
94
+ astUtils.isSemicolonToken(lastToken) &&
95
+ !astUtils.isTokenOnSameLine(prevToken, lastToken) &&
96
+ astUtils.isTokenOnSameLine(lastToken, nextToken)
97
+ );
98
+
99
+ return isSemicolonLessStyle
100
+ ? { curLast: prevToken, nextFirst: lastToken }
101
+ : { curLast: lastToken, nextFirst: nextToken };
102
+ }
103
+
56
104
  /**
57
105
  * Return the last token among the consecutive tokens that have no exceed max line difference in between, before the first token in the next member.
58
106
  * @param {Token} prevLastToken The last token in the previous member node.
@@ -101,8 +149,7 @@ module.exports = {
101
149
 
102
150
  for (let i = 0; i < body.length - 1; i++) {
103
151
  const curFirst = sourceCode.getFirstToken(body[i]);
104
- const curLast = sourceCode.getLastToken(body[i]);
105
- const nextFirst = sourceCode.getFirstToken(body[i + 1]);
152
+ const { curLast, nextFirst } = getBoundaryTokens(body[i], body[i + 1]);
106
153
  const isMulti = !astUtils.isTokenOnSameLine(curFirst, curLast);
107
154
  const skip = !isMulti && options[1].exceptAfterSingleLine;
108
155
  const beforePadding = findLastConsecutiveTokenAfter(curLast, nextFirst, 1);
@@ -19,15 +19,31 @@ module.exports = {
19
19
 
20
20
  docs: {
21
21
  description: "enforce a maximum number of classes per file",
22
- category: "Best Practices",
23
22
  recommended: false,
24
23
  url: "https://eslint.org/docs/rules/max-classes-per-file"
25
24
  },
26
25
 
27
26
  schema: [
28
27
  {
29
- type: "integer",
30
- minimum: 1
28
+ oneOf: [
29
+ {
30
+ type: "integer",
31
+ minimum: 1
32
+ },
33
+ {
34
+ type: "object",
35
+ properties: {
36
+ ignoreExpressions: {
37
+ type: "boolean"
38
+ },
39
+ max: {
40
+ type: "integer",
41
+ minimum: 1
42
+ }
43
+ },
44
+ additionalProperties: false
45
+ }
46
+ ]
31
47
  }
32
48
  ],
33
49
 
@@ -36,8 +52,10 @@ module.exports = {
36
52
  }
37
53
  },
38
54
  create(context) {
39
-
40
- const maxClasses = context.options[0] || 1;
55
+ const [option = {}] = context.options;
56
+ const [ignoreExpressions, max] = typeof option === "number"
57
+ ? [false, option || 1]
58
+ : [option.ignoreExpressions, option.max || 1];
41
59
 
42
60
  let classCount = 0;
43
61
 
@@ -46,19 +64,24 @@ module.exports = {
46
64
  classCount = 0;
47
65
  },
48
66
  "Program:exit"(node) {
49
- if (classCount > maxClasses) {
67
+ if (classCount > max) {
50
68
  context.report({
51
69
  node,
52
70
  messageId: "maximumExceeded",
53
71
  data: {
54
72
  classCount,
55
- max: maxClasses
73
+ max
56
74
  }
57
75
  });
58
76
  }
59
77
  },
60
- "ClassDeclaration, ClassExpression"() {
78
+ "ClassDeclaration"() {
61
79
  classCount++;
80
+ },
81
+ "ClassExpression"() {
82
+ if (!ignoreExpressions) {
83
+ classCount++;
84
+ }
62
85
  }
63
86
  };
64
87
  }
@@ -15,7 +15,6 @@ module.exports = {
15
15
 
16
16
  docs: {
17
17
  description: "enforce a maximum depth that blocks can be nested",
18
- category: "Stylistic Issues",
19
18
  recommended: false,
20
19
  url: "https://eslint.org/docs/rules/max-depth"
21
20
  },
@@ -69,7 +69,6 @@ module.exports = {
69
69
 
70
70
  docs: {
71
71
  description: "enforce a maximum line length",
72
- category: "Stylistic Issues",
73
72
  recommended: false,
74
73
  url: "https://eslint.org/docs/rules/max-len"
75
74
  },
@@ -215,7 +214,7 @@ module.exports = {
215
214
  * Ensure that an array exists at [key] on `object`, and add `value` to it.
216
215
  * @param {Object} object the object to mutate
217
216
  * @param {string} key the object's key
218
- * @param {*} value the value to add
217
+ * @param {any} value the value to add
219
218
  * @returns {void}
220
219
  * @private
221
220
  */
@@ -48,7 +48,7 @@ const OPTIONS_OR_INTEGER_SCHEMA = {
48
48
  /**
49
49
  * Given a list of comment nodes, return a map with numeric keys (source code line numbers) and comment token values.
50
50
  * @param {Array} comments An array of comment nodes.
51
- * @returns {Map.<string,Node>} A map with numeric keys (source code line numbers) and comment token values.
51
+ * @returns {Map<string, Node>} A map with numeric keys (source code line numbers) and comment token values.
52
52
  */
53
53
  function getCommentLineNumbers(comments) {
54
54
  const map = new Map();
@@ -71,7 +71,6 @@ module.exports = {
71
71
 
72
72
  docs: {
73
73
  description: "enforce a maximum number of lines of code in a function",
74
- category: "Stylistic Issues",
75
74
  recommended: false,
76
75
  url: "https://eslint.org/docs/rules/max-lines-per-function"
77
76
  },
@@ -34,7 +34,6 @@ module.exports = {
34
34
 
35
35
  docs: {
36
36
  description: "enforce a maximum number of lines per file",
37
- category: "Stylistic Issues",
38
37
  recommended: false,
39
38
  url: "https://eslint.org/docs/rules/max-lines"
40
39
  },
@@ -15,7 +15,6 @@ module.exports = {
15
15
 
16
16
  docs: {
17
17
  description: "enforce a maximum depth that callbacks can be nested",
18
- category: "Stylistic Issues",
19
18
  recommended: false,
20
19
  url: "https://eslint.org/docs/rules/max-nested-callbacks"
21
20
  },
@@ -22,7 +22,6 @@ module.exports = {
22
22
 
23
23
  docs: {
24
24
  description: "enforce a maximum number of parameters in function definitions",
25
- category: "Stylistic Issues",
26
25
  recommended: false,
27
26
  url: "https://eslint.org/docs/rules/max-params"
28
27
  },
@@ -20,7 +20,6 @@ module.exports = {
20
20
 
21
21
  docs: {
22
22
  description: "enforce a maximum number of statements allowed per line",
23
- category: "Stylistic Issues",
24
23
  recommended: false,
25
24
  url: "https://eslint.org/docs/rules/max-statements-per-line"
26
25
  },
@@ -22,7 +22,6 @@ module.exports = {
22
22
 
23
23
  docs: {
24
24
  description: "enforce a maximum number of statements allowed in function blocks",
25
- category: "Stylistic Issues",
26
25
  recommended: false,
27
26
  url: "https://eslint.org/docs/rules/max-statements"
28
27
  },
@@ -16,7 +16,6 @@ module.exports = {
16
16
 
17
17
  docs: {
18
18
  description: "enforce a particular style for multiline comments",
19
- category: "Stylistic Issues",
20
19
  recommended: false,
21
20
  url: "https://eslint.org/docs/rules/multiline-comment-style"
22
21
  },
@@ -17,7 +17,6 @@ module.exports = {
17
17
 
18
18
  docs: {
19
19
  description: "enforce newlines between operands of ternary expressions",
20
- category: "Stylistic Issues",
21
20
  recommended: false,
22
21
  url: "https://eslint.org/docs/rules/multiline-ternary"
23
22
  },
@@ -33,7 +33,8 @@ const CAPS_ALLOWED = [
33
33
  * Ensure that if the key is provided, it must be an array.
34
34
  * @param {Object} obj Object to check with `key`.
35
35
  * @param {string} key Object key to check on `obj`.
36
- * @param {*} fallback If obj[key] is not present, this will be returned.
36
+ * @param {any} fallback If obj[key] is not present, this will be returned.
37
+ * @throws {TypeError} If key is not an own array type property of `obj`.
37
38
  * @returns {string[]} Returns obj[key] if it's an Array, otherwise `fallback`
38
39
  */
39
40
  function checkArray(obj, key, fallback) {
@@ -81,7 +82,6 @@ module.exports = {
81
82
 
82
83
  docs: {
83
84
  description: "require constructor names to begin with a capital letter",
84
- category: "Stylistic Issues",
85
85
  recommended: false,
86
86
  url: "https://eslint.org/docs/rules/new-cap"
87
87
  },
@@ -25,7 +25,6 @@ module.exports = {
25
25
 
26
26
  docs: {
27
27
  description: "enforce or disallow parentheses when invoking a constructor with no arguments",
28
- category: "Stylistic Issues",
29
28
  recommended: false,
30
29
  url: "https://eslint.org/docs/rules/new-parens"
31
30
  },
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @fileoverview Rule to check empty newline after "var" statement
3
3
  * @author Gopal Venkatesan
4
- * @deprecated
4
+ * @deprecated in ESLint v4.0.0
5
5
  */
6
6
 
7
7
  "use strict";
@@ -22,7 +22,6 @@ module.exports = {
22
22
 
23
23
  docs: {
24
24
  description: "require or disallow an empty line after variable declarations",
25
- category: "Stylistic Issues",
26
25
  recommended: false,
27
26
  url: "https://eslint.org/docs/rules/newline-after-var"
28
27
  },
@@ -145,9 +144,9 @@ module.exports = {
145
144
 
146
145
  /**
147
146
  * Determine if a token starts more than one line after a comment ends
148
- * @param {token} token The token being checked
149
- * @param {integer} commentStartLine The line number on which the comment starts
150
- * @returns {boolean} True if `token` does not start immediately after a comment
147
+ * @param {token} token The token being checked
148
+ * @param {integer} commentStartLine The line number on which the comment starts
149
+ * @returns {boolean} True if `token` does not start immediately after a comment
151
150
  */
152
151
  function hasBlankLineAfterComment(token, commentStartLine) {
153
152
  return token.loc.start.line > getLastCommentLineOfBlock(commentStartLine) + 1;
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @fileoverview Rule to require newlines before `return` statement
3
3
  * @author Kai Cataldo
4
- * @deprecated
4
+ * @deprecated in ESLint v4.0.0
5
5
  */
6
6
  "use strict";
7
7
 
@@ -15,7 +15,6 @@ module.exports = {
15
15
 
16
16
  docs: {
17
17
  description: "require an empty line before `return` statements",
18
- category: "Stylistic Issues",
19
18
  recommended: false,
20
19
  url: "https://eslint.org/docs/rules/newline-before-return"
21
20
  },
@@ -134,7 +133,7 @@ module.exports = {
134
133
  if (tokenBefore) {
135
134
  lineNumTokenBefore = tokenBefore.loc.end.line;
136
135
  } else {
137
- lineNumTokenBefore = 0; // Global return at beginning of script
136
+ lineNumTokenBefore = 0; // global return at beginning of script
138
137
  }
139
138
 
140
139
  return lineNumTokenBefore;
@@ -18,7 +18,6 @@ module.exports = {
18
18
 
19
19
  docs: {
20
20
  description: "require a newline after each call in a method chain",
21
- category: "Stylistic Issues",
22
21
  recommended: false,
23
22
  url: "https://eslint.org/docs/rules/newline-per-chained-call"
24
23
  },
@@ -53,7 +52,7 @@ module.exports = {
53
52
  * Get the prefix of a given MemberExpression node.
54
53
  * If the MemberExpression node is a computed value it returns a
55
54
  * left bracket. If not it returns a period.
56
- * @param {ASTNode} node A MemberExpression node to get
55
+ * @param {ASTNode} node A MemberExpression node to get
57
56
  * @returns {string} The prefix of the node.
58
57
  */
59
58
  function getPrefix(node) {
@@ -88,7 +88,6 @@ module.exports = {
88
88
 
89
89
  docs: {
90
90
  description: "disallow the use of `alert`, `confirm`, and `prompt`",
91
- category: "Best Practices",
92
91
  recommended: false,
93
92
  url: "https://eslint.org/docs/rules/no-alert"
94
93
  },
@@ -15,7 +15,6 @@ module.exports = {
15
15
 
16
16
  docs: {
17
17
  description: "disallow `Array` constructors",
18
- category: "Stylistic Issues",
19
18
  recommended: false,
20
19
  url: "https://eslint.org/docs/rules/no-array-constructor"
21
20
  },
@@ -14,7 +14,6 @@ module.exports = {
14
14
 
15
15
  docs: {
16
16
  description: "disallow using an async function as a Promise executor",
17
- category: "Possible Errors",
18
17
  recommended: true,
19
18
  url: "https://eslint.org/docs/rules/no-async-promise-executor"
20
19
  },
@@ -59,7 +59,6 @@ module.exports = {
59
59
 
60
60
  docs: {
61
61
  description: "disallow `await` inside of loops",
62
- category: "Possible Errors",
63
62
  recommended: false,
64
63
  url: "https://eslint.org/docs/rules/no-await-in-loop"
65
64
  },
@@ -26,7 +26,6 @@ module.exports = {
26
26
 
27
27
  docs: {
28
28
  description: "disallow bitwise operators",
29
- category: "Stylistic Issues",
30
29
  recommended: false,
31
30
  url: "https://eslint.org/docs/rules/no-bitwise"
32
31
  },
@@ -63,7 +62,7 @@ module.exports = {
63
62
 
64
63
  /**
65
64
  * Reports an unexpected use of a bitwise operator.
66
- * @param {ASTNode} node Node which contains the bitwise operator.
65
+ * @param {ASTNode} node Node which contains the bitwise operator.
67
66
  * @returns {void}
68
67
  */
69
68
  function report(node) {
@@ -72,7 +71,7 @@ module.exports = {
72
71
 
73
72
  /**
74
73
  * Checks if the given node has a bitwise operator.
75
- * @param {ASTNode} node The node to check.
74
+ * @param {ASTNode} node The node to check.
76
75
  * @returns {boolean} Whether or not the node has a bitwise operator.
77
76
  */
78
77
  function hasBitwiseOperator(node) {
@@ -81,7 +80,7 @@ module.exports = {
81
80
 
82
81
  /**
83
82
  * Checks if exceptions were provided, e.g. `{ allow: ['~', '|'] }`.
84
- * @param {ASTNode} node The node to check.
83
+ * @param {ASTNode} node The node to check.
85
84
  * @returns {boolean} Whether or not the node has a bitwise operator.
86
85
  */
87
86
  function allowedOperator(node) {
@@ -90,7 +89,7 @@ module.exports = {
90
89
 
91
90
  /**
92
91
  * Checks if the given bitwise operator is used for integer typecasting, i.e. "|0"
93
- * @param {ASTNode} node The node to check.
92
+ * @param {ASTNode} node The node to check.
94
93
  * @returns {boolean} whether the node is used in integer typecasting.
95
94
  */
96
95
  function isInt32Hint(node) {
@@ -100,7 +99,7 @@ module.exports = {
100
99
 
101
100
  /**
102
101
  * Report if the given node contains a bitwise operator.
103
- * @param {ASTNode} node The node to check.
102
+ * @param {ASTNode} node The node to check.
104
103
  * @returns {void}
105
104
  */
106
105
  function checkNodeForBitwiseOperator(node) {
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * @fileoverview disallow use of the Buffer() constructor
3
3
  * @author Teddy Katz
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: "disallow use of the `Buffer()` constructor",
21
- category: "Node.js and CommonJS",
22
22
  recommended: false,
23
23
  url: "https://eslint.org/docs/rules/no-buffer-constructor"
24
24
  },
@@ -15,7 +15,6 @@ module.exports = {
15
15
 
16
16
  docs: {
17
17
  description: "disallow the use of `arguments.caller` or `arguments.callee`",
18
- category: "Best Practices",
19
18
  recommended: false,
20
19
  url: "https://eslint.org/docs/rules/no-caller"
21
20
  },
@@ -14,7 +14,6 @@ module.exports = {
14
14
 
15
15
  docs: {
16
16
  description: "disallow lexical declarations in case clauses",
17
- category: "Best Practices",
18
17
  recommended: true,
19
18
  url: "https://eslint.org/docs/rules/no-case-declarations"
20
19
  },
@@ -22,7 +22,6 @@ module.exports = {
22
22
 
23
23
  docs: {
24
24
  description: "disallow `catch` clause parameters from shadowing variables in the outer scope",
25
- category: "Variables",
26
25
  recommended: false,
27
26
  url: "https://eslint.org/docs/rules/no-catch-shadow"
28
27
  },
@@ -17,7 +17,6 @@ module.exports = {
17
17
 
18
18
  docs: {
19
19
  description: "disallow reassigning class members",
20
- category: "ECMAScript 6",
21
20
  recommended: true,
22
21
  url: "https://eslint.org/docs/rules/no-class-assign"
23
22
  },
@@ -14,7 +14,6 @@ module.exports = {
14
14
 
15
15
  docs: {
16
16
  description: "disallow comparing against -0",
17
- category: "Possible Errors",
18
17
  recommended: true,
19
18
  url: "https://eslint.org/docs/rules/no-compare-neg-zero"
20
19
  },
@@ -34,7 +34,6 @@ module.exports = {
34
34
 
35
35
  docs: {
36
36
  description: "disallow assignment operators in conditional expressions",
37
- category: "Possible Errors",
38
37
  recommended: true,
39
38
  url: "https://eslint.org/docs/rules/no-cond-assign"
40
39
  },