eslint 4.15.0 → 4.18.1

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 (90) hide show
  1. package/CHANGELOG.md +56 -0
  2. package/lib/config/config-validator.js +9 -2
  3. package/lib/linter.js +38 -19
  4. package/lib/options.js +7 -7
  5. package/lib/report-translator.js +28 -37
  6. package/lib/rules/accessor-pairs.js +7 -3
  7. package/lib/rules/array-bracket-newline.js +11 -5
  8. package/lib/rules/array-bracket-spacing.js +11 -5
  9. package/lib/rules/array-callback-return.js +11 -5
  10. package/lib/rules/array-element-newline.js +8 -3
  11. package/lib/rules/arrow-body-style.js +16 -8
  12. package/lib/rules/arrow-parens.js +13 -9
  13. package/lib/rules/arrow-spacing.js +13 -5
  14. package/lib/rules/block-scoped-var.js +6 -2
  15. package/lib/rules/block-spacing.js +13 -6
  16. package/lib/rules/brace-style.js +16 -14
  17. package/lib/rules/callback-return.js +6 -2
  18. package/lib/rules/camelcase.js +6 -2
  19. package/lib/rules/capitalized-comments.js +11 -8
  20. package/lib/rules/class-methods-use-this.js +7 -3
  21. package/lib/rules/comma-dangle.js +7 -4
  22. package/lib/rules/comma-spacing.js +13 -10
  23. package/lib/rules/comma-style.js +16 -5
  24. package/lib/rules/complexity.js +6 -2
  25. package/lib/rules/computed-property-spacing.js +13 -5
  26. package/lib/rules/consistent-return.js +12 -7
  27. package/lib/rules/consistent-this.js +9 -4
  28. package/lib/rules/constructor-super.js +17 -8
  29. package/lib/rules/curly.js +59 -80
  30. package/lib/rules/default-case.js +6 -2
  31. package/lib/rules/dot-location.js +8 -3
  32. package/lib/rules/dot-notation.js +10 -5
  33. package/lib/rules/eol-last.js +7 -3
  34. package/lib/rules/eqeqeq.js +6 -2
  35. package/lib/rules/guard-for-in.js +35 -7
  36. package/lib/rules/indent.js +4 -4
  37. package/lib/rules/key-spacing.js +3 -2
  38. package/lib/rules/keyword-spacing.js +6 -1
  39. package/lib/rules/no-alert.js +19 -18
  40. package/lib/rules/no-array-constructor.js +6 -2
  41. package/lib/rules/no-await-in-loop.js +75 -57
  42. package/lib/rules/no-bitwise.js +6 -2
  43. package/lib/rules/no-buffer-constructor.js +6 -3
  44. package/lib/rules/no-caller.js +6 -2
  45. package/lib/rules/no-case-declarations.js +6 -2
  46. package/lib/rules/no-catch-shadow.js +6 -2
  47. package/lib/rules/no-class-assign.js +6 -2
  48. package/lib/rules/no-compare-neg-zero.js +5 -2
  49. package/lib/rules/no-cond-assign.js +10 -4
  50. package/lib/rules/no-confusing-arrow.js +6 -2
  51. package/lib/rules/no-console.js +6 -2
  52. package/lib/rules/no-const-assign.js +6 -2
  53. package/lib/rules/no-constant-condition.js +6 -3
  54. package/lib/rules/no-continue.js +6 -2
  55. package/lib/rules/no-control-regex.js +7 -3
  56. package/lib/rules/no-debugger.js +5 -2
  57. package/lib/rules/no-delete-var.js +6 -2
  58. package/lib/rules/no-div-regex.js +6 -2
  59. package/lib/rules/no-dupe-args.js +6 -2
  60. package/lib/rules/no-dupe-class-members.js +6 -2
  61. package/lib/rules/no-dupe-keys.js +6 -2
  62. package/lib/rules/no-duplicate-case.js +6 -2
  63. package/lib/rules/no-else-return.js +7 -2
  64. package/lib/rules/no-empty-character-class.js +6 -2
  65. package/lib/rules/no-empty-function.js +6 -2
  66. package/lib/rules/no-empty-pattern.js +7 -3
  67. package/lib/rules/no-empty.js +7 -3
  68. package/lib/rules/no-eq-null.js +6 -2
  69. package/lib/rules/no-eval.js +6 -2
  70. package/lib/rules/no-ex-assign.js +6 -2
  71. package/lib/rules/no-extend-native.js +6 -2
  72. package/lib/rules/no-extra-bind.js +6 -2
  73. package/lib/rules/no-extra-boolean-cast.js +8 -3
  74. package/lib/rules/no-extra-label.js +6 -2
  75. package/lib/rules/no-extra-parens.js +5 -1
  76. package/lib/rules/no-extra-semi.js +6 -2
  77. package/lib/rules/no-self-assign.js +3 -1
  78. package/lib/rules/no-unused-vars.js +1 -1
  79. package/lib/rules/object-curly-newline.js +67 -19
  80. package/lib/rules/object-property-newline.js +8 -2
  81. package/lib/rules/object-shorthand.js +9 -7
  82. package/lib/rules/padding-line-between-statements.js +6 -0
  83. package/lib/rules/prefer-destructuring.js +4 -2
  84. package/lib/rules/require-await.js +5 -0
  85. package/lib/rules/rest-spread-spacing.js +6 -0
  86. package/lib/rules/space-unary-ops.js +1 -10
  87. package/lib/rules/valid-jsdoc.js +89 -28
  88. package/lib/util/glob-util.js +17 -4
  89. package/lib/util/npm-util.js +1 -1
  90. package/package.json +2 -2
