eslint 8.51.0 → 8.53.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 (77) hide show
  1. package/README.md +7 -2
  2. package/bin/eslint.js +24 -2
  3. package/conf/rule-type-list.json +25 -33
  4. package/lib/cli.js +8 -1
  5. package/lib/config/flat-config-schema.js +55 -36
  6. package/lib/linter/apply-disable-directives.js +126 -12
  7. package/lib/options.js +2 -2
  8. package/lib/rules/array-bracket-newline.js +3 -0
  9. package/lib/rules/array-bracket-spacing.js +3 -0
  10. package/lib/rules/array-element-newline.js +3 -0
  11. package/lib/rules/arrow-parens.js +3 -0
  12. package/lib/rules/arrow-spacing.js +3 -0
  13. package/lib/rules/block-spacing.js +3 -0
  14. package/lib/rules/brace-style.js +3 -0
  15. package/lib/rules/comma-dangle.js +3 -0
  16. package/lib/rules/comma-spacing.js +3 -0
  17. package/lib/rules/comma-style.js +3 -0
  18. package/lib/rules/computed-property-spacing.js +3 -0
  19. package/lib/rules/dot-location.js +3 -0
  20. package/lib/rules/eol-last.js +3 -0
  21. package/lib/rules/func-call-spacing.js +3 -0
  22. package/lib/rules/function-call-argument-newline.js +3 -0
  23. package/lib/rules/function-paren-newline.js +3 -0
  24. package/lib/rules/generator-star-spacing.js +3 -0
  25. package/lib/rules/implicit-arrow-linebreak.js +3 -0
  26. package/lib/rules/indent.js +3 -0
  27. package/lib/rules/jsx-quotes.js +3 -0
  28. package/lib/rules/key-spacing.js +3 -0
  29. package/lib/rules/keyword-spacing.js +3 -0
  30. package/lib/rules/linebreak-style.js +3 -0
  31. package/lib/rules/lines-around-comment.js +3 -0
  32. package/lib/rules/lines-between-class-members.js +3 -0
  33. package/lib/rules/max-len.js +3 -0
  34. package/lib/rules/max-statements-per-line.js +3 -0
  35. package/lib/rules/multiline-ternary.js +3 -0
  36. package/lib/rules/new-parens.js +3 -0
  37. package/lib/rules/newline-per-chained-call.js +3 -0
  38. package/lib/rules/no-confusing-arrow.js +3 -0
  39. package/lib/rules/no-extra-parens.js +3 -0
  40. package/lib/rules/no-extra-semi.js +3 -0
  41. package/lib/rules/no-floating-decimal.js +3 -0
  42. package/lib/rules/no-mixed-operators.js +3 -0
  43. package/lib/rules/no-mixed-spaces-and-tabs.js +3 -0
  44. package/lib/rules/no-multi-spaces.js +3 -0
  45. package/lib/rules/no-multiple-empty-lines.js +3 -0
  46. package/lib/rules/no-object-constructor.js +103 -5
  47. package/lib/rules/no-prototype-builtins.js +90 -2
  48. package/lib/rules/no-tabs.js +3 -0
  49. package/lib/rules/no-trailing-spaces.js +3 -0
  50. package/lib/rules/no-whitespace-before-property.js +3 -0
  51. package/lib/rules/nonblock-statement-body-position.js +3 -0
  52. package/lib/rules/object-curly-newline.js +3 -0
  53. package/lib/rules/object-curly-spacing.js +3 -0
  54. package/lib/rules/object-property-newline.js +3 -0
  55. package/lib/rules/one-var-declaration-per-line.js +3 -0
  56. package/lib/rules/operator-linebreak.js +3 -0
  57. package/lib/rules/padded-blocks.js +3 -0
  58. package/lib/rules/padding-line-between-statements.js +3 -0
  59. package/lib/rules/quote-props.js +3 -0
  60. package/lib/rules/quotes.js +3 -0
  61. package/lib/rules/rest-spread-spacing.js +3 -0
  62. package/lib/rules/semi-spacing.js +3 -0
  63. package/lib/rules/semi-style.js +3 -0
  64. package/lib/rules/semi.js +3 -0
  65. package/lib/rules/space-before-blocks.js +3 -0
  66. package/lib/rules/space-before-function-paren.js +3 -0
  67. package/lib/rules/space-in-parens.js +3 -0
  68. package/lib/rules/space-infix-ops.js +3 -0
  69. package/lib/rules/space-unary-ops.js +3 -0
  70. package/lib/rules/spaced-comment.js +3 -0
  71. package/lib/rules/switch-colon-spacing.js +3 -0
  72. package/lib/rules/template-curly-spacing.js +3 -0
  73. package/lib/rules/template-tag-spacing.js +3 -0
  74. package/lib/rules/wrap-iife.js +3 -0
  75. package/lib/rules/wrap-regex.js +3 -0
  76. package/lib/rules/yield-star-spacing.js +3 -0
  77. package/package.json +5 -14
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * @fileoverview Comma style - enforces comma styles of two types: last and first
3
3
  * @author Vignesh Anand aka vegetableman
