eslint 8.39.0 → 8.47.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 (317) hide show
  1. package/README.md +10 -4
  2. package/conf/globals.js +6 -1
  3. package/lib/cli-engine/cli-engine.js +30 -19
  4. package/lib/cli.js +2 -28
  5. package/lib/config/default-config.js +1 -1
  6. package/lib/config/flat-config-schema.js +127 -35
  7. package/lib/eslint/eslint-helpers.js +11 -10
  8. package/lib/eslint/eslint.js +1 -1
  9. package/lib/eslint/flat-eslint.js +119 -161
  10. package/lib/linter/apply-disable-directives.js +11 -1
  11. package/lib/linter/code-path-analysis/debug-helpers.js +1 -1
  12. package/lib/linter/config-comment-parser.js +9 -2
  13. package/lib/linter/linter.js +20 -11
  14. package/lib/linter/report-translator.js +22 -21
  15. package/lib/rule-tester/flat-rule-tester.js +1 -2
  16. package/lib/rule-tester/rule-tester.js +1 -2
  17. package/lib/rules/accessor-pairs.js +35 -43
  18. package/lib/rules/array-bracket-newline.js +2 -2
  19. package/lib/rules/array-bracket-spacing.js +2 -2
  20. package/lib/rules/array-callback-return.js +2 -2
  21. package/lib/rules/array-element-newline.js +12 -6
  22. package/lib/rules/arrow-body-style.js +2 -2
  23. package/lib/rules/arrow-parens.js +2 -2
  24. package/lib/rules/arrow-spacing.js +2 -2
  25. package/lib/rules/block-scoped-var.js +17 -7
  26. package/lib/rules/block-spacing.js +2 -2
  27. package/lib/rules/brace-style.js +2 -2
  28. package/lib/rules/callback-return.js +2 -2
  29. package/lib/rules/camelcase.js +2 -2
  30. package/lib/rules/capitalized-comments.js +2 -2
  31. package/lib/rules/class-methods-use-this.js +2 -2
  32. package/lib/rules/comma-dangle.js +2 -2
  33. package/lib/rules/comma-spacing.js +2 -2
  34. package/lib/rules/comma-style.js +2 -2
  35. package/lib/rules/complexity.js +1 -1
  36. package/lib/rules/computed-property-spacing.js +2 -2
  37. package/lib/rules/consistent-return.js +3 -3
  38. package/lib/rules/consistent-this.js +2 -2
  39. package/lib/rules/constructor-super.js +1 -1
  40. package/lib/rules/curly.js +2 -2
  41. package/lib/rules/default-case-last.js +1 -1
  42. package/lib/rules/default-case.js +2 -2
  43. package/lib/rules/default-param-last.js +1 -1
  44. package/lib/rules/dot-location.js +2 -2
  45. package/lib/rules/dot-notation.js +3 -4
  46. package/lib/rules/eol-last.js +2 -2
  47. package/lib/rules/eqeqeq.js +2 -2
  48. package/lib/rules/for-direction.js +1 -1
  49. package/lib/rules/func-call-spacing.js +2 -2
  50. package/lib/rules/func-name-matching.js +1 -1
  51. package/lib/rules/func-names.js +2 -2
  52. package/lib/rules/func-style.js +1 -1
  53. package/lib/rules/function-call-argument-newline.js +2 -2
  54. package/lib/rules/function-paren-newline.js +2 -2
  55. package/lib/rules/generator-star-spacing.js +2 -2
  56. package/lib/rules/getter-return.js +2 -2
  57. package/lib/rules/global-require.js +2 -2
  58. package/lib/rules/grouped-accessor-pairs.js +35 -44
  59. package/lib/rules/guard-for-in.js +1 -1
  60. package/lib/rules/handle-callback-err.js +2 -2
  61. package/lib/rules/id-blacklist.js +2 -2
  62. package/lib/rules/id-denylist.js +2 -2
  63. package/lib/rules/id-length.js +3 -36
  64. package/lib/rules/id-match.js +2 -2
  65. package/lib/rules/implicit-arrow-linebreak.js +2 -2
  66. package/lib/rules/indent-legacy.js +2 -2
  67. package/lib/rules/indent.js +84 -88
  68. package/lib/rules/init-declarations.js +1 -1
  69. package/lib/rules/jsx-quotes.js +1 -1
  70. package/lib/rules/key-spacing.js +4 -10
  71. package/lib/rules/keyword-spacing.js +2 -2
  72. package/lib/rules/line-comment-position.js +2 -2
  73. package/lib/rules/linebreak-style.js +2 -2
  74. package/lib/rules/lines-around-comment.js +2 -2
  75. package/lib/rules/lines-around-directive.js +2 -2
  76. package/lib/rules/lines-between-class-members.js +2 -2
  77. package/lib/rules/logical-assignment-operators.js +7 -5
  78. package/lib/rules/max-classes-per-file.js +1 -1
  79. package/lib/rules/max-depth.js +1 -1
  80. package/lib/rules/max-len.js +19 -15
  81. package/lib/rules/max-lines-per-function.js +2 -2
  82. package/lib/rules/max-lines.js +2 -2
  83. package/lib/rules/max-nested-callbacks.js +1 -1
  84. package/lib/rules/max-params.js +2 -2
  85. package/lib/rules/max-statements-per-line.js +2 -2
  86. package/lib/rules/max-statements.js +1 -1
  87. package/lib/rules/multiline-comment-style.js +2 -2
  88. package/lib/rules/multiline-ternary.js +2 -2
  89. package/lib/rules/new-cap.js +2 -2
  90. package/lib/rules/new-parens.js +2 -2
  91. package/lib/rules/newline-after-var.js +2 -4
  92. package/lib/rules/newline-before-return.js +2 -2
  93. package/lib/rules/newline-per-chained-call.js +2 -2
  94. package/lib/rules/no-alert.js +2 -2
  95. package/lib/rules/no-array-constructor.js +1 -1
  96. package/lib/rules/no-async-promise-executor.js +2 -2
  97. package/lib/rules/no-await-in-loop.js +1 -1
  98. package/lib/rules/no-bitwise.js +1 -1
  99. package/lib/rules/no-buffer-constructor.js +1 -1
  100. package/lib/rules/no-caller.js +1 -1
  101. package/lib/rules/no-case-declarations.js +1 -1
  102. package/lib/rules/no-catch-shadow.js +2 -2
  103. package/lib/rules/no-class-assign.js +2 -2
  104. package/lib/rules/no-compare-neg-zero.js +1 -1
  105. package/lib/rules/no-cond-assign.js +2 -2
  106. package/lib/rules/no-confusing-arrow.js +2 -2
  107. package/lib/rules/no-console.js +2 -2
  108. package/lib/rules/no-const-assign.js +2 -2
  109. package/lib/rules/no-constant-binary-expression.js +2 -2
  110. package/lib/rules/no-constant-condition.js +2 -2
  111. package/lib/rules/no-constructor-return.js +1 -1
  112. package/lib/rules/no-continue.js +1 -1
  113. package/lib/rules/no-control-regex.js +16 -3
  114. package/lib/rules/no-debugger.js +1 -1
  115. package/lib/rules/no-delete-var.js +1 -1
  116. package/lib/rules/no-div-regex.js +2 -2
  117. package/lib/rules/no-dupe-args.js +2 -2
  118. package/lib/rules/no-dupe-class-members.js +1 -1
  119. package/lib/rules/no-dupe-else-if.js +2 -2
  120. package/lib/rules/no-dupe-keys.js +1 -1
  121. package/lib/rules/no-duplicate-case.js +2 -2
  122. package/lib/rules/no-duplicate-imports.js +1 -1
  123. package/lib/rules/no-else-return.js +2 -2
  124. package/lib/rules/no-empty-character-class.js +34 -13
  125. package/lib/rules/no-empty-function.js +2 -2
  126. package/lib/rules/no-empty-pattern.js +39 -4
  127. package/lib/rules/no-empty-static-block.js +2 -2
  128. package/lib/rules/no-empty.js +2 -2
  129. package/lib/rules/no-eq-null.js +1 -1
  130. package/lib/rules/no-eval.js +2 -2
  131. package/lib/rules/no-ex-assign.js +2 -2
  132. package/lib/rules/no-extend-native.js +2 -2
  133. package/lib/rules/no-extra-bind.js +2 -2
  134. package/lib/rules/no-extra-boolean-cast.js +2 -2
  135. package/lib/rules/no-extra-label.js +2 -2
  136. package/lib/rules/no-extra-parens.js +48 -12
  137. package/lib/rules/no-extra-semi.js +31 -13
  138. package/lib/rules/no-fallthrough.js +3 -3
  139. package/lib/rules/no-floating-decimal.js +2 -2
  140. package/lib/rules/no-func-assign.js +2 -2
  141. package/lib/rules/no-global-assign.js +2 -2
  142. package/lib/rules/no-implicit-coercion.js +2 -2
  143. package/lib/rules/no-implicit-globals.js +2 -2
  144. package/lib/rules/no-implied-eval.js +2 -2
  145. package/lib/rules/no-import-assign.js +2 -2
  146. package/lib/rules/no-inline-comments.js +2 -2
  147. package/lib/rules/no-inner-declarations.js +1 -1
  148. package/lib/rules/no-invalid-regexp.js +23 -8
  149. package/lib/rules/no-invalid-this.js +2 -2
  150. package/lib/rules/no-irregular-whitespace.js +23 -6
  151. package/lib/rules/no-iterator.js +1 -1
  152. package/lib/rules/no-label-var.js +2 -2
  153. package/lib/rules/no-labels.js +1 -1
  154. package/lib/rules/no-lone-blocks.js +2 -2
  155. package/lib/rules/no-lonely-if.js +2 -2
  156. package/lib/rules/no-loop-func.js +3 -3
  157. package/lib/rules/no-loss-of-precision.js +15 -7
  158. package/lib/rules/no-magic-numbers.js +1 -1
  159. package/lib/rules/no-misleading-character-class.js +10 -4
  160. package/lib/rules/no-mixed-operators.js +2 -2
  161. package/lib/rules/no-mixed-requires.js +1 -1
  162. package/lib/rules/no-mixed-spaces-and-tabs.js +2 -2
  163. package/lib/rules/no-multi-assign.js +1 -1
  164. package/lib/rules/no-multi-spaces.js +2 -2
  165. package/lib/rules/no-multi-str.js +1 -1
  166. package/lib/rules/no-multiple-empty-lines.js +2 -2
  167. package/lib/rules/no-native-reassign.js +2 -2
  168. package/lib/rules/no-negated-condition.js +1 -1
  169. package/lib/rules/no-negated-in-lhs.js +1 -1
  170. package/lib/rules/no-nested-ternary.js +1 -1
  171. package/lib/rules/no-new-func.js +2 -2
  172. package/lib/rules/no-new-native-nonconstructor.js +2 -2
  173. package/lib/rules/no-new-object.js +2 -2
  174. package/lib/rules/no-new-require.js +1 -1
  175. package/lib/rules/no-new-symbol.js +2 -2
  176. package/lib/rules/no-new-wrappers.js +20 -8
  177. package/lib/rules/no-new.js +1 -1
  178. package/lib/rules/no-nonoctal-decimal-escape.js +2 -2
  179. package/lib/rules/no-obj-calls.js +2 -2
  180. package/lib/rules/no-octal-escape.js +1 -1
  181. package/lib/rules/no-octal.js +1 -1
  182. package/lib/rules/no-param-reassign.js +2 -2
  183. package/lib/rules/no-path-concat.js +1 -1
  184. package/lib/rules/no-plusplus.js +1 -1
  185. package/lib/rules/no-process-env.js +1 -1
  186. package/lib/rules/no-process-exit.js +1 -1
  187. package/lib/rules/no-promise-executor-return.js +2 -2
  188. package/lib/rules/no-proto.js +1 -1
  189. package/lib/rules/no-prototype-builtins.js +1 -1
  190. package/lib/rules/no-redeclare.js +2 -2
  191. package/lib/rules/no-regex-spaces.js +20 -5
  192. package/lib/rules/no-restricted-exports.js +2 -2
  193. package/lib/rules/no-restricted-globals.js +2 -2
  194. package/lib/rules/no-restricted-imports.js +2 -2
  195. package/lib/rules/no-restricted-modules.js +8 -11
  196. package/lib/rules/no-restricted-properties.js +1 -1
  197. package/lib/rules/no-restricted-syntax.js +1 -1
  198. package/lib/rules/no-return-assign.js +2 -2
  199. package/lib/rules/no-return-await.js +8 -3
  200. package/lib/rules/no-script-url.js +1 -1
  201. package/lib/rules/no-self-assign.js +2 -2
  202. package/lib/rules/no-self-compare.js +2 -2
  203. package/lib/rules/no-sequences.js +2 -2
  204. package/lib/rules/no-setter-return.js +2 -2
  205. package/lib/rules/no-shadow-restricted-names.js +2 -2
  206. package/lib/rules/no-shadow.js +2 -2
  207. package/lib/rules/no-spaced-func.js +2 -2
  208. package/lib/rules/no-sparse-arrays.js +1 -1
  209. package/lib/rules/no-sync.js +1 -1
  210. package/lib/rules/no-tabs.js +2 -2
  211. package/lib/rules/no-template-curly-in-string.js +1 -1
  212. package/lib/rules/no-ternary.js +1 -1
  213. package/lib/rules/no-this-before-super.js +1 -1
  214. package/lib/rules/no-throw-literal.js +1 -1
  215. package/lib/rules/no-trailing-spaces.js +2 -2
  216. package/lib/rules/no-undef-init.js +2 -2
  217. package/lib/rules/no-undef.js +2 -2
  218. package/lib/rules/no-undefined.js +2 -2
  219. package/lib/rules/no-underscore-dangle.js +2 -2
  220. package/lib/rules/no-unexpected-multiline.js +2 -2
  221. package/lib/rules/no-unmodified-loop-condition.js +2 -2
  222. package/lib/rules/no-unneeded-ternary.js +2 -2
  223. package/lib/rules/no-unreachable-loop.js +1 -1
  224. package/lib/rules/no-unreachable.js +2 -2
  225. package/lib/rules/no-unsafe-finally.js +1 -1
  226. package/lib/rules/no-unsafe-negation.js +2 -2
  227. package/lib/rules/no-unsafe-optional-chaining.js +1 -1
  228. package/lib/rules/no-unused-expressions.js +4 -6
  229. package/lib/rules/no-unused-labels.js +48 -15
  230. package/lib/rules/no-unused-private-class-members.js +1 -1
  231. package/lib/rules/no-unused-vars.js +4 -3
  232. package/lib/rules/no-use-before-define.js +2 -2
  233. package/lib/rules/no-useless-backreference.js +3 -3
  234. package/lib/rules/no-useless-call.js +2 -2
  235. package/lib/rules/no-useless-catch.js +1 -1
  236. package/lib/rules/no-useless-computed-key.js +2 -2
  237. package/lib/rules/no-useless-concat.js +2 -2
  238. package/lib/rules/no-useless-constructor.js +1 -1
  239. package/lib/rules/no-useless-escape.js +162 -83
  240. package/lib/rules/no-useless-rename.js +2 -2
  241. package/lib/rules/no-useless-return.js +37 -9
  242. package/lib/rules/no-var.js +2 -2
  243. package/lib/rules/no-void.js +1 -1
  244. package/lib/rules/no-warning-comments.js +2 -2
  245. package/lib/rules/no-whitespace-before-property.js +2 -2
  246. package/lib/rules/no-with.js +1 -1
  247. package/lib/rules/nonblock-statement-body-position.js +2 -2
  248. package/lib/rules/object-curly-newline.js +2 -2
  249. package/lib/rules/object-curly-spacing.js +4 -4
  250. package/lib/rules/object-property-newline.js +2 -2
  251. package/lib/rules/object-shorthand.js +2 -2
  252. package/lib/rules/one-var-declaration-per-line.js +1 -1
  253. package/lib/rules/one-var.js +2 -2
  254. package/lib/rules/operator-assignment.js +2 -2
  255. package/lib/rules/operator-linebreak.js +2 -2
  256. package/lib/rules/padded-blocks.js +2 -2
  257. package/lib/rules/padding-line-between-statements.js +8 -53
  258. package/lib/rules/prefer-arrow-callback.js +2 -2
  259. package/lib/rules/prefer-const.js +2 -2
  260. package/lib/rules/prefer-destructuring.js +2 -2
  261. package/lib/rules/prefer-exponentiation-operator.js +4 -3
  262. package/lib/rules/prefer-named-capture-group.js +10 -7
  263. package/lib/rules/prefer-numeric-literals.js +2 -2
  264. package/lib/rules/prefer-object-has-own.js +2 -2
  265. package/lib/rules/prefer-object-spread.js +2 -2
  266. package/lib/rules/prefer-promise-reject-errors.js +2 -2
  267. package/lib/rules/prefer-reflect.js +1 -1
  268. package/lib/rules/prefer-regex-literals.js +14 -17
  269. package/lib/rules/prefer-rest-params.js +2 -2
  270. package/lib/rules/prefer-spread.js +2 -2
  271. package/lib/rules/prefer-template.js +2 -2
  272. package/lib/rules/quote-props.js +2 -2
  273. package/lib/rules/quotes.js +16 -16
  274. package/lib/rules/radix.js +2 -2
  275. package/lib/rules/require-atomic-updates.js +2 -2
  276. package/lib/rules/require-await.js +2 -2
  277. package/lib/rules/require-jsdoc.js +2 -2
  278. package/lib/rules/require-unicode-regexp.js +5 -5
  279. package/lib/rules/require-yield.js +1 -1
  280. package/lib/rules/rest-spread-spacing.js +2 -2
  281. package/lib/rules/semi-spacing.js +2 -2
  282. package/lib/rules/semi-style.js +2 -2
  283. package/lib/rules/semi.js +30 -5
  284. package/lib/rules/sort-imports.js +2 -2
  285. package/lib/rules/sort-keys.js +2 -2
  286. package/lib/rules/sort-vars.js +2 -2
  287. package/lib/rules/space-before-blocks.js +2 -2
  288. package/lib/rules/space-before-function-paren.js +2 -2
  289. package/lib/rules/space-in-parens.js +2 -2
  290. package/lib/rules/space-infix-ops.js +2 -2
  291. package/lib/rules/space-unary-ops.js +2 -2
  292. package/lib/rules/spaced-comment.js +2 -2
  293. package/lib/rules/strict.js +1 -1
  294. package/lib/rules/switch-colon-spacing.js +2 -2
  295. package/lib/rules/symbol-description.js +2 -2
  296. package/lib/rules/template-curly-spacing.js +2 -2
  297. package/lib/rules/template-tag-spacing.js +2 -2
  298. package/lib/rules/unicode-bom.js +2 -2
  299. package/lib/rules/use-isnan.js +1 -1
  300. package/lib/rules/utils/ast-utils.js +55 -7
  301. package/lib/rules/utils/regular-expressions.js +2 -2
  302. package/lib/rules/valid-jsdoc.js +2 -2
  303. package/lib/rules/valid-typeof.js +9 -3
  304. package/lib/rules/vars-on-top.js +1 -1
  305. package/lib/rules/wrap-iife.js +2 -2
  306. package/lib/rules/wrap-regex.js +2 -2
  307. package/lib/rules/yield-star-spacing.js +2 -2
  308. package/lib/rules/yoda.js +4 -13
  309. package/lib/shared/string-utils.js +39 -1
  310. package/lib/shared/types.js +7 -3
  311. package/lib/unsupported-api.js +5 -2
  312. package/messages/eslintrc-incompat.js +98 -0
  313. package/messages/eslintrc-plugins.js +24 -0
  314. package/messages/invalid-rule-options.js +17 -0
  315. package/messages/invalid-rule-severity.js +13 -0
  316. package/messages/shared.js +18 -0
  317. package/package.json +15 -19