@@ -99,7 +99,16 @@ module.exports = {
99
99
  url: "https://eslint.org/docs/rules/constructor-super"
100
100
  },
101
101
 
102
- schema: []
102
+ schema: [],
103
+
104
+ messages: {
105
+ missingSome: "Lacked a call of 'super()' in some code paths.",
106
+ missingAll: "Expected to call 'super()'.",
107
+
108
+ duplicate: "Unexpected duplicate 'super()'.",
109
+ badSuper: "Unexpected 'super()' because 'super' is not a constructor.",
110
+ unexpected: "Unexpected 'super()'."
111
+ }
103
112
  },
104
113
 
105
114
  create(context) {
@@ -210,9 +219,9 @@ module.exports = {
210
219
 
211
220
  if (!calledInEveryPaths) {
212
221
  context.report({
213
- message: calledInSomePaths
214
- ? "Lacked a call of 'super()' in some code paths."
215
- : "Expected to call 'super()'.",
222
+ messageId: calledInSomePaths
223
+ ? "missingSome"
224
+ : "missingAll",
216
225
  node: node.parent
217
226
  });
218
227
  }
@@ -281,7 +290,7 @@ module.exports = {
281
290
  const node = nodes[i];
282
291
 
283
292
  context.report({
284
- message: "Unexpected duplicate 'super()'.",
293
+ messageId: "duplicate",
285
294
  node
286
295
  });
287
296
  }
@@ -325,12 +334,12 @@ module.exports = {
325
334
  if (info) {
326
335
  if (duplicate) {
327
336
  context.report({
328
- message: "Unexpected duplicate 'super()'.",
337
+ messageId: "duplicate",
329
338
  node
330
339
  });
331
340
  } else if (!funcInfo.superIsConstructor) {
332
341
  context.report({
333
- message: "Unexpected 'super()' because 'super' is not a constructor.",
342
+ messageId: "badSuper",
334
343
  node
335
344
  });
336
345
  } else {
@@ -339,7 +348,7 @@ module.exports = {
339
348
  }
340
349
  } else if (funcInfo.codePath.currentSegments.some(isReachable)) {
341
350
  context.report({
342
- message: "Unexpected 'super()'.",
351
+ messageId: "unexpected",
343
352
  node
344
353
  });
345
354
  }
@@ -51,7 +51,14 @@ module.exports = {
51
51
  ]
52
52
  },
53
53
 
54
- fixable: "code"
54
+ fixable: "code",
55
+
56
+ messages: {
57
+ missingCurlyAfter: "Expected { after '{{name}}'.",
58
+ missingCurlyAfterCondition: "Expected { after '{{name}}' condition.",
59
+ unexpectedCurlyAfter: "Unnecessary { after '{{name}}'.",
60
+ unexpectedCurlyAfterCondition: "Unnecessary { after '{{name}}' condition."
61
+ }
55
62
  },
56
63
 
57
64
  create(context) {
@@ -142,28 +149,6 @@ module.exports = {
142
149
  return false;
143
150
  }
144
151
 
145
- /**
146
- * Reports "Expected { after ..." error
147
- * @param {ASTNode} node The node to report.
148
- * @param {ASTNode} bodyNode The body node that is incorrectly missing curly brackets
149
- * @param {string} name The name to report.
150
- * @param {string} suffix Additional string to add to the end of a report.
151
- * @returns {void}
152
- * @private
153
- */
154
- function reportExpectedBraceError(node, bodyNode, name, suffix) {
155
- context.report({
156
- node,
157
- loc: (name !== "else" ? node : getElseKeyword(node)).loc.start,
158
- message: "Expected { after '{{name}}'{{suffix}}.",
159
- data: {
160
- name,
161
- suffix: (suffix ? ` ${suffix}` : "")
162
- },
163
- fix: fixer => fixer.replaceText(bodyNode, `{${sourceCode.getText(bodyNode)}}`)
164
- });
165
- }
166
-
167
152
  /**
168
153
  * Determines if a semicolon needs to be inserted after removing a set of curly brackets, in order to avoid a SyntaxError.
169
154
  * @param {Token} closingBracket The } token
@@ -218,62 +203,12 @@ module.exports = {
218
203
  return false;
219
204
  }
220
205
 
221
- /**
222
- * Reports "Unnecessary { after ..." error
223
- * @param {ASTNode} node The node to report.
224
- * @param {ASTNode} bodyNode The block statement that is incorrectly surrounded by parens
225
- * @param {string} name The name to report.
226
- * @param {string} suffix Additional string to add to the end of a report.
227
- * @returns {void}
228
- * @private
229
- */
230
- function reportUnnecessaryBraceError(node, bodyNode, name, suffix) {
231
- context.report({
232
- node,
233
- loc: (name !== "else" ? node : getElseKeyword(node)).loc.start,
234
- message: "Unnecessary { after '{{name}}'{{suffix}}.",
235
- data: {
236
- name,
237
- suffix: (suffix ? ` ${suffix}` : "")
238
- },
239
- fix(fixer) {
240
-
241
- /*
242
- * `do while` expressions sometimes need a space to be inserted after `do`.
243
- * e.g. `do{foo()} while (bar)` should be corrected to `do foo() while (bar)`
244
- */
245
- const needsPrecedingSpace = node.type === "DoWhileStatement" &&
246
- sourceCode.getTokenBefore(bodyNode).range[1] === bodyNode.range[0] &&
247
- !astUtils.canTokensBeAdjacent("do", sourceCode.getFirstToken(bodyNode, { skip: 1 }));
248
-
249
- const openingBracket = sourceCode.getFirstToken(bodyNode);
250
- const closingBracket = sourceCode.getLastToken(bodyNode);
251
- const lastTokenInBlock = sourceCode.getTokenBefore(closingBracket);
252
-
253
- if (needsSemicolon(closingBracket)) {
254
-
255
- /*
256
- * If removing braces would cause a SyntaxError due to multiple statements on the same line (or
257
- * change the semantics of the code due to ASI), don't perform a fix.
258
- */
259
- return null;
260
- }
261
-
262
- const resultingBodyText = sourceCode.getText().slice(openingBracket.range[1], lastTokenInBlock.range[0]) +
263
- sourceCode.getText(lastTokenInBlock) +
264
- sourceCode.getText().slice(lastTokenInBlock.range[1], closingBracket.range[0]);
265
-
266
- return fixer.replaceText(bodyNode, (needsPrecedingSpace ? " " : "") + resultingBodyText);
267
- }
268
- });
269
- }
270
-
271
206
  /**
272
207
  * Prepares to check the body of a node to see if it's a block statement.
273
208
  * @param {ASTNode} node The node to report if there's a problem.
274
209
  * @param {ASTNode} body The body node to check for blocks.
275
210
  * @param {string} name The name to report if there's a problem.
276
- * @param {string} suffix Additional string to add to the end of a report.
211
+ * @param {{ condition: boolean }} opts Options to pass to the report functions
277
212
  * @returns {Object} a prepared check object, with "actual", "expected", "check" properties.
278
213
  * "actual" will be `true` or `false` whether the body is already a block statement.
279
214
  * "expected" will be `true` or `false` if the body should be a block statement or not, or
@@ -282,7 +217,7 @@ module.exports = {
282
217
  * "check" will be a function reporting appropriate problems depending on the other
283
218
  * properties.
284
219
  */
285
- function prepareCheck(node, body, name, suffix) {
220
+ function prepareCheck(node, body, name, opts) {
286
221
  const hasBlock = (body.type === "BlockStatement");
287
222
  let expected = null;
288
223
 
@@ -314,9 +249,53 @@ module.exports = {
314
249
  check() {
315
250
  if (this.expected !== null && this.expected !== this.actual) {
316
251
  if (this.expected) {
317
- reportExpectedBraceError(node, body, name, suffix);
252
+ context.report({
253
+ node,
254
+ loc: (name !== "else" ? node : getElseKeyword(node)).loc.start,
255
+ messageId: opts && opts.condition ? "missingCurlyAfterCondition" : "missingCurlyAfter",
256
+ data: {
257
+ name
258
+ },
259
+ fix: fixer => fixer.replaceText(body, `{${sourceCode.getText(body)}}`)
260
+ });
318
261
  } else {
319
- reportUnnecessaryBraceError(node, body, name, suffix);
262
+ context.report({
263
+ node,
264
+ loc: (name !== "else" ? node : getElseKeyword(node)).loc.start,
265
+ messageId: opts && opts.condition ? "unexpectedCurlyAfterCondition" : "unexpectedCurlyAfter",
266
+ data: {
267
+ name
268
+ },
269
+ fix(fixer) {
270
+
271
+ /*
272
+ * `do while` expressions sometimes need a space to be inserted after `do`.
273
+ * e.g. `do{foo()} while (bar)` should be corrected to `do foo() while (bar)`
274
+ */
275
+ const needsPrecedingSpace = node.type === "DoWhileStatement" &&
276
+ sourceCode.getTokenBefore(body).range[1] === body.range[0] &&
277
+ !astUtils.canTokensBeAdjacent("do", sourceCode.getFirstToken(body, { skip: 1 }));
278
+
279
+ const openingBracket = sourceCode.getFirstToken(body);
280
+ const closingBracket = sourceCode.getLastToken(body);
281
+ const lastTokenInBlock = sourceCode.getTokenBefore(closingBracket);
282
+
283
+ if (needsSemicolon(closingBracket)) {
284
+
285
+ /*
286
+ * If removing braces would cause a SyntaxError due to multiple statements on the same line (or
287
+ * change the semantics of the code due to ASI), don't perform a fix.
288
+ */
289
+ return null;
290
+ }
291
+
292
+ const resultingBodyText = sourceCode.getText().slice(openingBracket.range[1], lastTokenInBlock.range[0]) +
293
+ sourceCode.getText(lastTokenInBlock) +
294
+ sourceCode.getText().slice(lastTokenInBlock.range[1], closingBracket.range[0]);
295
+
296
+ return fixer.replaceText(body, (needsPrecedingSpace ? " " : "") + resultingBodyText);
297
+ }
298
+ });
320
299
  }
321
300
  }
322
301
  }
@@ -333,7 +312,7 @@ module.exports = {
333
312
  const preparedChecks = [];
334
313
 
335
314
  do {
336
- preparedChecks.push(prepareCheck(node, node.consequent, "if", "condition"));
315
+ preparedChecks.push(prepareCheck(node, node.consequent, "if", { condition: true }));
337
316
  if (node.alternate && node.alternate.type !== "IfStatement") {
338
317
  preparedChecks.push(prepareCheck(node, node.alternate, "else"));
339
318
  break;
@@ -377,7 +356,7 @@ module.exports = {
377
356
  },
378
357
 
379
358
  WhileStatement(node) {
380
- prepareCheck(node, node.body, "while", "condition").check();
359
+ prepareCheck(node, node.body, "while", { condition: true }).check();
381
360
  },
382
361
 
383
362
  DoWhileStatement(node) {
@@ -385,7 +364,7 @@ module.exports = {
385
364
  },
386
365
 
387
366
  ForStatement(node) {
388
- prepareCheck(node, node.body, "for", "condition").check();
367
+ prepareCheck(node, node.body, "for", { condition: true }).check();
389
368
  },
390
369
 
391
370
  ForInStatement(node) {
@@ -27,7 +27,11 @@ module.exports = {
27
27
  }
28
28
  },
29
29
  additionalProperties: false
30
- }]
30
+ }],
31
+
32
+ messages: {
33
+ missingDefaultCase: "Expected a default case."
34
+ }
31
35
  },
32
36
 
33
37
  create(context) {
@@ -82,7 +86,7 @@ module.exports = {
82
86
  }
83
87
 
84
88
  if (!comment || !commentPattern.test(comment.value.trim())) {
85
- context.report({ node, message: "Expected a default case." });
89
+ context.report({ node, messageId: "missingDefaultCase" });
86
90
  }
87
91
  }
88
92
  }
@@ -26,7 +26,12 @@ module.exports = {
26
26
  }
27
27
  ],
28
28
 
29
- fixable: "code"
29
+ fixable: "code",
30
+
31
+ messages: {
32
+ expectedDotAfterObject: "Expected dot to be on same line as object.",
33
+ expectedDotBeforeProperty: "Expected dot to be on same line as property."
34
+ }
30
35
  },
31
36
 
32
37
  create(context) {
@@ -58,7 +63,7 @@ module.exports = {
58
63
  context.report({
59
64
  node,
60
65
  loc: dot.loc.start,
61
- message: "Expected dot to be on same line as object.",
66
+ messageId: "expectedDotAfterObject",
62
67
  fix: fixer => fixer.replaceTextRange([obj.range[1], prop.range[0]], `${neededTextAfterObj}.${textBeforeDot}${textAfterDot}`)
63
68
  });
64
69
  }
@@ -66,7 +71,7 @@ module.exports = {
66
71
  context.report({
67
72
  node,
68
73
  loc: dot.loc.start,
69
- message: "Expected dot to be on same line as property.",
74
+ messageId: "expectedDotBeforeProperty",
70
75
  fix: fixer => fixer.replaceTextRange([obj.range[1], prop.range[0]], `${textBeforeDot}${textAfterDot}.`)
71
76
  });
72
77
  }
@@ -41,7 +41,12 @@ module.exports = {
41
41
  }
42
42
  ],
43
43
 
44
- fixable: "code"
44
+ fixable: "code",
45
+
46
+ messages: {
47
+ useDot: "[{{key}}] is better written in dot notation.",
48
+ useBrackets: ".{{key}} is a syntax error."
49
+ }
45
50
  },
46
51
 
47
52
  create(context) {
@@ -71,9 +76,9 @@ module.exports = {
71
76
 
72
77
  context.report({
73
78
  node: node.property,
74
- message: "[{{propertyValue}}] is better written in dot notation.",
79
+ messageId: "useDot",
75
80
  data: {
76
- propertyValue: formattedValue
81
+ key: formattedValue
77
82
  },
78
83
  fix(fixer) {
79
84
  const leftBracket = sourceCode.getTokenAfter(node.object, astUtils.isOpeningBracketToken);
@@ -124,9 +129,9 @@ module.exports = {
124
129
  ) {
125
130
  context.report({
126
131
  node: node.property,
127
- message: ".{{propertyName}} is a syntax error.",
132
+ messageId: "useBrackets",
128
133
  data: {
129
- propertyName: node.property.name
134
+ key: node.property.name
130
135
  },
131
136
  fix(fixer) {
132
137
  const dot = sourceCode.getTokenBefore(node.property);
@@ -27,7 +27,11 @@ module.exports = {
27
27
  {
28
28
  enum: ["always", "never", "unix", "windows"]
29
29
  }
30
- ]
30
+ ],
31
+ messages: {
32
+ missing: "Newline required at end of file but not found.",
33
+ unexpected: "Newline not allowed at end of file."
34
+ }
31
35
  },
32
36
  create(context) {
33
37
 
@@ -75,7 +79,7 @@ module.exports = {
75
79
  context.report({
76
80
  node,
77
81
  loc: location,
78
- message: "Newline required at end of file but not found.",
82
+ messageId: "missing",
79
83
  fix(fixer) {
80
84
  return fixer.insertTextAfterRange([0, src.length], appendCRLF ? CRLF : LF);
81
85
  }
@@ -86,7 +90,7 @@ module.exports = {
86
90
  context.report({
87
91
  node,
88
92
  loc: location,
89
- message: "Newline not allowed at end of file.",
93
+ messageId: "unexpected",
90
94
  fix(fixer) {
91
95
  const finalEOLs = /(?:\r?\n)+$/,
92
96
  match = finalEOLs.exec(sourceCode.text),
@@ -56,7 +56,11 @@ module.exports = {
56
56
  ]
57
57
  },
58
58
 
59
- fixable: "code"
59
+ fixable: "code",
60
+
61
+ messages: {
62
+ unexpected: "Expected '{{expectedOperator}}' and instead saw '{{actualOperator}}'."
63
+ }
60
64
  },
61
65
 
62
66
  create(context) {
@@ -134,7 +138,7 @@ module.exports = {
134
138
  context.report({
135
139
  node,
136
140
  loc: getOperatorLocation(node),
137
- message: "Expected '{{expectedOperator}}' and instead saw '{{actualOperator}}'.",
141
+ messageId: "unexpected",
138
142
  data: { expectedOperator, actualOperator: node.operator },
139
143
  fix(fixer) {
140
144
 
@@ -26,16 +26,44 @@ module.exports = {
26
26
  return {
27
27
 
28
28
  ForInStatement(node) {
29
+ const body = node.body;
29
30
 
30
- /*
31
- * If the for-in statement has {}, then the real body is the body
32
- * of the BlockStatement. Otherwise, just use body as provided.
33
- */
34
- const body = node.body.type === "BlockStatement" ? node.body.body[0] : node.body;
31
+ // empty statement
32
+ if (body.type === "EmptyStatement") {
33
+ return;
34
+ }
35
+
36
+ // if statement
37
+ if (body.type === "IfStatement") {
38
+ return;
39
+ }
40
+
41
+ // empty block
42
+ if (body.type === "BlockStatement" && body.body.length === 0) {
43
+ return;
44
+ }
35
45
 
36
- if (body && body.type !== "IfStatement") {
37
- context.report({ node, message: "The body of a for-in should be wrapped in an if statement to filter unwanted properties from the prototype." });
46
+ // block with just if statement
47
+ if (body.type === "BlockStatement" && body.body.length === 1 && body.body[0].type === "IfStatement") {
48
+ return;
38
49
  }
50
+
51
+ // block that starts with if statement
52
+ if (body.type === "BlockStatement" && body.body.length >= 1 && body.body[0].type === "IfStatement") {
53
+ const i = body.body[0];
54
+
55
+ // ... whose consequent is a continue
56
+ if (i.consequent.type === "ContinueStatement") {
57
+ return;
58
+ }
59
+
60
+ // ... whose consequent is a block that contains only a continue
61
+ if (i.consequent.type === "BlockStatement" && i.consequent.body.length === 1 && i.consequent.body[0].type === "ContinueStatement") {
62
+ return;
63
+ }
64
+ }
65
+
66
+ context.report({ node, message: "The body of a for-in should be wrapped in an if statement to filter unwanted properties from the prototype." });
39
67
  }
40
68
  };
41
69
 
@@ -442,6 +442,7 @@ class OffsetStorage {
442
442
  const offset = (
443
443
  offsetInfo.from &&
444
444
  offsetInfo.from.loc.start.line === token.loc.start.line &&
445
+ !/^\s*?\n/.test(token.value) &&
445
446
  !offsetInfo.force
446
447
  ) ? 0 : offsetInfo.offset * this._indentSize;
447
448
 
@@ -836,7 +837,7 @@ module.exports = {
836
837
  const previousElement = elements[index - 1];
837
838
  const firstTokenOfPreviousElement = previousElement && getFirstToken(previousElement);
838
839
 
839
- if (previousElement && sourceCode.getLastToken(previousElement).loc.start.line > startToken.loc.end.line) {
840
+ if (previousElement && sourceCode.getLastToken(previousElement).loc.end.line > startToken.loc.end.line) {
840
841
  offsets.setDesiredOffsets(element.range, firstTokenOfPreviousElement, 0);
841
842
  }
842
843
  }
@@ -1042,7 +1043,6 @@ module.exports = {
1042
1043
  offsets.ignoreToken(operator);
1043
1044
  offsets.ignoreToken(tokenAfterOperator);
1044
1045
  offsets.setDesiredOffset(tokenAfterOperator, operator, 0);
1045
- offsets.setDesiredOffsets([tokenAfterOperator.range[1], node.range[1]], tokenAfterOperator, 1);
1046
1046
  },
1047
1047
 
1048
1048
  "BlockStatement, ClassBody"(node) {
@@ -1094,8 +1094,8 @@ module.exports = {
1094
1094
  const questionMarkToken = sourceCode.getFirstTokenBetween(node.test, node.consequent, token => token.type === "Punctuator" && token.value === "?");
1095
1095
  const colonToken = sourceCode.getFirstTokenBetween(node.consequent, node.alternate, token => token.type === "Punctuator" && token.value === ":");
1096
1096
 
1097
- const firstConsequentToken = sourceCode.getTokenAfter(questionMarkToken, { includeComments: true });
1098
- const lastConsequentToken = sourceCode.getTokenBefore(colonToken, { includeComments: true });
1097
+ const firstConsequentToken = sourceCode.getTokenAfter(questionMarkToken);
1098
+ const lastConsequentToken = sourceCode.getTokenBefore(colonToken);
1099
1099
  const firstAlternateToken = sourceCode.getTokenAfter(colonToken);
1100
1100
 
1101
1101
  offsets.setDesiredOffset(questionMarkToken, firstToken, 1);
@@ -360,9 +360,10 @@ module.exports = {
360
360
  */
361
361
  function isKeyValueProperty(property) {
362
362
  return !(
363
- (property.method ||
363
+ property.method ||
364
364
  property.shorthand ||
365
- property.kind !== "init" || property.type !== "Property") // Could be "ExperimentalSpreadProperty" or "SpreadProperty"
365
+ property.kind !== "init" ||
366
+ property.type !== "Property" // Could be "ExperimentalSpreadProperty" or "SpreadElement"
366
367
  );
367
368
  }
368
369
 
@@ -436,7 +436,12 @@ module.exports = {
436
436
  * @returns {void}
437
437
  */
438
438
  function checkSpacingForForOfStatement(node) {
439
- checkSpacingAroundFirstToken(node);
439
+ if (node.await) {
440
+ checkSpacingBefore(sourceCode.getFirstToken(node, 0));
441
+ checkSpacingAfter(sourceCode.getFirstToken(node, 1));
442
+ } else {
443
+ checkSpacingAroundFirstToken(node);
444
+ }
440
445
  checkSpacingAround(sourceCode.getTokenBefore(node.right, astUtils.isNotOpeningParenToken));
441
446
  }
442
447
 
@@ -23,17 +23,6 @@ function isProhibitedIdentifier(name) {
23
23
  return /^(alert|confirm|prompt)$/.test(name);
24
24
  }
25
25
 
26
- /**
27
- * Reports the given node and identifier name.
28
- * @param {RuleContext} context The ESLint rule context.
29
- * @param {ASTNode} node The node to report on.
30
- * @param {string} identifierName The name of the identifier.
31
- * @returns {void}
32
- */
33
- function report(context, node, identifierName) {
34
- context.report(node, "Unexpected {{name}}.", { name: identifierName });
35
- }
36
-
37
26
  /**
38
27
  * Finds the eslint-scope reference in the given scope.
39
28
  * @param {Object} scope The scope to search.
@@ -92,7 +81,11 @@ module.exports = {
92
81
  url: "https://eslint.org/docs/rules/no-alert"
93
82
  },
94
83
 
95
- schema: []
84
+ schema: [],
85
+
86
+ messages: {
87
+ unexpected: "Unexpected {{name}}."
88
+ }
96
89
  },
97
90
 
98
91
  create(context) {
@@ -103,17 +96,25 @@ module.exports = {
103
96
 
104
97
  // without window.
105
98
  if (callee.type === "Identifier") {
106
- const identifierName = callee.name;
99
+ const name = callee.name;
107
100
 
108
101
  if (!isShadowed(currentScope, callee) && isProhibitedIdentifier(callee.name)) {
109
- report(context, node, identifierName);
102
+ context.report({
103
+ node,
104
+ messageId: "unexpected",
105
+ data: { name }
106
+ });
110
107
  }
111
108
 
112
109
  } else if (callee.type === "MemberExpression" && isGlobalThisReferenceOrGlobalWindow(currentScope, callee.object)) {
113
- const identifierName = getPropertyName(callee);
114
-
115
- if (isProhibitedIdentifier(identifierName)) {
116
- report(context, node, identifierName);
110
+ const name = getPropertyName(callee);
111
+
112
+ if (isProhibitedIdentifier(name)) {
113
+ context.report({
114
+ node,
115
+ messageId: "unexpected",
116
+ data: { name }
117
+ });
117
118
  }
118
119
  }
119
120
 
@@ -18,7 +18,11 @@ module.exports = {
18
18
  url: "https://eslint.org/docs/rules/no-array-constructor"
19
19
  },
20
20
 
21
- schema: []
21
+ schema: [],
22
+
23
+ messages: {
24
+ preferLiteral: "The array literal notation [] is preferable."
25
+ }
22
26
  },
23
27
 
24
28
  create(context) {
@@ -35,7 +39,7 @@ module.exports = {
35
39
  node.callee.type === "Identifier" &&
36
40
  node.callee.name === "Array"
37
41
  ) {
38
- context.report({ node, message: "The array literal notation [] is preferrable." });
42
+ context.report({ node, messageId: "preferLiteral" });
39
43
  }
40
44
  }
41
45