4
+ * @deprecated in ESLint v8.53.0
4
5
  */
5
6
 
6
7
  "use strict";
@@ -14,6 +15,8 @@ const astUtils = require("./utils/ast-utils");
14
15
  /** @type {import('../shared/types').Rule} */
15
16
  module.exports = {
16
17
  meta: {
18
+ deprecated: true,
19
+ replacedBy: [],
17
20
  type: "layout",
18
21
 
19
22
  docs: {
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * @fileoverview Disallows or enforces spaces inside computed properties.
3
3
  * @author Jamund Ferguson
4
+ * @deprecated in ESLint v8.53.0
4
5
  */
5
6
  "use strict";
6
7
 
@@ -13,6 +14,8 @@ const astUtils = require("./utils/ast-utils");
13
14
  /** @type {import('../shared/types').Rule} */
14
15
  module.exports = {
15
16
  meta: {
17
+ deprecated: true,
18
+ replacedBy: [],
16
19
  type: "layout",
17
20
 
18
21
  docs: {
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * @fileoverview Validates newlines before and after dots
3
3
  * @author Greg Cochard
4
+ * @deprecated in ESLint v8.53.0
4
5
  */
5
6
 
6
7
  "use strict";
@@ -14,6 +15,8 @@ const astUtils = require("./utils/ast-utils");
14
15
  /** @type {import('../shared/types').Rule} */
15
16
  module.exports = {
16
17
  meta: {
18
+ deprecated: true,
19
+ replacedBy: [],
17
20
  type: "layout",
18
21
 
19
22
  docs: {
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * @fileoverview Require or disallow newline at the end of files
3
3
  * @author Nodeca Team <https://github.com/nodeca>
4
+ * @deprecated in ESLint v8.53.0
4
5
  */
5
6
  "use strict";
6
7
 
@@ -11,6 +12,8 @@
11
12
  /** @type {import('../shared/types').Rule} */
12
13
  module.exports = {
13
14
  meta: {
15
+ deprecated: true,
16
+ replacedBy: [],
14
17
  type: "layout",
15
18
 
16
19
  docs: {
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * @fileoverview Rule to control spacing within function calls
3
3
  * @author Matt DuVall <http://www.mattduvall.com>
4
+ * @deprecated in ESLint v8.53.0
4
5
  */
5
6
 
6
7
  "use strict";
@@ -18,6 +19,8 @@ const astUtils = require("./utils/ast-utils");
18
19
  /** @type {import('../shared/types').Rule} */
19
20
  module.exports = {
20
21
  meta: {
22
+ deprecated: true,
23
+ replacedBy: [],
21
24
  type: "layout",
22
25
 
23
26
  docs: {
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * @fileoverview Rule to enforce line breaks between arguments of a function call
3
3
  * @author Alexey Gonchar <https://github.com/finico>
4
+ * @deprecated in ESLint v8.53.0
4
5
  */
5
6
 
6
7
  "use strict";
@@ -12,6 +13,8 @@
12
13
  /** @type {import('../shared/types').Rule} */
13
14
  module.exports = {
14
15
  meta: {
16
+ deprecated: true,
17
+ replacedBy: [],
15
18
  type: "layout",
16
19
 
17
20
  docs: {
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * @fileoverview enforce consistent line breaks inside function parentheses
3
3
  * @author Teddy Katz
4
+ * @deprecated in ESLint v8.53.0
4
5
  */
5
6
  "use strict";
6
7
 
@@ -17,6 +18,8 @@ const astUtils = require("./utils/ast-utils");
17
18
  /** @type {import('../shared/types').Rule} */
18
19
  module.exports = {
19
20
  meta: {
21
+ deprecated: true,
22
+ replacedBy: [],
20
23
  type: "layout",
21
24
 
22
25
  docs: {
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * @fileoverview Rule to check the spacing around the * in generator functions.
3
3
  * @author Jamund Ferguson
4
+ * @deprecated in ESLint v8.53.0
4
5
  */
5
6
 
6
7
  "use strict";
@@ -28,6 +29,8 @@ const OVERRIDE_SCHEMA = {
28
29
  /** @type {import('../shared/types').Rule} */
29
30
  module.exports = {
30
31
  meta: {
32
+ deprecated: true,
33
+ replacedBy: [],
31
34
  type: "layout",
32
35
 
33
36
  docs: {
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * @fileoverview enforce the location of arrow function bodies
3
3
  * @author Sharmila Jesupaul
4
+ * @deprecated in ESLint v8.53.0
4
5
  */
5
6
  "use strict";
6
7
 
@@ -12,6 +13,8 @@ const { isCommentToken, isNotOpeningParenToken } = require("./utils/ast-utils");
12
13
  /** @type {import('../shared/types').Rule} */
13
14
  module.exports = {
14
15
  meta: {
16
+ deprecated: true,
17
+ replacedBy: [],
15
18
  type: "layout",
16
19
 
17
20
  docs: {
@@ -4,6 +4,7 @@
4
4
  * @author Teddy Katz
5
5
  * @author Vitaly Puzrin
6
6
  * @author Gyandeep Singh
7
+ * @deprecated in ESLint v8.53.0
7
8
  */
8
9
 
9
10
  "use strict";
@@ -493,6 +494,8 @@ const ELEMENT_LIST_SCHEMA = {
493
494
  /** @type {import('../shared/types').Rule} */
494
495
  module.exports = {
495
496
  meta: {
497
+ deprecated: true,
498
+ replacedBy: [],
496
499
  type: "layout",
497
500
 
498
501
  docs: {
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * @fileoverview A rule to ensure consistent quotes used in jsx syntax.
3
3
  * @author Mathias Schreck <https://github.com/lo1tuma>
4
+ * @deprecated in ESLint v8.53.0
4
5
  */
5
6
 
6
7
  "use strict";
@@ -39,6 +40,8 @@ const QUOTE_SETTINGS = {
39
40
  /** @type {import('../shared/types').Rule} */
40
41
  module.exports = {
41
42
  meta: {
43
+ deprecated: true,
44
+ replacedBy: [],
42
45
  type: "layout",
43
46
 
44
47
  docs: {
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * @fileoverview Rule to specify spacing of object literal keys and values
3
3
  * @author Brandon Mills
4
+ * @deprecated in ESLint v8.53.0
4
5
  */
5
6
  "use strict";
6
7
 
@@ -133,6 +134,8 @@ function initOptions(toOptions, fromOptions) {
133
134
  /** @type {import('../shared/types').Rule} */
134
135
  module.exports = {
135
136
  meta: {
137
+ deprecated: true,
138
+ replacedBy: [],
136
139
  type: "layout",
137
140
 
138
141
  docs: {
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * @fileoverview Rule to enforce spacing before and after keywords.
3
3
  * @author Toru Nagashima
4
+ * @deprecated in ESLint v8.53.0
4
5
  */
5
6
 
6
7
  "use strict";
@@ -64,6 +65,8 @@ function isCloseParenOfTemplate(token) {
64
65
  /** @type {import('../shared/types').Rule} */
65
66
  module.exports = {
66
67
  meta: {
68
+ deprecated: true,
69
+ replacedBy: [],
67
70
  type: "layout",
68
71
 
69
72
  docs: {
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * @fileoverview Rule to enforce a single linebreak style.
3
3
  * @author Erik Mueller
4
+ * @deprecated in ESLint v8.53.0
4
5
  */
5
6
 
6
7
  "use strict";
@@ -18,6 +19,8 @@ const astUtils = require("./utils/ast-utils");
18
19
  /** @type {import('../shared/types').Rule} */
19
20
  module.exports = {
20
21
  meta: {
22
+ deprecated: true,
23
+ replacedBy: [],
21
24
  type: "layout",
22
25
 
23
26
  docs: {
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * @fileoverview Enforces empty lines around comments.
3
3
  * @author Jamund Ferguson
4
+ * @deprecated in ESLint v8.53.0
4
5
  */
5
6
  "use strict";
6
7
 
@@ -52,6 +53,8 @@ function getCommentLineNums(comments) {
52
53
  /** @type {import('../shared/types').Rule} */
53
54
  module.exports = {
54
55
  meta: {
56
+ deprecated: true,
57
+ replacedBy: [],
55
58
  type: "layout",
56
59
 
57
60
  docs: {
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * @fileoverview Rule to check empty newline between class members
3
3
  * @author 薛定谔的猫<hh_2013@foxmail.com>
4
+ * @deprecated in ESLint v8.53.0
4
5
  */
5
6
  "use strict";
6
7
 
@@ -32,6 +33,8 @@ const ClassMemberTypes = {
32
33
  /** @type {import('../shared/types').Rule} */
33
34
  module.exports = {
34
35
  meta: {
36
+ deprecated: true,
37
+ replacedBy: [],
35
38
  type: "layout",
36
39
 
37
40
  docs: {
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * @fileoverview Rule to check for max length on a line.
3
3
  * @author Matt DuVall <http://www.mattduvall.com>
4
+ * @deprecated in ESLint v8.53.0
4
5
  */
5
6
 
6
7
  "use strict";
@@ -66,6 +67,8 @@ const OPTIONS_OR_INTEGER_SCHEMA = {
66
67
  /** @type {import('../shared/types').Rule} */
67
68
  module.exports = {
68
69
  meta: {
70
+ deprecated: true,
71
+ replacedBy: [],
69
72
  type: "layout",
70
73
 
71
74
  docs: {
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * @fileoverview Specify the maximum number of statements allowed per line.
3
3
  * @author Kenneth Williams
4
+ * @deprecated in ESLint v8.53.0
4
5
  */
5
6
  "use strict";
6
7
 
@@ -17,6 +18,8 @@ const astUtils = require("./utils/ast-utils");
17
18
  /** @type {import('../shared/types').Rule} */
18
19
  module.exports = {
19
20
  meta: {
21
+ deprecated: true,
22
+ replacedBy: [],
20
23
  type: "layout",
21
24
 
22
25
  docs: {
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * @fileoverview Enforce newlines between operands of ternary expressions
3
3
  * @author Kai Cataldo
4
+ * @deprecated in ESLint v8.53.0
4
5
  */
5
6
 
6
7
  "use strict";
@@ -14,6 +15,8 @@ const astUtils = require("./utils/ast-utils");
14
15
  /** @type {import('../shared/types').Rule} */
15
16
  module.exports = {
16
17
  meta: {
18
+ deprecated: true,
19
+ replacedBy: [],
17
20
  type: "layout",
18
21
 
19
22
  docs: {
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * @fileoverview Rule to flag when using constructor without parentheses
3
3
  * @author Ilya Volodin
4
+ * @deprecated in ESLint v8.53.0
4
5
  */
5
6
 
6
7
  "use strict";
@@ -22,6 +23,8 @@ const astUtils = require("./utils/ast-utils");
22
23
  /** @type {import('../shared/types').Rule} */
23
24
  module.exports = {
24
25
  meta: {
26
+ deprecated: true,
27
+ replacedBy: [],
25
28
  type: "layout",
26
29
 
27
30
  docs: {
@@ -2,6 +2,7 @@
2
2
  * @fileoverview Rule to ensure newline per method call when chaining calls
3
3
  * @author Rajendra Patil
4
4
  * @author Burak Yigit Kaya
5
+ * @deprecated in ESLint v8.53.0
5
6
  */
6
7
 
7
8
  "use strict";
@@ -15,6 +16,8 @@ const astUtils = require("./utils/ast-utils");
15
16
  /** @type {import('../shared/types').Rule} */
16
17
  module.exports = {
17
18
  meta: {
19
+ deprecated: true,
20
+ replacedBy: [],
18
21
  type: "layout",
19
22
 
20
23
  docs: {
@@ -2,6 +2,7 @@
2
2
  * @fileoverview A rule to warn against using arrow functions when they could be
3
3
  * confused with comparisons
4
4
  * @author Jxck <https://github.com/Jxck>
5
+ * @deprecated in ESLint v8.53.0
5
6
  */
6
7
 
7
8
  "use strict";
@@ -28,6 +29,8 @@ function isConditional(node) {
28
29
  /** @type {import('../shared/types').Rule} */
29
30
  module.exports = {
30
31
  meta: {
32
+ deprecated: true,
33
+ replacedBy: [],
31
34
  type: "suggestion",
32
35
 
33
36
  docs: {
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * @fileoverview Disallow parenthesising higher precedence subexpressions.
3
3
  * @author Michael Ficarra
4
+ * @deprecated in ESLint v8.53.0
4
5
  */
5
6
  "use strict";
6
7
 
@@ -14,6 +15,8 @@ const astUtils = require("./utils/ast-utils.js");
14
15
  /** @type {import('../shared/types').Rule} */
15
16
  module.exports = {
16
17
  meta: {
18
+ deprecated: true,
19
+ replacedBy: [],
17
20
  type: "layout",
18
21
 
19
22
  docs: {
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * @fileoverview Rule to flag use of unnecessary semicolons
3
3
  * @author Nicholas C. Zakas
4
+ * @deprecated in ESLint v8.53.0
4
5
  */
5
6
 
6
7
  "use strict";
@@ -19,6 +20,8 @@ const astUtils = require("./utils/ast-utils");
19
20
  /** @type {import('../shared/types').Rule} */
20
21
  module.exports = {
21
22
  meta: {
23
+ deprecated: true,
24
+ replacedBy: [],
22
25
  type: "suggestion",
23
26
 
24
27
  docs: {
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * @fileoverview Rule to flag use of a leading/trailing decimal point in a numeric literal
3
3
  * @author James Allardice
4
+ * @deprecated in ESLint v8.53.0
4
5
  */
5
6
 
6
7
  "use strict";
@@ -18,6 +19,8 @@ const astUtils = require("./utils/ast-utils");
18
19
  /** @type {import('../shared/types').Rule} */
19
20
  module.exports = {
20
21
  meta: {
22
+ deprecated: true,
23
+ replacedBy: [],
21
24
  type: "suggestion",
22
25
 
23
26
  docs: {
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * @fileoverview Rule to disallow mixed binary operators.
3
3
  * @author Toru Nagashima
4
+ * @deprecated in ESLint v8.53.0
4
5
  */
5
6
 
6
7
  "use strict";
@@ -85,6 +86,8 @@ function getChildNode(node) {
85
86
  /** @type {import('../shared/types').Rule} */
86
87
  module.exports = {
87
88
  meta: {
89
+ deprecated: true,
90
+ replacedBy: [],
88
91
  type: "suggestion",
89
92
 
90
93
  docs: {
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * @fileoverview Disallow mixed spaces and tabs for indentation
3
3
  * @author Jary Niebur
4
+ * @deprecated in ESLint v8.53.0
4
5
  */
5
6
  "use strict";
6
7
 
@@ -11,6 +12,8 @@
11
12
  /** @type {import('../shared/types').Rule} */
12
13
  module.exports = {
13
14
  meta: {
15
+ deprecated: true,
16
+ replacedBy: [],
14
17
  type: "layout",
15
18
 
16
19
  docs: {
@@ -1,6 +1,7 @@
1
1
  /**
2
2
  * @fileoverview Disallow use of multiple spaces.
3
3
  * @author Nicholas C. Zakas
4
+ * @deprecated in ESLint v8.53.0
4
5
  */
5
6
 
6
7
  "use strict";
@@ -14,6 +15,8 @@ const astUtils = require("./utils/ast-utils");
14
15
  /** @type {import('../shared/types').Rule} */
15
16
  module.exports = {
16
17
  meta: {
18
+ deprecated: true,
19
+ replacedBy: [],
17
20
  type: "layout",
18
21
 
19
22
  docs: {
@@ -2,6 +2,7 @@
2
2
  * @fileoverview Disallows multiple blank lines.
3
3
  * implementation adapted from the no-trailing-spaces rule.
4
4
  * @author Greg Cochard
5
+ * @deprecated in ESLint v8.53.0
5
6
  */
6
7
  "use strict";
7
8
 
@@ -12,6 +13,8 @@
12
13
  /** @type {import('../shared/types').Rule} */
13
14
  module.exports = {
14
15
  meta: {
16
+ deprecated: true,
17
+ replacedBy: [],
15
18
  type: "layout",
16
19
 
17
20
  docs: {
@@ -9,12 +9,51 @@
9
9
  // Requirements
10
10
  //------------------------------------------------------------------------------
11
11
 
12
- const { getVariableByName, isArrowToken } = require("./utils/ast-utils");
12
+ const { getVariableByName, isArrowToken, isClosingBraceToken, isClosingParenToken } = require("./utils/ast-utils");
13
13
 
14
14
  //------------------------------------------------------------------------------
15
15
  // Helpers
16
16
  //------------------------------------------------------------------------------
17
17
 
18
+ const BREAK_OR_CONTINUE = new Set(["BreakStatement", "ContinueStatement"]);
19
+
20
+ // Declaration types that must contain a string Literal node at the end.
21
+ const DECLARATIONS = new Set(["ExportAllDeclaration", "ExportNamedDeclaration", "ImportDeclaration"]);
22
+
23
+ const IDENTIFIER_OR_KEYWORD = new Set(["Identifier", "Keyword"]);
24
+
25
+ // Keywords that can immediately precede an ExpressionStatement node, mapped to the their node types.
26
+ const NODE_TYPES_BY_KEYWORD = {
27
+ __proto__: null,
28
+ break: "BreakStatement",
29
+ continue: "ContinueStatement",
30
+ debugger: "DebuggerStatement",
31
+ do: "DoWhileStatement",
32
+ else: "IfStatement",
33
+ return: "ReturnStatement",
34
+ yield: "YieldExpression"
35
+ };
36
+
37
+ /*
38
+ * Before an opening parenthesis, postfix `++` and `--` always trigger ASI;
39
+ * the tokens `:`, `;`, `{` and `=>` don't expect a semicolon, as that would count as an empty statement.
40
+ */
41
+ const PUNCTUATORS = new Set([":", ";", "{", "=>", "++", "--"]);
42
+
43
+ /*
44
+ * Statements that can contain an `ExpressionStatement` after a closing parenthesis.
45
+ * DoWhileStatement is an exception in that it always triggers ASI after the closing parenthesis.
46
+ */
47
+ const STATEMENTS = new Set([
48
+ "DoWhileStatement",
49
+ "ForInStatement",
50
+ "ForOfStatement",
51
+ "ForStatement",
52
+ "IfStatement",
53
+ "WhileStatement",
54
+ "WithStatement"
55
+ ]);
56
+
18
57
  /**
19
58
  * Tests if a node appears at the beginning of an ancestor ExpressionStatement node.
20
59
  * @param {ASTNode} node The node to check.
@@ -53,7 +92,8 @@ module.exports = {
53
92
 
54
93
  messages: {
55
94
  preferLiteral: "The object literal notation {} is preferable.",
56
- useLiteral: "Replace with '{{replacement}}'."
95
+ useLiteral: "Replace with '{{replacement}}'.",
96
+ useLiteralAfterSemicolon: "Replace with '{{replacement}}', add preceding semicolon."
57
97
  }
58
98
  },
59
99
 
@@ -80,6 +120,50 @@ module.exports = {
80
120
  return false;
81
121
  }
82
122
 
123
+ /**
124
+ * Determines whether a parenthesized object literal that replaces a specified node needs to be preceded by a semicolon.
125
+ * @param {ASTNode} node The node to be replaced. This node should be at the start of an `ExpressionStatement` or at the start of the body of an `ArrowFunctionExpression`.
126
+ * @returns {boolean} Whether a semicolon is required before the parenthesized object literal.
127
+ */
128
+ function needsSemicolon(node) {
129
+ const prevToken = sourceCode.getTokenBefore(node);
130
+
131
+ if (!prevToken || prevToken.type === "Punctuator" && PUNCTUATORS.has(prevToken.value)) {
132
+ return false;
133
+ }
134
+
135
+ const prevNode = sourceCode.getNodeByRangeIndex(prevToken.range[0]);
136
+
137
+ if (isClosingParenToken(prevToken)) {
138
+ return !STATEMENTS.has(prevNode.type);
139
+ }
140
+
141
+ if (isClosingBraceToken(prevToken)) {
142
+ return (
143
+ prevNode.type === "BlockStatement" && prevNode.parent.type === "FunctionExpression" ||
144
+ prevNode.type === "ClassBody" && prevNode.parent.type === "ClassExpression" ||
145
+ prevNode.type === "ObjectExpression"
146
+ );
147
+ }
148
+
149
+ if (IDENTIFIER_OR_KEYWORD.has(prevToken.type)) {
150
+ if (BREAK_OR_CONTINUE.has(prevNode.parent.type)) {
151
+ return false;
152
+ }
153
+
154
+ const keyword = prevToken.value;
155
+ const nodeType = NODE_TYPES_BY_KEYWORD[keyword];
156
+
157
+ return prevNode.type !== nodeType;
158
+ }
159
+
160
+ if (prevToken.type === "String") {
161
+ return !DECLARATIONS.has(prevNode.parent.type);
162
+ }
163
+
164
+ return true;
165
+ }
166
+
83
167
  /**
84
168
  * Reports on nodes where the `Object` constructor is called without arguments.
85
169
  * @param {ASTNode} node The node to evaluate.
@@ -93,16 +177,30 @@ module.exports = {
93
177
  const variable = getVariableByName(sourceCode.getScope(node), "Object");
94
178
 
95
179
  if (variable && variable.identifiers.length === 0) {
96
- const replacement = needsParentheses(node) ? "({})" : "{}";
180
+ let replacement;
181
+ let fixText;
182
+ let messageId = "useLiteral";
183
+
184
+ if (needsParentheses(node)) {
185
+ replacement = "({})";
186
+ if (needsSemicolon(node)) {
187
+ fixText = ";({})";
188
+ messageId = "useLiteralAfterSemicolon";
189
+ } else {
190
+ fixText = "({})";
191
+ }
192
+ } else {
193
+ replacement = fixText = "{}";
194
+ }
97
195
 
98
196
  context.report({
99
197
  node,
100
198
  messageId: "preferLiteral",
101
199
  suggest: [
102
200
  {
103
- messageId: "useLiteral",
201
+ messageId,
104
202
  data: { replacement },
105
- fix: fixer => fixer.replaceText(node, replacement)
203
+ fix: fixer => fixer.replaceText(node, fixText)
106
204
  }
107
205
  ]
108
206
  });