@@ -90,7 +90,7 @@ module.exports = {
90
90
  docs: {
91
91
  description: "Disallow duplicate keys in object literals",
92
92
  recommended: true,
93
- url: "https://eslint.org/docs/rules/no-dupe-keys"
93
+ url: "https://eslint.org/docs/latest/rules/no-dupe-keys"
94
94
  },
95
95
 
96
96
  schema: [],
@@ -24,7 +24,7 @@ module.exports = {
24
24
  docs: {
25
25
  description: "Disallow duplicate case labels",
26
26
  recommended: true,
27
- url: "https://eslint.org/docs/rules/no-duplicate-case"
27
+ url: "https://eslint.org/docs/latest/rules/no-duplicate-case"
28
28
  },
29
29
 
30
30
  schema: [],
@@ -35,7 +35,7 @@ module.exports = {
35
35
  },
36
36
 
37
37
  create(context) {
38
- const sourceCode = context.getSourceCode();
38
+ const sourceCode = context.sourceCode;
39
39
 
40
40
  /**
41
41
  * Determines whether the two given nodes are considered to be equal.
@@ -235,7 +235,7 @@ module.exports = {
235
235
  docs: {
236
236
  description: "Disallow duplicate module imports",
237
237
  recommended: false,
238
- url: "https://eslint.org/docs/rules/no-duplicate-imports"
238
+ url: "https://eslint.org/docs/latest/rules/no-duplicate-imports"
239
239
  },
240
240
 
241
241
  schema: [
@@ -24,7 +24,7 @@ module.exports = {
24
24
  docs: {
25
25
  description: "Disallow `else` blocks after `return` statements in `if` statements",
26
26
  recommended: false,
27
- url: "https://eslint.org/docs/rules/no-else-return"
27
+ url: "https://eslint.org/docs/latest/rules/no-else-return"
28
28
  },
29
29
 
30
30
  schema: [{
@@ -47,7 +47,7 @@ module.exports = {
47
47
 
48
48
  create(context) {
49
49
 
50
- const sourceCode = context.getSourceCode();
50
+ const sourceCode = context.sourceCode;
51
51
 
52
52
  //--------------------------------------------------------------------------
53
53
  // Helpers
@@ -5,20 +5,18 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ //------------------------------------------------------------------------------
9
+ // Requirements
10
+ //------------------------------------------------------------------------------
11
+
12
+ const { RegExpParser, visitRegExpAST } = require("@eslint-community/regexpp");
13
+
8
14
  //------------------------------------------------------------------------------
9
15
  // Helpers
10
16
  //------------------------------------------------------------------------------
11
17
 
12
- /*
13
- * plain-English description of the following regexp:
14
- * 0. `^` fix the match at the beginning of the string
15
- * 1. `([^\\[]|\\.|\[([^\\\]]|\\.)+\])*`: regexp contents; 0 or more of the following
16
- * 1.0. `[^\\[]`: any character that's not a `\` or a `[` (anything but escape sequences and character classes)
17
- * 1.1. `\\.`: an escape sequence
18
- * 1.2. `\[([^\\\]]|\\.)+\]`: a character class that isn't empty
19
- * 2. `$`: fix the match at the end of the string
20
- */
21
- const regex = /^([^\\[]|\\.|\[([^\\\]]|\\.)+\])*$/u;
18
+ const parser = new RegExpParser();
19
+ const QUICK_TEST_REGEX = /\[\]/u;
22
20
 
23
21
  //------------------------------------------------------------------------------
24
22
  // Rule Definition
@@ -32,7 +30,7 @@ module.exports = {
32
30
  docs: {
33
31
  description: "Disallow empty character classes in regular expressions",
34
32
  recommended: true,
35
- url: "https://eslint.org/docs/rules/no-empty-character-class"
33
+ url: "https://eslint.org/docs/latest/rules/no-empty-character-class"
36
34
  },
37
35
 
38
36
  schema: [],
@@ -45,9 +43,32 @@ module.exports = {
45
43
  create(context) {
46
44
  return {
47
45
  "Literal[regex]"(node) {
48
- if (!regex.test(node.regex.pattern)) {
49
- context.report({ node, messageId: "unexpected" });
46
+ const { pattern, flags } = node.regex;
47
+
48
+ if (!QUICK_TEST_REGEX.test(pattern)) {
49
+ return;
50
50
  }
51
+
52
+ let regExpAST;
53
+
54
+ try {
55
+ regExpAST = parser.parsePattern(pattern, 0, pattern.length, {
56
+ unicode: flags.includes("u"),
57
+ unicodeSets: flags.includes("v")
58
+ });
59
+ } catch {
60
+
61
+ // Ignore regular expressions that regexpp cannot parse
62
+ return;
63
+ }
64
+
65
+ visitRegExpAST(regExpAST, {
66
+ onCharacterClassEnter(characterClass) {
67
+ if (!characterClass.negate && characterClass.elements.length === 0) {
68
+ context.report({ node, messageId: "unexpected" });
69
+ }
70
+ }
71
+ });
51
72
  }
52
73
  };
53
74
 
@@ -97,7 +97,7 @@ module.exports = {
97
97
  docs: {
98
98
  description: "Disallow empty functions",
99
99
  recommended: false,
100
- url: "https://eslint.org/docs/rules/no-empty-function"
100
+ url: "https://eslint.org/docs/latest/rules/no-empty-function"
101
101
  },
102
102
 
103
103
  schema: [
@@ -123,7 +123,7 @@ module.exports = {
123
123
  const options = context.options[0] || {};
124
124
  const allowed = options.allow || [];
125
125
 
126
- const sourceCode = context.getSourceCode();
126
+ const sourceCode = context.sourceCode;
127
127
 
128
128
  /**
129
129
  * Reports a given function node if the node matches the following patterns.
@@ -4,6 +4,8 @@
4
4
  */
5
5
  "use strict";
6
6
 
7
+ const astUtils = require("./utils/ast-utils");
8
+
7
9
  //------------------------------------------------------------------------------
8
10
  // Rule Definition
9
11
  //------------------------------------------------------------------------------
@@ -16,10 +18,21 @@ module.exports = {
16
18
  docs: {
17
19
  description: "Disallow empty destructuring patterns",
18
20
  recommended: true,
19
- url: "https://eslint.org/docs/rules/no-empty-pattern"
21
+ url: "https://eslint.org/docs/latest/rules/no-empty-pattern"
20
22
  },
21
23
 
22
- schema: [],
24
+ schema: [
25
+ {
26
+ type: "object",
27
+ properties: {
28
+ allowObjectPatternsAsParameters: {
29
+ type: "boolean",
30
+ default: false
31
+ }
32
+ },
33
+ additionalProperties: false
34
+ }
35
+ ],
23
36
 
24
37
  messages: {
25
38
  unexpected: "Unexpected empty {{type}} pattern."
@@ -27,11 +40,33 @@ module.exports = {
27
40
  },
28
41
 
29
42
  create(context) {
43
+ const options = context.options[0] || {},
44
+ allowObjectPatternsAsParameters = options.allowObjectPatternsAsParameters || false;
45
+
30
46
  return {
31
47
  ObjectPattern(node) {
32
- if (node.properties.length === 0) {
33
- context.report({ node, messageId: "unexpected", data: { type: "object" } });
48
+
49
+ if (node.properties.length > 0) {
50
+ return;
34
51
  }
52
+
53
+ // Allow {} and {} = {} empty object patterns as parameters when allowObjectPatternsAsParameters is true
54
+ if (
55
+ allowObjectPatternsAsParameters &&
56
+ (
57
+ astUtils.isFunction(node.parent) ||
58
+ (
59
+ node.parent.type === "AssignmentPattern" &&
60
+ astUtils.isFunction(node.parent.parent) &&
61
+ node.parent.right.type === "ObjectExpression" &&
62
+ node.parent.right.properties.length === 0
63
+ )
64
+ )
65
+ ) {
66
+ return;
67
+ }
68
+
69
+ context.report({ node, messageId: "unexpected", data: { type: "object" } });
35
70
  },
36
71
  ArrayPattern(node) {
37
72
  if (node.elements.length === 0) {
@@ -16,7 +16,7 @@ module.exports = {
16
16
  docs: {
17
17
  description: "Disallow empty static blocks",
18
18
  recommended: false,
19
- url: "https://eslint.org/docs/rules/no-empty-static-block"
19
+ url: "https://eslint.org/docs/latest/rules/no-empty-static-block"
20
20
  },
21
21
 
22
22
  schema: [],
@@ -27,7 +27,7 @@ module.exports = {
27
27
  },
28
28
 
29
29
  create(context) {
30
- const sourceCode = context.getSourceCode();
30
+ const sourceCode = context.sourceCode;
31
31
 
32
32
  return {
33
33
  StaticBlock(node) {
@@ -23,7 +23,7 @@ module.exports = {
23
23
  docs: {
24
24
  description: "Disallow empty block statements",
25
25
  recommended: true,
26
- url: "https://eslint.org/docs/rules/no-empty"
26
+ url: "https://eslint.org/docs/latest/rules/no-empty"
27
27
  },
28
28
 
29
29
  schema: [
@@ -49,7 +49,7 @@ module.exports = {
49
49
  const options = context.options[0] || {},
50
50
  allowEmptyCatch = options.allowEmptyCatch || false;
51
51
 
52
- const sourceCode = context.getSourceCode();
52
+ const sourceCode = context.sourceCode;
53
53
 
54
54
  return {
55
55
  BlockStatement(node) {
@@ -18,7 +18,7 @@ module.exports = {
18
18
  docs: {
19
19
  description: "Disallow `null` comparisons without type-checking operators",
20
20
  recommended: false,
21
- url: "https://eslint.org/docs/rules/no-eq-null"
21
+ url: "https://eslint.org/docs/latest/rules/no-eq-null"
22
22
  },
23
23
 
24
24
  schema: [],
@@ -45,7 +45,7 @@ module.exports = {
45
45
  docs: {
46
46
  description: "Disallow the use of `eval()`",
47
47
  recommended: false,
48
- url: "https://eslint.org/docs/rules/no-eval"
48
+ url: "https://eslint.org/docs/latest/rules/no-eval"
49
49
  },
50
50
 
51
51
  schema: [
@@ -68,7 +68,7 @@ module.exports = {
68
68
  context.options[0] &&
69
69
  context.options[0].allowIndirect
70
70
  );
71
- const sourceCode = context.getSourceCode();
71
+ const sourceCode = context.sourceCode;
72
72
  let funcInfo = null;
73
73
 
74
74
  /**
@@ -19,7 +19,7 @@ module.exports = {
19
19
  docs: {
20
20
  description: "Disallow reassigning exceptions in `catch` clauses",
21
21
  recommended: true,
22
- url: "https://eslint.org/docs/rules/no-ex-assign"
22
+ url: "https://eslint.org/docs/latest/rules/no-ex-assign"
23
23
  },
24
24
 
25
25
  schema: [],
@@ -31,7 +31,7 @@ module.exports = {
31
31
 
32
32
  create(context) {
33
33
 
34
- const sourceCode = context.getSourceCode();
34
+ const sourceCode = context.sourceCode;
35
35
 
36
36
  /**
37
37
  * Finds and reports references that are non initializer and writable.
@@ -24,7 +24,7 @@ module.exports = {
24
24
  docs: {
25
25
  description: "Disallow extending native types",
26
26
  recommended: false,
27
- url: "https://eslint.org/docs/rules/no-extend-native"
27
+ url: "https://eslint.org/docs/latest/rules/no-extend-native"
28
28
  },
29
29
 
30
30
  schema: [
@@ -51,7 +51,7 @@ module.exports = {
51
51
  create(context) {
52
52
 
53
53
  const config = context.options[0] || {};
54
- const sourceCode = context.getSourceCode();
54
+ const sourceCode = context.sourceCode;
55
55
  const exceptions = new Set(config.exceptions || []);
56
56
  const modifiedBuiltins = new Set(
57
57
  Object.keys(globals.builtin)
@@ -28,7 +28,7 @@ module.exports = {
28
28
  docs: {
29
29
  description: "Disallow unnecessary calls to `.bind()`",
30
30
  recommended: false,
31
- url: "https://eslint.org/docs/rules/no-extra-bind"
31
+ url: "https://eslint.org/docs/latest/rules/no-extra-bind"
32
32
  },
33
33
 
34
34
  schema: [],
@@ -40,7 +40,7 @@ module.exports = {
40
40
  },
41
41
 
42
42
  create(context) {
43
- const sourceCode = context.getSourceCode();
43
+ const sourceCode = context.sourceCode;
44
44
  let scopeInfo = null;
45
45
 
46
46
  /**
@@ -26,7 +26,7 @@ module.exports = {
26
26
  docs: {
27
27
  description: "Disallow unnecessary boolean casts",
28
28
  recommended: true,
29
- url: "https://eslint.org/docs/rules/no-extra-boolean-cast"
29
+ url: "https://eslint.org/docs/latest/rules/no-extra-boolean-cast"
30
30
  },
31
31
 
32
32
  schema: [{
@@ -48,7 +48,7 @@ module.exports = {
48
48
  },
49
49
 
50
50
  create(context) {
51
- const sourceCode = context.getSourceCode();
51
+ const sourceCode = context.sourceCode;
52
52
 
53
53
  // Node types which have a test which will coerce values to booleans.
54
54
  const BOOLEAN_NODE_TYPES = new Set([
@@ -23,7 +23,7 @@ module.exports = {
23
23
  docs: {
24
24
  description: "Disallow unnecessary labels",
25
25
  recommended: false,
26
- url: "https://eslint.org/docs/rules/no-extra-label"
26
+ url: "https://eslint.org/docs/latest/rules/no-extra-label"
27
27
  },
28
28
 
29
29
  schema: [],
@@ -35,7 +35,7 @@ module.exports = {
35
35
  },
36
36
 
37
37
  create(context) {
38
- const sourceCode = context.getSourceCode();
38
+ const sourceCode = context.sourceCode;
39
39
  let scopeInfo = null;
40
40
 
41
41
  /**
@@ -19,7 +19,7 @@ module.exports = {
19
19
  docs: {
20
20
  description: "Disallow unnecessary parentheses",
21
21
  recommended: false,
22
- url: "https://eslint.org/docs/rules/no-extra-parens"
22
+ url: "https://eslint.org/docs/latest/rules/no-extra-parens"
23
23
  },
24
24
 
25
25
  fixable: "code",
@@ -46,6 +46,7 @@ module.exports = {
46
46
  type: "object",
47
47
  properties: {
48
48
  conditionalAssign: { type: "boolean" },
49
+ ternaryOperandBinaryExpressions: { type: "boolean" },
49
50
  nestedBinaryExpressions: { type: "boolean" },
50
51
  returnAssign: { type: "boolean" },
51
52
  ignoreJSX: { enum: ["none", "all", "single-line", "multi-line"] },
@@ -70,12 +71,13 @@ module.exports = {
70
71
  },
71
72
 
72
73
  create(context) {
73
- const sourceCode = context.getSourceCode();
74
+ const sourceCode = context.sourceCode;
74
75
 
75
76
  const tokensToIgnore = new WeakSet();
76
77
  const precedence = astUtils.getPrecedence;
77
78
  const ALL_NODES = context.options[0] !== "functions";
78
79
  const EXCEPT_COND_ASSIGN = ALL_NODES && context.options[1] && context.options[1].conditionalAssign === false;
80
+ const EXCEPT_COND_TERNARY = ALL_NODES && context.options[1] && context.options[1].ternaryOperandBinaryExpressions === false;
79
81
  const NESTED_BINARY = ALL_NODES && context.options[1] && context.options[1].nestedBinaryExpressions === false;
80
82
  const EXCEPT_RETURN_ASSIGN = ALL_NODES && context.options[1] && context.options[1].returnAssign === false;
81
83
  const IGNORE_JSX = ALL_NODES && context.options[1] && context.options[1].ignoreJSX;
@@ -386,6 +388,30 @@ module.exports = {
386
388
  return node && (node.type === "Identifier" || node.type === "MemberExpression");
387
389
  }
388
390
 
391
+ /**
392
+ * Checks if a node is fixable.
393
+ * A node is fixable if removing a single pair of surrounding parentheses does not turn it
394
+ * into a directive after fixing other nodes.
395
+ * Almost all nodes are fixable, except if all of the following conditions are met:
396
+ * The node is a string Literal
397
+ * It has a single pair of parentheses
398
+ * It is the only child of an ExpressionStatement
399
+ * @param {ASTNode} node The node to evaluate.
400
+ * @returns {boolean} Whether or not the node is fixable.
401
+ * @private
402
+ */
403
+ function isFixable(node) {
404
+
405
+ // if it's not a string literal it can be autofixed
406
+ if (node.type !== "Literal" || typeof node.value !== "string") {
407
+ return true;
408
+ }
409
+ if (isParenthesisedTwice(node)) {
410
+ return true;
411
+ }
412
+ return !astUtils.isTopLevelExpressionStatement(node.parent);
413
+ }
414
+
389
415
  /**
390
416
  * Report the node
391
417
  * @param {ASTNode} node node to evaluate
@@ -429,14 +455,16 @@ module.exports = {
429
455
  node,
430
456
  loc: leftParenToken.loc,
431
457
  messageId: "unexpected",
432
- fix(fixer) {
433
- const parenthesizedSource = sourceCode.text.slice(leftParenToken.range[1], rightParenToken.range[0]);
434
-
435
- return fixer.replaceTextRange([
436
- leftParenToken.range[0],
437
- rightParenToken.range[1]
438
- ], (requiresLeadingSpace(node) ? " " : "") + parenthesizedSource + (requiresTrailingSpace(node) ? " " : ""));
439
- }
458
+ fix: isFixable(node)
459
+ ? fixer => {
460
+ const parenthesizedSource = sourceCode.text.slice(leftParenToken.range[1], rightParenToken.range[0]);
461
+
462
+ return fixer.replaceTextRange([
463
+ leftParenToken.range[0],
464
+ rightParenToken.range[1]
465
+ ], (requiresLeadingSpace(node) ? " " : "") + parenthesizedSource + (requiresTrailingSpace(node) ? " " : ""));
466
+ }
467
+ : null
440
468
  });
441
469
  }
442
470
 
@@ -860,18 +888,26 @@ module.exports = {
860
888
  if (isReturnAssignException(node)) {
861
889
  return;
862
890
  }
891
+
892
+ const availableTypes = new Set(["BinaryExpression", "LogicalExpression"]);
893
+
863
894
  if (
895
+ !(EXCEPT_COND_TERNARY && availableTypes.has(node.test.type)) &&
864
896
  !isCondAssignException(node) &&
865
897
  hasExcessParensWithPrecedence(node.test, precedence({ type: "LogicalExpression", operator: "||" }))
866
898
  ) {
867
899
  report(node.test);
868
900
  }
869
901
 
870
- if (hasExcessParensWithPrecedence(node.consequent, PRECEDENCE_OF_ASSIGNMENT_EXPR)) {
902
+ if (
903
+ !(EXCEPT_COND_TERNARY && availableTypes.has(node.consequent.type)) &&
904
+ hasExcessParensWithPrecedence(node.consequent, PRECEDENCE_OF_ASSIGNMENT_EXPR)) {
871
905
  report(node.consequent);
872
906
  }
873
907
 
874
- if (hasExcessParensWithPrecedence(node.alternate, PRECEDENCE_OF_ASSIGNMENT_EXPR)) {
908
+ if (
909
+ !(EXCEPT_COND_TERNARY && availableTypes.has(node.alternate.type)) &&
910
+ hasExcessParensWithPrecedence(node.alternate, PRECEDENCE_OF_ASSIGNMENT_EXPR)) {
875
911
  report(node.alternate);
876
912
  }
877
913
  },
@@ -24,7 +24,7 @@ module.exports = {
24
24
  docs: {
25
25
  description: "Disallow unnecessary semicolons",
26
26
  recommended: true,
27
- url: "https://eslint.org/docs/rules/no-extra-semi"
27
+ url: "https://eslint.org/docs/latest/rules/no-extra-semi"
28
28
  },
29
29
 
30
30
  fixable: "code",
@@ -36,7 +36,24 @@ module.exports = {
36
36
  },
37
37
 
38
38
  create(context) {
39
- const sourceCode = context.getSourceCode();
39
+ const sourceCode = context.sourceCode;
40
+
41
+ /**
42
+ * Checks if a node or token is fixable.
43
+ * A node is fixable if it can be removed without turning a subsequent statement into a directive after fixing other nodes.
44
+ * @param {Token} nodeOrToken The node or token to check.
45
+ * @returns {boolean} Whether or not the node is fixable.
46
+ */
47
+ function isFixable(nodeOrToken) {
48
+ const nextToken = sourceCode.getTokenAfter(nodeOrToken);
49
+
50
+ if (!nextToken || nextToken.type !== "String") {
51
+ return true;
52
+ }
53
+ const stringNode = sourceCode.getNodeByRangeIndex(nextToken.range[0]);
54
+
55
+ return !astUtils.isTopLevelExpressionStatement(stringNode.parent);
56
+ }
40
57
 
41
58
  /**
42
59
  * Reports an unnecessary semicolon error.
@@ -47,17 +64,18 @@ module.exports = {
47
64
  context.report({
48
65
  node: nodeOrToken,
49
66
  messageId: "unexpected",
50
- fix(fixer) {
51
-
52
- /*
53
- * Expand the replacement range to include the surrounding
54
- * tokens to avoid conflicting with semi.
55
- * https://github.com/eslint/eslint/issues/7928
56
- */
57
- return new FixTracker(fixer, context.getSourceCode())
58
- .retainSurroundingTokens(nodeOrToken)
59
- .remove(nodeOrToken);
60
- }
67
+ fix: isFixable(nodeOrToken)
68
+ ? fixer =>
69
+
70
+ /*
71
+ * Expand the replacement range to include the surrounding
72
+ * tokens to avoid conflicting with semi.
73
+ * https://github.com/eslint/eslint/issues/7928
74
+ */
75
+ new FixTracker(fixer, context.sourceCode)
76
+ .retainSurroundingTokens(nodeOrToken)
77
+ .remove(nodeOrToken)
78
+ : null
61
79
  });
62
80
  }
63
81
 
@@ -35,7 +35,7 @@ function isFallThroughComment(comment, fallthroughCommentPattern) {
35
35
  * @returns {boolean} `true` if the case has a valid fallthrough comment.
36
36
  */
37
37
  function hasFallthroughComment(caseWhichFallsThrough, subsequentCase, context, fallthroughCommentPattern) {
38
- const sourceCode = context.getSourceCode();
38
+ const sourceCode = context.sourceCode;
39
39
 
40
40
  if (caseWhichFallsThrough.consequent.length === 1 && caseWhichFallsThrough.consequent[0].type === "BlockStatement") {
41
41
  const trailingCloseBrace = sourceCode.getLastToken(caseWhichFallsThrough.consequent[0]);
@@ -82,7 +82,7 @@ module.exports = {
82
82
  docs: {
83
83
  description: "Disallow fallthrough of `case` statements",
84
84
  recommended: true,
85
- url: "https://eslint.org/docs/rules/no-fallthrough"
85
+ url: "https://eslint.org/docs/latest/rules/no-fallthrough"
86
86
  },
87
87
 
88
88
  schema: [
@@ -110,7 +110,7 @@ module.exports = {
110
110
  create(context) {
111
111
  const options = context.options[0] || {};
112
112
  let currentCodePath = null;
113
- const sourceCode = context.getSourceCode();
113
+ const sourceCode = context.sourceCode;
114
114
  const allowEmptyCase = options.allowEmptyCase || false;
115
115
 
116
116
  /*
@@ -23,7 +23,7 @@ module.exports = {
23
23
  docs: {
24
24
  description: "Disallow leading or trailing decimal points in numeric literals",
25
25
  recommended: false,
26
- url: "https://eslint.org/docs/rules/no-floating-decimal"
26
+ url: "https://eslint.org/docs/latest/rules/no-floating-decimal"
27
27
  },
28
28
 
29
29
  schema: [],
@@ -35,7 +35,7 @@ module.exports = {
35
35
  },
36
36
 
37
37
  create(context) {
38
- const sourceCode = context.getSourceCode();
38
+ const sourceCode = context.sourceCode;
39
39
 
40
40
  return {
41
41
  Literal(node) {
@@ -19,7 +19,7 @@ module.exports = {
19
19
  docs: {
20
20
  description: "Disallow reassigning `function` declarations",
21
21
  recommended: true,
22
- url: "https://eslint.org/docs/rules/no-func-assign"
22
+ url: "https://eslint.org/docs/latest/rules/no-func-assign"
23
23
  },
24
24
 
25
25
  schema: [],
@@ -31,7 +31,7 @@ module.exports = {
31
31
 
32
32
  create(context) {
33
33
 
34
- const sourceCode = context.getSourceCode();
34
+ const sourceCode = context.sourceCode;
35
35
 
36
36
  /**
37
37
  * Reports a reference if is non initializer and writable.
@@ -17,7 +17,7 @@ module.exports = {
17
17
  docs: {
18
18
  description: "Disallow assignments to native objects or read-only global variables",
19
19
  recommended: true,
20
- url: "https://eslint.org/docs/rules/no-global-assign"
20
+ url: "https://eslint.org/docs/latest/rules/no-global-assign"
21
21
  },
22
22
 
23
23
  schema: [
@@ -41,7 +41,7 @@ module.exports = {
41
41
 
42
42
  create(context) {
43
43
  const config = context.options[0];
44
- const sourceCode = context.getSourceCode();
44
+ const sourceCode = context.sourceCode;
45
45
  const exceptions = (config && config.exceptions) || [];
46
46
 
47
47
  /**
@@ -193,7 +193,7 @@ module.exports = {
193
193
  docs: {
194
194
  description: "Disallow shorthand type conversions",
195
195
  recommended: false,
196
- url: "https://eslint.org/docs/rules/no-implicit-coercion"
196
+ url: "https://eslint.org/docs/latest/rules/no-implicit-coercion"
197
197
  },
198
198
 
199
199
  fixable: "code",
@@ -235,7 +235,7 @@ module.exports = {
235
235
 
236
236
  create(context) {
237
237
  const options = parseOptions(context.options[0] || {});
238
- const sourceCode = context.getSourceCode();
238
+ const sourceCode = context.sourceCode;
239
239
 
240
240
  /**
241
241
  * Reports an error and autofixes the node