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
package/CHANGELOG.md CHANGED
@@ -1,3 +1,59 @@
1
+ v4.18.1 - February 20, 2018
2
+
3
+ * f417506 Fix: ensure no-await-in-loop reports the correct node (fixes #9992) (#9993) (Teddy Katz)
4
+ * 3e99363 Docs: Fixed typo in key-spacing rule doc (#9987) (Jaid)
5
+ * 7c2cd70 Docs: deprecate experimentalObjectRestSpread (#9986) (Toru Nagashima)
6
+
7
+ v4.18.0 - February 16, 2018
8
+
9
+ * 70f22f3 Chore: Apply memoization to config creation within glob utils (#9944) (Kenton Jacobsen)
10
+ * 0e4ae22 Update: fix indent bug with binary operators/ignoredNodes (fixes #9882) (#9951) (Teddy Katz)
11
+ * 47ac478 Update: add named imports and exports for object-curly-newline (#9876) (Nicholas Chua)
12
+ * e8efdd0 Fix: support Rest/Spread Properties (fixes #9885) (#9943) (Toru Nagashima)
13
+ * f012b8c Fix: support Async iteration (fixes #9891) (#9957) (Toru Nagashima)
14
+ * 74fa253 Docs: Clarify no-mixed-operators options (fixes #9962) (#9964) (Ivan Hayes)
15
+ * 426868f Docs: clean up key-spacing docs (fixes #9900) (#9963) (Abid Uzair)
16
+ * 4a6f22e Update: support eslint-disable-* block comments (fixes #8781) (#9745) (Erin)
17
+ * 777283b Docs: Propose fix typo for function (#9965) (John Eismeier)
18
+ * bf3d494 Docs: Fix typo in max-len ignorePattern example. (#9956) (Tim Martin)
19
+ * d64fbb4 Docs: fix typo in prefer-destructuring.md example (#9930) (Vse Mozhet Byt)
20
+ * f8d343f Chore: Fix default issue template (#9946) (Kai Cataldo)
21
+
22
+ v4.17.0 - February 2, 2018
23
+
24
+ * 1da1ada Update: Add "multiline" type to padding-line-between-statements (#8668) (Matthew Bennett)
25
+ * bb213dc Chore: Use messageIds in some of the core rules (#9648) (Jed Fox)
26
+ * 1aa1970 Docs: remove outdated rule naming convention (#9925) (Teddy Katz)
27
+ * 3afaff6 Docs: Add prefer-destructuring variable reassignment example (#9873) (LePirlouit)
28
+ * d20f6b4 Fix: Typo in error message when running npm (#9866) (Maciej Kasprzyk)
29
+ * 51ec6a7 Docs: Use GitHub Multiple PR/Issue templates (#9911) (Kai Cataldo)
30
+ * dc80487 Update: space-unary-ops uses astUtils.canTokensBeAdjacent (fixes #9907) (#9906) (Kevin Partington)
31
+ * 084351b Docs: Fix the messageId example (fixes #9889) (#9892) (Jed Fox)
32
+ * 9cbb487 Docs: Mention the `globals` key in the no-undef docs (#9867) (Dan Dascalescu)
33
+
34
+ v4.16.0 - January 19, 2018
35
+
36
+ * e26a25f Update: allow continue instead of if wrap in guard-for-in (fixes #7567) (#9796) (Michael Ficarra)
37
+ * af043eb Update: Add NewExpression support to comma-style (#9591) (Frazer McLean)
38
+ * 4f898c7 Build: Fix JSDoc syntax errors (#9813) (Matija Marohnić)
39
+ * 13bcf3c Fix: Removing curly quotes in no-eq-null report message (#9852) (Kevin Partington)
40
+ * b96fb31 Docs: configuration hierarchy for CLIEngine options (fixes #9526) (#9855) (PiIsFour)
41
+ * 8ccbdda Docs: Clarify that -c configs merge with `.eslintrc.*` (fixes #9535) (#9847) (Kevin Partington)
42
+ * 978574f Docs: Fix examples for no-useless-escape (#9853) (Toru Kobayashi)
43
+ * cd5681d Chore: Deactivate consistent-docs-url in internal rules folder (#9815) (Kevin Partington)
44
+ * 2e87ddd Docs: Sync messageId examples' style with other examples (#9816) (Kevin Partington)
45
+ * 1d61930 Update: use doctrine range information in valid-jsdoc (#9831) (Teddy Katz)
46
+ * 133336e Update: fix indent behavior on template literal arguments (fixes #9061) (#9820) (Teddy Katz)
47
+ * ea1b15d Fix: avoid crashing on malformed configuration comments (fixes #9373) (#9819) (Teddy Katz)
48
+ * add1e70 Update: fix indent bug on comments in ternary expressions (fixes #9729) (#9818) (Teddy Katz)
49
+ * 6a5cd32 Fix: prefer-destructuring error with computed properties (fixes #9784) (#9817) (Teddy Katz)
50
+ * 601f851 Docs: Minor modification to code comments for clarity (#9821) (rgovind92)
51
+ * b9da067 Docs: fix misleading info about RuleTester column numbers (#9830) (Teddy Katz)
52
+ * 2cf4522 Update: Rename and deprecate object-property-newline option (#9570) (Jonathan Pool)
53
+ * acde640 Docs: Add ES 2018 to Configuring ESLint (#9829) (Kai Cataldo)
54
+ * ccfce15 Docs: Minor tweaks to working with rules page (#9824) (Kevin Partington)
55
+ * 54b329a Docs: fix substitution of {{ name }} (#9822) (Andres Kalle)
56
+
1
57
  v4.15.0 - January 6, 2018
2
58
 
3
59
  * 6ab04b5 New: Add context.report({ messageId }) (fixes #6740) (#9165) (Jed Fox)
@@ -98,7 +98,8 @@ function validateRuleSchema(rule, localOptions) {
98
98
  * @param {{create: Function}|null} rule The rule that the config is being validated for
99
99
  * @param {string} ruleId The rule's unique name.
100
100
  * @param {array|number} options The given options for the rule.
101
- * @param {string} source The name of the configuration source to report in any errors.
101
+ * @param {string|null} source The name of the configuration source to report in any errors. If null or undefined,
102
+ * no source is prepended to the message.
102
103
  * @returns {void}
103
104
  */
104
105
  function validateRuleOptions(rule, ruleId, options, source) {
@@ -112,7 +113,13 @@ function validateRuleOptions(rule, ruleId, options, source) {
112
113
  validateRuleSchema(rule, Array.isArray(options) ? options.slice(1) : []);
113
114
  }
114
115
  } catch (err) {
115
- throw new Error(`${source}:\n\tConfiguration for rule "${ruleId}" is invalid:\n${err.message}`);
116
+ const enhancedMessage = `Configuration for rule "${ruleId}" is invalid:\n${err.message}`;
117
+
118
+ if (typeof source === "string") {
119
+ throw new Error(`${source}:\n\t${enhancedMessage}`);
120
+ } else {
121
+ throw new Error(enhancedMessage);
122
+ }
116
123
  }
117
124
  }
118
125
 
package/lib/linter.js CHANGED
@@ -48,6 +48,14 @@ const MAX_AUTOFIX_PASSES = 10;
48
48
  * @property {Object|null} visitorKeys The visitor keys to traverse this AST.
49
49
  */
50
50
 
51
+ /**
52
+ * @typedef {Object} DisableDirective
53
+ * @property {("disable"|"enable"|"disable-line"|"disable-next-line")} type
54
+ * @property {number} line
55
+ * @property {number} column
56
+ * @property {(string|null)} ruleId
57
+ */
58
+
51
59
  //------------------------------------------------------------------------------
52
60
  // Helpers
53
61
  //------------------------------------------------------------------------------
@@ -260,12 +268,7 @@ function addDeclaredGlobals(globalScope, config, envContext) {
260
268
  * @param {{line: number, column: number}} loc The 0-based location of the comment token
261
269
  * @param {string} value The value after the directive in the comment
262
270
  * comment specified no specific rules, so it applies to all rules (e.g. `eslint-disable`)
263
- * @returns {{
264
- * type: ("disable"|"enable"|"disable-line"|"disable-next-line"),
265
- * line: number,
266
- * column: number,
267
- * ruleId: (string|null)
268
- * }[]} Directives from the comment
271
+ * @returns {DisableDirective[]} Directives from the comment
269
272
  */
270
273
  function createDisableDirectives(type, loc, value) {
271
274
  const ruleIds = Object.keys(parseListConfig(value));
@@ -282,17 +285,8 @@ function createDisableDirectives(type, loc, value) {
282
285
  * @param {ASTNode} ast The top node of the AST.
283
286
  * @param {Object} config The existing configuration data.
284
287
  * @param {function(string): {create: Function}} ruleMapper A map from rule IDs to defined rules
285
- * @returns {{
286
- * config: Object,
287
- * problems: Problem[],
288
- * disableDirectives: {
289
- * type: ("disable"|"enable"|"disable-line"|"disable-next-line"),
290
- * line: number,
291
- * column: number,
292
- * ruleId: (string|null)
293
- * }[]
294
- * }} Modified config object, along with any problems encountered
295
- * while parsing config comments
288
+ * @returns {{config: Object, problems: Problem[], disableDirectives: DisableDirective[]}}
289
+ * Modified config object, along with any problems encountered while parsing config comments
296
290
  */
297
291
  function modifyConfigsFromComments(filename, ast, config, ruleMapper) {
298
292
 
@@ -313,7 +307,6 @@ function modifyConfigsFromComments(filename, ast, config, ruleMapper) {
313
307
 
314
308
  if (match) {
315
309
  value = value.slice(match.index + match[1].length);
316
-
317
310
  if (comment.type === "Block") {
318
311
  switch (match[1]) {
319
312
  case "exported":
@@ -329,6 +322,18 @@ function modifyConfigsFromComments(filename, ast, config, ruleMapper) {
329
322
  [].push.apply(disableDirectives, createDisableDirectives("disable", comment.loc.start, value));
330
323
  break;
331
324
 
325
+ case "eslint-disable-line":
326
+ if (comment.loc.start.line === comment.loc.end.line) {
327
+ [].push.apply(disableDirectives, createDisableDirectives("disable-line", comment.loc.start, value));
328
+ }
329
+ break;
330
+
331
+ case "eslint-disable-next-line":
332
+ if (comment.loc.start.line === comment.loc.end.line) {
333
+ [].push.apply(disableDirectives, createDisableDirectives("disable-next-line", comment.loc.start, value));
334
+ }
335
+ break;
336
+
332
337
  case "eslint-enable":
333
338
  [].push.apply(disableDirectives, createDisableDirectives("enable", comment.loc.start, value));
334
339
  break;
@@ -340,7 +345,21 @@ function modifyConfigsFromComments(filename, ast, config, ruleMapper) {
340
345
  Object.keys(parseResult.config).forEach(name => {
341
346
  const ruleValue = parseResult.config[name];
342
347
 
343
- validator.validateRuleOptions(ruleMapper(name), name, ruleValue, `${filename} line ${comment.loc.start.line}`);
348
+ try {
349
+ validator.validateRuleOptions(ruleMapper(name), name, ruleValue);
350
+ } catch (err) {
351
+ problems.push({
352
+ ruleId: name,
353
+ severity: 2,
354
+ source: null,
355
+ message: err.message,
356
+ line: comment.loc.start.line,
357
+ column: comment.loc.start.column + 1,
358
+ endLine: comment.loc.end.line,
359
+ endColumn: comment.loc.end.column + 1,
360
+ nodeType: null
361
+ });
362
+ }
344
363
  commentRules[name] = ruleValue;
345
364
  });
346
365
  } else {
package/lib/options.js CHANGED
@@ -26,17 +26,17 @@ module.exports = optionator({
26
26
  {
27
27
  heading: "Basic configuration"
28
28
  },
29
- {
30
- option: "config",
31
- alias: "c",
32
- type: "path::String",
33
- description: "Use configuration from this file or shareable config"
34
- },
35
29
  {
36
30
  option: "eslintrc",
37
31
  type: "Boolean",
38
32
  default: "true",
39
- description: "Disable use of configuration from .eslintrc"
33
+ description: "Disable use of configuration from .eslintrc.*"
34
+ },
35
+ {
36
+ option: "config",
37
+ alias: "c",
38
+ type: "path::String",
39
+ description: "Use this configuration, overriding .eslintrc.* config options if present"
40
40
  },
41
41
  {
42
42
  option: "env",
@@ -28,6 +28,22 @@ const interpolate = require("./util/interpolate");
28
28
  * @property {Function} [fix] The function to call that creates a fix command.
29
29
  */
30
30
 
31
+ /**
32
+ * Information about the report
33
+ * @typedef {Object} ReportInfo
34
+ * @property {string} ruleId
35
+ * @property {(0|1|2)} severity
36
+ * @property {(string|undefined)} message
37
+ * @property {(string|undefined)} messageId
38
+ * @property {number} line
39
+ * @property {number} column
40
+ * @property {(number|undefined)} endLine
41
+ * @property {(number|undefined)} endColumn
42
+ * @property {(string|null)} nodeType
43
+ * @property {string} source
44
+ * @property {({text: string, range: (number[]|null)}|null)} fix
45
+ */
46
+
31
47
  //------------------------------------------------------------------------------
32
48
  // Module Definition
33
49
  //------------------------------------------------------------------------------
@@ -121,7 +137,7 @@ function compareFixesByRange(a, b) {
121
137
  * Merges the given fixes array into one.
122
138
  * @param {Fix[]} fixes The fixes to merge.
123
139
  * @param {SourceCode} sourceCode The source code object to get the text between fixes.
124
- * @returns {{text: string, range: [number, number]}} The merged fixes
140
+ * @returns {{text: string, range: number[]}} The merged fixes
125
141
  */
126
142
  function mergeFixes(fixes, sourceCode) {
127
143
  if (fixes.length === 0) {
@@ -158,7 +174,7 @@ function mergeFixes(fixes, sourceCode) {
158
174
  * If the descriptor retrieves multiple fixes, this merges those to one.
159
175
  * @param {MessageDescriptor} descriptor The report descriptor.
160
176
  * @param {SourceCode} sourceCode The source code object to get text between fixes.
161
- * @returns {({text: string, range: [number, number]}|null)} The fix for the descriptor
177
+ * @returns {({text: string, range: number[]}|null)} The fix for the descriptor
162
178
  */
163
179
  function normalizeFixes(descriptor, sourceCode) {
164
180
  if (typeof descriptor.fix !== "function") {
@@ -177,27 +193,15 @@ function normalizeFixes(descriptor, sourceCode) {
177
193
 
178
194
  /**
179
195
  * Creates information about the report from a descriptor
180
- * @param {{
181
- * ruleId: string,
182
- * severity: (0|1|2),
183
- * node: (ASTNode|null),
184
- * message: string,
185
- * loc: {start: SourceLocation, end: (SourceLocation|null)},
186
- * fix: ({text: string, range: [number, number]}|null),
187
- * sourceLines: string[]
188
- * }} options Information about the problem
189
- * @returns {function(...args): {
190
- * ruleId: string,
191
- * severity: (0|1|2),
192
- * message: string,
193
- * line: number,
194
- * column: number,
195
- * endLine: (number|undefined),
196
- * endColumn: (number|undefined),
197
- * nodeType: (string|null),
198
- * source: string,
199
- * fix: ({text: string, range: [number, number]}|null)
200
- * }} Information about the report
196
+ * @param {Object} options Information about the problem
197
+ * @param {string} options.ruleId Rule ID
198
+ * @param {(0|1|2)} options.severity Rule severity
199
+ * @param {(ASTNode|null)} options.node Node
200
+ * @param {string} options.message Error message
201
+ * @param {{start: SourceLocation, end: (SourceLocation|null)}} options.loc Start and end location
202
+ * @param {{text: string, range: (number[]|null)}} options.fix The fix object
203
+ * @param {string[]} options.sourceLines Source lines
204
+ * @returns {function(...args): ReportInfo} Function that returns information about the report
201
205
  */
202
206
  function createProblem(options) {
203
207
  const problem = {
@@ -235,20 +239,7 @@ function createProblem(options) {
235
239
  * problem for the Node.js API.
236
240
  * @param {{ruleId: string, severity: number, sourceCode: SourceCode, messageIds: Object}} metadata Metadata for the reported problem
237
241
  * @param {SourceCode} sourceCode The `SourceCode` instance for the text being linted
238
- * @returns {function(...args): {
239
- * ruleId: string,
240
- * severity: (0|1|2),
241
- * message: (string|undefined),
242
- * messageId: (string|undefined),
243
- * line: number,
244
- * column: number,
245
- * endLine: (number|undefined),
246
- * endColumn: (number|undefined),
247
- * nodeType: (string|null),
248
- * source: string,
249
- * fix: ({text: string, range: [number, number]}|null)
250
- * }}
251
- * Information about the report
242
+ * @returns {function(...args): ReportInfo} Function that returns information about the report
252
243
  */
253
244
 
254
245
  module.exports = function createReportTranslator(metadata) {
@@ -89,7 +89,11 @@ module.exports = {
89
89
  }
90
90
  },
91
91
  additionalProperties: false
92
- }]
92
+ }],
93
+ messages: {
94
+ getter: "Getter is not present.",
95
+ setter: "Setter is not present."
96
+ }
93
97
  },
94
98
  create(context) {
95
99
  const config = context.options[0] || {};
@@ -140,9 +144,9 @@ module.exports = {
140
144
  }
141
145
 
142
146
  if (checkSetWithoutGet && isSetPresent && !isGetPresent) {
143
- context.report({ node, message: "Getter is not present." });
147
+ context.report({ node, messageId: "getter" });
144
148
  } else if (checkGetWithoutSet && isGetPresent && !isSetPresent) {
145
- context.report({ node, message: "Setter is not present." });
149
+ context.report({ node, messageId: "setter" });
146
150
  }
147
151
  }
148
152
 
@@ -41,7 +41,13 @@ module.exports = {
41
41
  }
42
42
  ]
43
43
  }
44
- ]
44
+ ],
45
+ messages: {
46
+ unexpectedOpeningLinebreak: "There should be no linebreak after '['.",
47
+ unexpectedClosingLinebreak: "There should be no linebreak before ']'.",
48
+ missingOpeningLinebreak: "A linebreak is required after '['.",
49
+ missingClosingLinebreak: "A linebreak is required before ']'."
50
+ }
45
51
  },
46
52
 
47
53
  create(context) {
@@ -106,7 +112,7 @@ module.exports = {
106
112
  context.report({
107
113
  node,
108
114
  loc: token.loc,
109
- message: "There should be no linebreak after '['.",
115
+ messageId: "unexpectedOpeningLinebreak",
110
116
  fix(fixer) {
111
117
  const nextToken = sourceCode.getTokenAfter(token, { includeComments: true });
112
118
 
@@ -129,7 +135,7 @@ module.exports = {
129
135
  context.report({
130
136
  node,
131
137
  loc: token.loc,
132
- message: "There should be no linebreak before ']'.",
138
+ messageId: "unexpectedClosingLinebreak",
133
139
  fix(fixer) {
134
140
  const previousToken = sourceCode.getTokenBefore(token, { includeComments: true });
135
141
 
@@ -152,7 +158,7 @@ module.exports = {
152
158
  context.report({
153
159
  node,
154
160
  loc: token.loc,
155
- message: "A linebreak is required after '['.",
161
+ messageId: "missingOpeningLinebreak",
156
162
  fix(fixer) {
157
163
  return fixer.insertTextAfter(token, "\n");
158
164
  }
@@ -169,7 +175,7 @@ module.exports = {
169
175
  context.report({
170
176
  node,
171
177
  loc: token.loc,
172
- message: "A linebreak is required before ']'.",
178
+ messageId: "missingClosingLinebreak",
173
179
  fix(fixer) {
174
180
  return fixer.insertTextBefore(token, "\n");
175
181
  }
@@ -38,7 +38,13 @@ module.exports = {
38
38
  },
39
39
  additionalProperties: false
40
40
  }
41
- ]
41
+ ],
42
+ messages: {
43
+ unexpectedSpaceAfter: "There should be no space after '{{tokenValue}}'.",
44
+ unexpectedSpaceBefore: "There should be no space before '{{tokenValue}}'.",
45
+ missingSpaceAfter: "A space is required after '{{tokenValue}}'.",
46
+ missingSpaceBefore: "A space is required before '{{tokenValue}}'."
47
+ }
42
48
  },
43
49
  create(context) {
44
50
  const spaced = context.options[0] === "always",
@@ -76,7 +82,7 @@ module.exports = {
76
82
  context.report({
77
83
  node,
78
84
  loc: token.loc.start,
79
- message: "There should be no space after '{{tokenValue}}'.",
85
+ messageId: "unexpectedSpaceAfter",
80
86
  data: {
81
87
  tokenValue: token.value
82
88
  },
@@ -98,7 +104,7 @@ module.exports = {
98
104
  context.report({
99
105
  node,
100
106
  loc: token.loc.start,
101
- message: "There should be no space before '{{tokenValue}}'.",
107
+ messageId: "unexpectedSpaceBefore",
102
108
  data: {
103
109
  tokenValue: token.value
104
110
  },
@@ -120,7 +126,7 @@ module.exports = {
120
126
  context.report({
121
127
  node,
122
128
  loc: token.loc.start,
123
- message: "A space is required after '{{tokenValue}}'.",
129
+ messageId: "missingSpaceAfter",
124
130
  data: {
125
131
  tokenValue: token.value
126
132
  },
@@ -140,7 +146,7 @@ module.exports = {
140
146
  context.report({
141
147
  node,
142
148
  loc: token.loc.start,
143
- message: "A space is required before '{{tokenValue}}'.",
149
+ messageId: "missingSpaceBefore",
144
150
  data: {
145
151
  tokenValue: token.value
146
152
  },
@@ -156,7 +156,13 @@ module.exports = {
156
156
  },
157
157
  additionalProperties: false
158
158
  }
159
- ]
159
+ ],
160
+
161
+ messages: {
162
+ expectedAtEnd: "Expected to return a value at the end of {{name}}.",
163
+ expectedInside: "Expected to return a value in {{name}}.",
164
+ expectedReturnValue: "{{name}} expected a return value."
165
+ }
160
166
  },
161
167
 
162
168
  create(context) {
@@ -188,9 +194,9 @@ module.exports = {
188
194
  context.report({
189
195
  node,
190
196
  loc: getLocation(node, context.getSourceCode()).loc.start,
191
- message: funcInfo.hasReturn
192
- ? "Expected to return a value at the end of {{name}}."
193
- : "Expected to return a value in {{name}}.",
197
+ messageId: funcInfo.hasReturn
198
+ ? "expectedAtEnd"
199
+ : "expectedInside",
194
200
  data: {
195
201
  name: astUtils.getFunctionNameWithKind(funcInfo.node)
196
202
  }
@@ -230,7 +236,7 @@ module.exports = {
230
236
  if (!options.allowImplicit && !node.argument) {
231
237
  context.report({
232
238
  node,
233
- message: "{{name}} expected a return value.",
239
+ messageId: "expectedReturnValue",
234
240
  data: {
235
241
  name: lodash.upperFirst(astUtils.getFunctionNameWithKind(funcInfo.node))
236
242
  }
@@ -41,7 +41,12 @@ module.exports = {
41
41
  }
42
42
  ]
43
43
  }
44
- ]
44
+ ],
45
+
46
+ messages: {
47
+ unexpectedLineBreak: "There should be no linebreak here.",
48
+ missingLineBreak: "There should be a linebreak after this element."
49
+ }
45
50
  },
46
51
 
47
52
  create(context) {
@@ -100,7 +105,7 @@ module.exports = {
100
105
  start: tokenBefore.loc.end,
101
106
  end: token.loc.start
102
107
  },
103
- message: "There should be no linebreak here.",
108
+ messageId: "unexpectedLineBreak",
104
109
  fix(fixer) {
105
110
  if (astUtils.isCommentToken(tokenBefore)) {
106
111
  return null;
@@ -149,7 +154,7 @@ module.exports = {
149
154
  start: tokenBefore.loc.end,
150
155
  end: token.loc.start
151
156
  },
152
- message: "There should be a linebreak after this element.",
157
+ messageId: "missingLineBreak",
153
158
  fix(fixer) {
154
159
  return fixer.replaceTextRange([tokenBefore.range[1], token.range[0]], "\n");
155
160
  }
@@ -55,7 +55,15 @@ module.exports = {
55
55
  ]
56
56
  },
57
57
 
58
- fixable: "code"
58
+ fixable: "code",
59
+
60
+ messages: {
61
+ unexpectedOtherBlock: "Unexpected block statement surrounding arrow body.",
62
+ unexpectedEmptyBlock: "Unexpected block statement surrounding arrow body; put a value of `undefined` immediately after the `=>`.",
63
+ unexpectedObjectBlock: "Unexpected block statement surrounding arrow body; parenthesize the returned value and move it immediately after the `=>`.",
64
+ unexpectedSingleBlock: "Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`.",
65
+ expectedBlock: "Expected block statement surrounding arrow body."
66
+ }
59
67
  },
60
68
 
61
69
  create(context) {
@@ -110,22 +118,22 @@ module.exports = {
110
118
  }
111
119
 
112
120
  if (never || asNeeded && blockBody[0].type === "ReturnStatement") {
113
- let message;
121
+ let messageId;
114
122
 
115
123
  if (blockBody.length === 0) {
116
- message = "Unexpected block statement surrounding arrow body; put a value of `undefined` immediately after the `=>`.";
124
+ messageId = "unexpectedEmptyBlock";
117
125
  } else if (blockBody.length > 1) {
118
- message = "Unexpected block statement surrounding arrow body.";
126
+ messageId = "unexpectedOtherBlock";
119
127
  } else if (astUtils.isOpeningBraceToken(sourceCode.getFirstToken(blockBody[0], { skip: 1 }))) {
120
- message = "Unexpected block statement surrounding arrow body; parenthesize the returned value and move it immediately after the `=>`.";
128
+ messageId = "unexpectedObjectBlock";
121
129
  } else {
122
- message = "Unexpected block statement surrounding arrow body; move the returned value immediately after the `=>`.";
130
+ messageId = "unexpectedSingleBlock";
123
131
  }
124
132
 
125
133
  context.report({
126
134
  node,
127
135
  loc: arrowBody.loc.start,
128
- message,
136
+ messageId,
129
137
  fix(fixer) {
130
138
  const fixes = [];
131
139
 
@@ -190,7 +198,7 @@ module.exports = {
190
198
  context.report({
191
199
  node,
192
200
  loc: arrowBody.loc.start,
193
- message: "Expected block statement surrounding arrow body.",
201
+ messageId: "expectedBlock",
194
202
  fix(fixer) {
195
203
  const fixes = [];
196
204
  const arrowToken = sourceCode.getTokenBefore(arrowBody, astUtils.isArrowToken);
@@ -38,15 +38,19 @@ module.exports = {
38
38
  },
39
39
  additionalProperties: false
40
40
  }
41
- ]
41
+ ],
42
+
43
+ messages: {
44
+ unexpectedParens: "Unexpected parentheses around single function argument.",
45
+ expectedParens: "Expected parentheses around arrow function argument.",
46
+
47
+ unexpectedParensInline: "Unexpected parentheses around single function argument having a body with no curly braces.",
48
+ expectedParensBlock: "Expected parentheses around arrow function argument having a body with curly braces."
49
+ }
42
50
  },
43
51
 
44
52
  create(context) {
45
- const message = "Expected parentheses around arrow function argument.";
46
- const asNeededMessage = "Unexpected parentheses around single function argument.";
47
53
  const asNeeded = context.options[0] === "as-needed";
48
- const requireForBlockBodyMessage = "Unexpected parentheses around single function argument having a body with no curly braces";
49
- const requireForBlockBodyNoParensMessage = "Expected parentheses around arrow function argument having a body with curly braces.";
50
54
  const requireForBlockBody = asNeeded && context.options[1] && context.options[1].requireForBlockBody === true;
51
55
 
52
56
  const sourceCode = context.getSourceCode();
@@ -94,7 +98,7 @@ module.exports = {
94
98
  if (astUtils.isOpeningParenToken(firstTokenOfParam)) {
95
99
  context.report({
96
100
  node,
97
- message: requireForBlockBodyMessage,
101
+ messageId: "unexpectedParensInline",
98
102
  fix: fixParamsWithParenthesis
99
103
  });
100
104
  }
@@ -108,7 +112,7 @@ module.exports = {
108
112
  if (!astUtils.isOpeningParenToken(firstTokenOfParam)) {
109
113
  context.report({
110
114
  node,
111
- message: requireForBlockBodyNoParensMessage,
115
+ messageId: "expectedParensBlock",
112
116
  fix(fixer) {
113
117
  return fixer.replaceText(firstTokenOfParam, `(${firstTokenOfParam.value})`);
114
118
  }
@@ -127,7 +131,7 @@ module.exports = {
127
131
  if (astUtils.isOpeningParenToken(firstTokenOfParam)) {
128
132
  context.report({
129
133
  node,
130
- message: asNeededMessage,
134
+ messageId: "unexpectedParens",
131
135
  fix: fixParamsWithParenthesis
132
136
  });
133
137
  }
@@ -141,7 +145,7 @@ module.exports = {
141
145
  if (after.value !== ")") {
142
146
  context.report({
143
147
  node,
144
- message,
148
+ messageId: "expectedParens",
145
149
  fix(fixer) {
146
150
  return fixer.replaceText(firstTokenOfParam, `(${firstTokenOfParam.value})`);
147
151
  }