eslint 5.12.0 → 5.14.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 (146) hide show
  1. package/CHANGELOG.md +70 -0
  2. package/README.md +76 -143
  3. package/conf/eslint-all.js +3 -5
  4. package/conf/eslint-recommended.js +4 -268
  5. package/lib/built-in-rules-index.js +277 -0
  6. package/lib/cli-engine.js +6 -2
  7. package/lib/config/config-file.js +25 -2
  8. package/lib/config/config-initializer.js +150 -143
  9. package/lib/config/config-ops.js +30 -0
  10. package/lib/config/config-rule.js +2 -4
  11. package/lib/config/plugins.js +12 -4
  12. package/lib/config.js +1 -1
  13. package/lib/formatters/table.js +13 -4
  14. package/lib/formatters/tap.js +7 -4
  15. package/lib/linter.js +31 -31
  16. package/lib/load-rules.js +2 -5
  17. package/lib/rules/accessor-pairs.js +4 -2
  18. package/lib/rules/array-bracket-newline.js +4 -2
  19. package/lib/rules/array-callback-return.js +2 -1
  20. package/lib/rules/array-element-newline.js +4 -2
  21. package/lib/rules/arrow-body-style.js +1 -1
  22. package/lib/rules/arrow-parens.js +2 -1
  23. package/lib/rules/arrow-spacing.js +7 -6
  24. package/lib/rules/brace-style.js +2 -1
  25. package/lib/rules/camelcase.js +3 -2
  26. package/lib/rules/capitalized-comments.js +15 -14
  27. package/lib/rules/class-methods-use-this.js +1 -1
  28. package/lib/rules/comma-spacing.js +10 -4
  29. package/lib/rules/complexity.js +7 -9
  30. package/lib/rules/consistent-return.js +2 -1
  31. package/lib/rules/dot-notation.js +5 -3
  32. package/lib/rules/eqeqeq.js +2 -1
  33. package/lib/rules/for-direction.js +30 -17
  34. package/lib/rules/func-call-spacing.js +2 -1
  35. package/lib/rules/func-style.js +3 -2
  36. package/lib/rules/getter-return.js +2 -1
  37. package/lib/rules/global-require.js +5 -2
  38. package/lib/rules/guard-for-in.js +5 -2
  39. package/lib/rules/handle-callback-err.js +5 -2
  40. package/lib/rules/id-blacklist.js +4 -1
  41. package/lib/rules/id-length.js +9 -6
  42. package/lib/rules/id-match.js +11 -5
  43. package/lib/rules/implicit-arrow-linebreak.js +7 -3
  44. package/lib/rules/indent-legacy.js +11 -5
  45. package/lib/rules/indent.js +18 -9
  46. package/lib/rules/init-declarations.js +13 -13
  47. package/lib/rules/jsx-quotes.js +5 -2
  48. package/lib/rules/key-spacing.js +70 -35
  49. package/lib/rules/keyword-spacing.js +18 -12
  50. package/lib/rules/line-comment-position.js +15 -8
  51. package/lib/rules/linebreak-style.js +6 -6
  52. package/lib/rules/lines-around-comment.js +20 -16
  53. package/lib/rules/lines-around-directive.js +5 -2
  54. package/lib/rules/lines-between-class-members.js +8 -6
  55. package/lib/rules/max-depth.js +11 -9
  56. package/lib/rules/max-len.js +24 -13
  57. package/lib/rules/max-lines-per-function.js +17 -18
  58. package/lib/rules/max-lines.js +14 -10
  59. package/lib/rules/max-nested-callbacks.js +12 -11
  60. package/lib/rules/max-params.js +11 -9
  61. package/lib/rules/max-statements-per-line.js +8 -5
  62. package/lib/rules/max-statements.js +12 -11
  63. package/lib/rules/multiline-comment-style.js +18 -17
  64. package/lib/rules/multiline-ternary.js +8 -6
  65. package/lib/rules/new-cap.js +18 -11
  66. package/lib/rules/new-parens.js +5 -2
  67. package/lib/rules/newline-after-var.js +6 -8
  68. package/lib/rules/newline-before-return.js +5 -1
  69. package/lib/rules/newline-per-chained-call.js +7 -3
  70. package/lib/rules/no-async-promise-executor.js +5 -2
  71. package/lib/rules/no-bitwise.js +2 -1
  72. package/lib/rules/no-confusing-arrow.js +1 -1
  73. package/lib/rules/no-constant-condition.js +24 -2
  74. package/lib/rules/no-duplicate-imports.js +17 -11
  75. package/lib/rules/no-else-return.js +2 -1
  76. package/lib/rules/no-empty.js +2 -1
  77. package/lib/rules/no-eval.js +1 -1
  78. package/lib/rules/no-extra-parens.js +4 -4
  79. package/lib/rules/no-fallthrough.js +8 -4
  80. package/lib/rules/no-floating-decimal.js +7 -3
  81. package/lib/rules/no-implicit-coercion.js +9 -6
  82. package/lib/rules/no-irregular-whitespace.js +8 -4
  83. package/lib/rules/no-labels.js +6 -4
  84. package/lib/rules/no-magic-numbers.js +6 -3
  85. package/lib/rules/no-mixed-operators.js +5 -4
  86. package/lib/rules/no-mixed-requires.js +4 -2
  87. package/lib/rules/no-multi-spaces.js +2 -1
  88. package/lib/rules/no-param-reassign.js +1 -1
  89. package/lib/rules/no-plusplus.js +2 -1
  90. package/lib/rules/no-redeclare.js +2 -2
  91. package/lib/rules/no-self-assign.js +2 -1
  92. package/lib/rules/no-shadow-restricted-names.js +16 -2
  93. package/lib/rules/no-shadow.js +3 -3
  94. package/lib/rules/no-sync.js +2 -1
  95. package/lib/rules/no-tabs.js +2 -1
  96. package/lib/rules/no-trailing-spaces.js +5 -3
  97. package/lib/rules/no-undef.js +7 -3
  98. package/lib/rules/no-underscore-dangle.js +6 -3
  99. package/lib/rules/no-unexpected-multiline.js +14 -13
  100. package/lib/rules/no-unneeded-ternary.js +2 -1
  101. package/lib/rules/no-unsafe-negation.js +6 -3
  102. package/lib/rules/no-unused-expressions.js +6 -3
  103. package/lib/rules/no-unused-labels.js +7 -2
  104. package/lib/rules/no-unused-vars.js +8 -4
  105. package/lib/rules/no-use-before-define.js +3 -3
  106. package/lib/rules/no-useless-rename.js +3 -3
  107. package/lib/rules/object-curly-newline.js +6 -4
  108. package/lib/rules/object-property-newline.js +5 -3
  109. package/lib/rules/object-shorthand.js +9 -5
  110. package/lib/rules/one-var.js +24 -38
  111. package/lib/rules/operator-assignment.js +8 -4
  112. package/lib/rules/padded-blocks.js +32 -9
  113. package/lib/rules/prefer-arrow-callback.js +4 -2
  114. package/lib/rules/prefer-const.js +7 -4
  115. package/lib/rules/prefer-destructuring.js +70 -12
  116. package/lib/rules/prefer-promise-reject-errors.js +1 -1
  117. package/lib/rules/prefer-spread.js +2 -13
  118. package/lib/rules/quote-props.js +10 -5
  119. package/lib/rules/quotes.js +4 -2
  120. package/lib/rules/require-jsdoc.js +13 -7
  121. package/lib/rules/semi-spacing.js +6 -8
  122. package/lib/rules/semi.js +5 -4
  123. package/lib/rules/sort-imports.js +6 -3
  124. package/lib/rules/sort-keys.js +13 -5
  125. package/lib/rules/sort-vars.js +2 -1
  126. package/lib/rules/space-before-function-paren.js +6 -3
  127. package/lib/rules/space-infix-ops.js +2 -1
  128. package/lib/rules/space-unary-ops.js +20 -10
  129. package/lib/rules/spaced-comment.js +2 -1
  130. package/lib/rules/strict.js +34 -35
  131. package/lib/rules/switch-colon-spacing.js +11 -8
  132. package/lib/rules/symbol-description.js +6 -3
  133. package/lib/rules/template-curly-spacing.js +10 -10
  134. package/lib/rules/template-tag-spacing.js +7 -3
  135. package/lib/rules/unicode-bom.js +7 -3
  136. package/lib/rules/use-isnan.js +5 -2
  137. package/lib/rules/valid-jsdoc.js +40 -19
  138. package/lib/rules/valid-typeof.js +9 -4
  139. package/lib/rules/vars-on-top.js +6 -4
  140. package/lib/rules/wrap-iife.js +12 -6
  141. package/lib/rules/yield-star-spacing.js +17 -10
  142. package/lib/rules/yoda.js +9 -4
  143. package/lib/rules.js +4 -34
  144. package/lib/util/ajv.js +1 -0
  145. package/lib/util/config-comment-parser.js +7 -10
  146. package/package.json +20 -20
@@ -40,11 +40,13 @@ module.exports = {
40
40
  properties: {
41
41
  maximum: {
42
42
  type: "integer",
43
- minimum: 0
43
+ minimum: 0,
44
+ default: 10
44
45
  },
45
46
  max: {
46
47
  type: "integer",
47
- minimum: 0
48
+ minimum: 0,
49
+ default: 10
48
50
  }
49
51
  },
50
52
  additionalProperties: false
@@ -60,7 +62,10 @@ module.exports = {
60
62
  },
61
63
  additionalProperties: false
62
64
  }
63
- ]
65
+ ],
66
+ messages: {
67
+ exceed: "{{name}} has too many statements ({{count}}). Maximum allowed is {{max}}."
68
+ }
64
69
  },
65
70
 
66
71
  create(context) {
@@ -75,13 +80,9 @@ module.exports = {
75
80
  topLevelFunctions = [];
76
81
  let maxStatements = 10;
77
82
 
78
- if (typeof option === "object" && Object.prototype.hasOwnProperty.call(option, "maximum") && typeof option.maximum === "number") {
79
- maxStatements = option.maximum;
80
- }
81
- if (typeof option === "object" && Object.prototype.hasOwnProperty.call(option, "max") && typeof option.max === "number") {
82
- maxStatements = option.max;
83
- }
84
- if (typeof option === "number") {
83
+ if (typeof option === "object") {
84
+ maxStatements = option.maximum || option.max;
85
+ } else if (typeof option === "number") {
85
86
  maxStatements = option;
86
87
  }
87
88
 
@@ -99,7 +100,7 @@ module.exports = {
99
100
 
100
101
  context.report({
101
102
  node,
102
- message: "{{name}} has too many statements ({{count}}). Maximum allowed is {{max}}.",
103
+ messageId: "exceed",
103
104
  data: { name, count, max }
104
105
  });
105
106
  }
@@ -22,20 +22,21 @@ module.exports = {
22
22
  },
23
23
 
24
24
  fixable: "whitespace",
25
- schema: [{ enum: ["starred-block", "separate-lines", "bare-block"] }]
25
+ schema: [{ enum: ["starred-block", "separate-lines", "bare-block"] }],
26
+ messages: {
27
+ expectedBlock: "Expected a block comment instead of consecutive line comments.",
28
+ startNewline: "Expected a linebreak after '/*'.",
29
+ endNewline: "Expected a linebreak before '*/'.",
30
+ missingStar: "Expected a '*' at the start of this line.",
31
+ alignment: "Expected this line to be aligned with the start of the comment.",
32
+ expectedLines: "Expected multiple line comments instead of a block comment."
33
+ }
26
34
  },
27
35
 
28
36
  create(context) {
29
37
  const sourceCode = context.getSourceCode();
30
38
  const option = context.options[0] || "starred-block";
31
39
 
32
- const EXPECTED_BLOCK_ERROR = "Expected a block comment instead of consecutive line comments.";
33
- const START_NEWLINE_ERROR = "Expected a linebreak after '/*'.";
34
- const END_NEWLINE_ERROR = "Expected a linebreak before '*/'.";
35
- const MISSING_STAR_ERROR = "Expected a '*' at the start of this line.";
36
- const ALIGNMENT_ERROR = "Expected this line to be aligned with the start of the comment.";
37
- const EXPECTED_LINES_ERROR = "Expected multiple line comments instead of a block comment.";
38
-
39
40
  //----------------------------------------------------------------------
40
41
  // Helpers
41
42
  //----------------------------------------------------------------------
@@ -127,7 +128,7 @@ module.exports = {
127
128
  start: commentGroup[0].loc.start,
128
129
  end: commentGroup[commentGroup.length - 1].loc.end
129
130
  },
130
- message: EXPECTED_BLOCK_ERROR,
131
+ messageId: "expectedBlock",
131
132
  fix(fixer) {
132
133
  const range = [commentGroup[0].range[0], commentGroup[commentGroup.length - 1].range[1]];
133
134
  const starredBlock = `/*${convertToStarredBlock(commentGroup[0], commentLines)}*/`;
@@ -150,7 +151,7 @@ module.exports = {
150
151
  start: block.loc.start,
151
152
  end: { line: block.loc.start.line, column: block.loc.start.column + 2 }
152
153
  },
153
- message: START_NEWLINE_ERROR,
154
+ messageId: "startNewline",
154
155
  fix: fixer => fixer.insertTextAfterRange([start, start + 2], `\n${expectedLinePrefix}`)
155
156
  });
156
157
  }
@@ -161,7 +162,7 @@ module.exports = {
161
162
  start: { line: block.loc.end.line, column: block.loc.end.column - 2 },
162
163
  end: block.loc.end
163
164
  },
164
- message: END_NEWLINE_ERROR,
165
+ messageId: "endNewline",
165
166
  fix: fixer => fixer.replaceTextRange([block.range[1] - 2, block.range[1]], `\n${expectedLinePrefix}/`)
166
167
  });
167
168
  }
@@ -175,9 +176,9 @@ module.exports = {
175
176
  start: { line: lineNumber, column: 0 },
176
177
  end: { line: lineNumber, column: sourceCode.lines[lineNumber - 1].length }
177
178
  },
178
- message: /^\s*\*/.test(lineText)
179
- ? ALIGNMENT_ERROR
180
- : MISSING_STAR_ERROR,
179
+ messageId: /^\s*\*/.test(lineText)
180
+ ? "alignment"
181
+ : "missingStar",
181
182
  fix(fixer) {
182
183
  const lineStartIndex = sourceCode.getIndexFromLoc({ line: lineNumber, column: 0 });
183
184
  const linePrefixLength = lineText.match(/^\s*\*? ?/)[0].length;
@@ -209,7 +210,7 @@ module.exports = {
209
210
  start: block.loc.start,
210
211
  end: { line: block.loc.start.line, column: block.loc.start.column + 2 }
211
212
  },
212
- message: EXPECTED_LINES_ERROR,
213
+ messageId: "expectedLines",
213
214
  fix(fixer) {
214
215
  return fixer.replaceText(block, convertToSeparateLines(block, commentLines.filter(line => line)));
215
216
  }
@@ -228,7 +229,7 @@ module.exports = {
228
229
  start: commentGroup[0].loc.start,
229
230
  end: commentGroup[commentGroup.length - 1].loc.end
230
231
  },
231
- message: EXPECTED_BLOCK_ERROR,
232
+ messageId: "expectedBlock",
232
233
  fix(fixer) {
233
234
  const range = [commentGroup[0].range[0], commentGroup[commentGroup.length - 1].range[1]];
234
235
  const block = convertToBlock(commentGroup[0], commentLines.filter(line => line));
@@ -249,7 +250,7 @@ module.exports = {
249
250
  start: block.loc.start,
250
251
  end: { line: block.loc.start.line, column: block.loc.start.column + 2 }
251
252
  },
252
- message: EXPECTED_BLOCK_ERROR,
253
+ messageId: "expectedBlock",
253
254
  fix(fixer) {
254
255
  return fixer.replaceText(block, convertToBlock(block, commentLines.filter(line => line)));
255
256
  }
@@ -26,7 +26,13 @@ module.exports = {
26
26
  {
27
27
  enum: ["always", "always-multiline", "never"]
28
28
  }
29
- ]
29
+ ],
30
+ messages: {
31
+ expectedTestCons: "Expected newline between test and consequent of ternary expression.",
32
+ expectedConsAlt: "Expected newline between consequent and alternate of ternary expression.",
33
+ unexpectedTestCons: "Unexpected newline between test and consequent of ternary expression.",
34
+ unexpectedConsAlt: "Unexpected newline between consequent and alternate of ternary expression."
35
+ }
30
36
  },
31
37
 
32
38
  create(context) {
@@ -49,11 +55,7 @@ module.exports = {
49
55
  function reportError(node, parentNode, expected) {
50
56
  context.report({
51
57
  node,
52
- message: "{{expected}} newline between {{typeOfError}} of ternary expression.",
53
- data: {
54
- expected: expected ? "Expected" : "Unexpected",
55
- typeOfError: node === parentNode.test ? "test and consequent" : "consequent and alternate"
56
- }
58
+ messageId: `${expected ? "expected" : "unexpected"}${node === parentNode.test ? "TestCons" : "ConsAlt"}`
57
59
  });
58
60
  }
59
61
 
@@ -88,10 +88,12 @@ module.exports = {
88
88
  type: "object",
89
89
  properties: {
90
90
  newIsCap: {
91
- type: "boolean"
91
+ type: "boolean",
92
+ default: true
92
93
  },
93
94
  capIsNew: {
94
- type: "boolean"
95
+ type: "boolean",
96
+ default: true
95
97
  },
96
98
  newIsCapExceptions: {
97
99
  type: "array",
@@ -112,17 +114,22 @@ module.exports = {
112
114
  type: "string"
113
115
  },
114
116
  properties: {
115
- type: "boolean"
117
+ type: "boolean",
118
+ default: true
116
119
  }
117
120
  },
118
121
  additionalProperties: false
119
122
  }
120
- ]
123
+ ],
124
+ messages: {
125
+ upper: "A function with a name starting with an uppercase letter should only be used as a constructor.",
126
+ lower: "A constructor name should not start with a lowercase letter."
127
+ }
121
128
  },
122
129
 
123
130
  create(context) {
124
131
 
125
- const config = context.options[0] ? Object.assign({}, context.options[0]) : {};
132
+ const config = Object.assign({}, context.options[0]);
126
133
 
127
134
  config.newIsCap = config.newIsCap !== false;
128
135
  config.capIsNew = config.capIsNew !== false;
@@ -219,19 +226,19 @@ module.exports = {
219
226
  }
220
227
 
221
228
  /**
222
- * Reports the given message for the given node. The location will be the start of the property or the callee.
229
+ * Reports the given messageId for the given node. The location will be the start of the property or the callee.
223
230
  * @param {ASTNode} node CallExpression or NewExpression node.
224
- * @param {string} message The message to report.
231
+ * @param {string} messageId The messageId to report.
225
232
  * @returns {void}
226
233
  */
227
- function report(node, message) {
234
+ function report(node, messageId) {
228
235
  let callee = node.callee;
229
236
 
230
237
  if (callee.type === "MemberExpression") {
231
238
  callee = callee.property;
232
239
  }
233
240
 
234
- context.report({ node, loc: callee.loc.start, message });
241
+ context.report({ node, loc: callee.loc.start, messageId });
235
242
  }
236
243
 
237
244
  //--------------------------------------------------------------------------
@@ -248,7 +255,7 @@ module.exports = {
248
255
  const isAllowed = capitalization !== "lower" || isCapAllowed(newIsCapExceptions, node, constructorName, newIsCapExceptionPattern);
249
256
 
250
257
  if (!isAllowed) {
251
- report(node, "A constructor name should not start with a lowercase letter.");
258
+ report(node, "lower");
252
259
  }
253
260
  }
254
261
  };
@@ -264,7 +271,7 @@ module.exports = {
264
271
  const isAllowed = capitalization !== "upper" || isCapAllowed(capIsNewExceptions, node, calleeName, capIsNewExceptionPattern);
265
272
 
266
273
  if (!isAllowed) {
267
- report(node, "A function with a name starting with an uppercase letter should only be used as a constructor.");
274
+ report(node, "upper");
268
275
  }
269
276
  }
270
277
  };
@@ -30,8 +30,11 @@ module.exports = {
30
30
  url: "https://eslint.org/docs/rules/new-parens"
31
31
  },
32
32
 
33
+ fixable: "code",
33
34
  schema: [],
34
- fixable: "code"
35
+ messages: {
36
+ missing: "Missing '()' invoking a constructor."
37
+ }
35
38
  },
36
39
 
37
40
  create(context) {
@@ -50,7 +53,7 @@ module.exports = {
50
53
  if (!hasParens) {
51
54
  context.report({
52
55
  node,
53
- message: "Missing '()' invoking a constructor.",
56
+ messageId: "missing",
54
57
  fix: fixer => fixer.insertTextAfter(node, "()")
55
58
  });
56
59
  }
@@ -26,14 +26,16 @@ module.exports = {
26
26
  recommended: false,
27
27
  url: "https://eslint.org/docs/rules/newline-after-var"
28
28
  },
29
-
30
29
  schema: [
31
30
  {
32
31
  enum: ["never", "always"]
33
32
  }
34
33
  ],
35
-
36
34
  fixable: "whitespace",
35
+ messages: {
36
+ expected: "Expected blank line after variable declarations.",
37
+ unexpected: "Unexpected blank line after variable declarations."
38
+ },
37
39
 
38
40
  deprecated: true,
39
41
 
@@ -41,10 +43,6 @@ module.exports = {
41
43
  },
42
44
 
43
45
  create(context) {
44
-
45
- const ALWAYS_MESSAGE = "Expected blank line after variable declarations.",
46
- NEVER_MESSAGE = "Unexpected blank line after variable declarations.";
47
-
48
46
  const sourceCode = context.getSourceCode();
49
47
 
50
48
  // Default `mode` to "always".
@@ -214,7 +212,7 @@ module.exports = {
214
212
  if (mode === "never" && noNextLineToken && !hasNextLineComment) {
215
213
  context.report({
216
214
  node,
217
- message: NEVER_MESSAGE,
215
+ messageId: "unexpected",
218
216
  data: { identifier: node.name },
219
217
  fix(fixer) {
220
218
  const linesBetween = sourceCode.getText().slice(lastToken.range[1], nextToken.range[0]).split(astUtils.LINEBREAK_MATCHER);
@@ -233,7 +231,7 @@ module.exports = {
233
231
  ) {
234
232
  context.report({
235
233
  node,
236
- message: ALWAYS_MESSAGE,
234
+ messageId: "expected",
237
235
  data: { identifier: node.name },
238
236
  fix(fixer) {
239
237
  if ((noNextLineToken ? getLastCommentLineOfBlock(nextLineNum) : lastToken.loc.end.line) === nextToken.loc.start.line) {
@@ -22,6 +22,10 @@ module.exports = {
22
22
 
23
23
  fixable: "whitespace",
24
24
  schema: [],
25
+ messages: {
26
+ expected: "Expected newline before return statement."
27
+ },
28
+
25
29
  deprecated: true,
26
30
  replacedBy: ["padding-line-between-statements"]
27
31
  },
@@ -196,7 +200,7 @@ module.exports = {
196
200
  if (!isFirstNode(node) && !hasNewlineBefore(node)) {
197
201
  context.report({
198
202
  node,
199
- message: "Expected newline before return statement.",
203
+ messageId: "expected",
200
204
  fix(fixer) {
201
205
  if (canFix(node)) {
202
206
  const tokenBefore = sourceCode.getTokenBefore(node);
@@ -31,11 +31,15 @@ module.exports = {
31
31
  ignoreChainWithDepth: {
32
32
  type: "integer",
33
33
  minimum: 1,
34
- maximum: 10
34
+ maximum: 10,
35
+ default: 2
35
36
  }
36
37
  },
37
38
  additionalProperties: false
38
- }]
39
+ }],
40
+ messages: {
41
+ expected: "Expected line break before `{{callee}}`."
42
+ }
39
43
  },
40
44
 
41
45
  create(context) {
@@ -91,7 +95,7 @@ module.exports = {
91
95
  context.report({
92
96
  node: callee.property,
93
97
  loc: callee.property.loc.start,
94
- message: "Expected line break before `{{callee}}`.",
98
+ messageId: "expected",
95
99
  data: {
96
100
  callee: getPropertyText(callee)
97
101
  },
@@ -20,7 +20,10 @@ module.exports = {
20
20
  },
21
21
 
22
22
  fixable: null,
23
- schema: []
23
+ schema: [],
24
+ messages: {
25
+ async: "Promise executor functions should not be async."
26
+ }
24
27
  },
25
28
 
26
29
  create(context) {
@@ -28,7 +31,7 @@ module.exports = {
28
31
  "NewExpression[callee.name='Promise'][arguments.0.async=true]"(node) {
29
32
  context.report({
30
33
  node: context.getSourceCode().getFirstToken(node.arguments[0], token => token.value === "async"),
31
- message: "Promise executor functions should not be async."
34
+ messageId: "async"
32
35
  });
33
36
  }
34
37
  };
@@ -43,7 +43,8 @@ module.exports = {
43
43
  uniqueItems: true
44
44
  },
45
45
  int32Hint: {
46
- type: "boolean"
46
+ type: "boolean",
47
+ default: false
47
48
  }
48
49
  },
49
50
  additionalProperties: false
@@ -41,7 +41,7 @@ module.exports = {
41
41
  schema: [{
42
42
  type: "object",
43
43
  properties: {
44
- allowParens: { type: "boolean" }
44
+ allowParens: { type: "boolean", default: false }
45
45
  },
46
46
  additionalProperties: false
47
47
  }],
@@ -5,6 +5,13 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ //------------------------------------------------------------------------------
9
+ // Helpers
10
+ //------------------------------------------------------------------------------
11
+
12
+ const EQUALITY_OPERATORS = ["===", "!==", "==", "!="];
13
+ const RELATIONAL_OPERATORS = [">", "<", ">=", "<=", "in", "instanceof"];
14
+
8
15
  //------------------------------------------------------------------------------
9
16
  // Rule Definition
10
17
  //------------------------------------------------------------------------------
@@ -25,7 +32,8 @@ module.exports = {
25
32
  type: "object",
26
33
  properties: {
27
34
  checkLoops: {
28
- type: "boolean"
35
+ type: "boolean",
36
+ default: true
29
37
  }
30
38
  },
31
39
  additionalProperties: false
@@ -109,7 +117,21 @@ module.exports = {
109
117
  const isLeftShortCircuit = (isLeftConstant && isLogicalIdentity(node.left, node.operator));
110
118
  const isRightShortCircuit = (isRightConstant && isLogicalIdentity(node.right, node.operator));
111
119
 
112
- return (isLeftConstant && isRightConstant) || isLeftShortCircuit || isRightShortCircuit;
120
+ return (isLeftConstant && isRightConstant) ||
121
+ (
122
+
123
+ // in the case of an "OR", we need to know if the right constant value is truthy
124
+ node.operator === "||" &&
125
+ isRightConstant &&
126
+ node.right.value &&
127
+ (
128
+ !node.parent ||
129
+ node.parent.type !== "BinaryExpression" ||
130
+ !(EQUALITY_OPERATORS.includes(node.parent.operator) || RELATIONAL_OPERATORS.includes(node.parent.operator))
131
+ )
132
+ ) ||
133
+ isLeftShortCircuit ||
134
+ isRightShortCircuit;
113
135
  }
114
136
 
115
137
  case "AssignmentExpression":
@@ -29,18 +29,17 @@ function getValue(node) {
29
29
  * @param {ASTNode} node - A node to get.
30
30
  * @param {string} value - The name of the imported or exported module.
31
31
  * @param {string[]} array - The array containing other imports or exports in the file.
32
- * @param {string} message - A message to be reported after the name of the module
32
+ * @param {string} messageId - A messageId to be reported after the name of the module
33
33
  *
34
34
  * @returns {void} No return value
35
35
  */
36
- function checkAndReport(context, node, value, array, message) {
36
+ function checkAndReport(context, node, value, array, messageId) {
37
37
  if (array.indexOf(value) !== -1) {
38
38
  context.report({
39
39
  node,
40
- message: "'{{module}}' {{message}}",
40
+ messageId,
41
41
  data: {
42
- module: value,
43
- message
42
+ module: value
44
43
  }
45
44
  });
46
45
  }
@@ -66,10 +65,10 @@ function handleImports(context, includeExports, importsInFile, exportsInFile) {
66
65
  const value = getValue(node);
67
66
 
68
67
  if (value) {
69
- checkAndReport(context, node, value, importsInFile, "import is duplicated.");
68
+ checkAndReport(context, node, value, importsInFile, "import");
70
69
 
71
70
  if (includeExports) {
72
- checkAndReport(context, node, value, exportsInFile, "import is duplicated as export.");
71
+ checkAndReport(context, node, value, exportsInFile, "importAs");
73
72
  }
74
73
 
75
74
  importsInFile.push(value);
@@ -91,8 +90,8 @@ function handleExports(context, importsInFile, exportsInFile) {
91
90
  const value = getValue(node);
92
91
 
93
92
  if (value) {
94
- checkAndReport(context, node, value, exportsInFile, "export is duplicated.");
95
- checkAndReport(context, node, value, importsInFile, "export is duplicated as import.");
93
+ checkAndReport(context, node, value, exportsInFile, "export");
94
+ checkAndReport(context, node, value, importsInFile, "exportAs");
96
95
 
97
96
  exportsInFile.push(value);
98
97
  }
@@ -114,11 +113,18 @@ module.exports = {
114
113
  type: "object",
115
114
  properties: {
116
115
  includeExports: {
117
- type: "boolean"
116
+ type: "boolean",
117
+ default: false
118
118
  }
119
119
  },
120
120
  additionalProperties: false
121
- }]
121
+ }],
122
+ messages: {
123
+ import: "'{{module}}' import is duplicated.",
124
+ importAs: "'{{module}}' import is duplicated as export.",
125
+ export: "'{{module}}' export is duplicated.",
126
+ exportAs: "'{{module}}' export is duplicated as import."
127
+ }
122
128
  },
123
129
 
124
130
  create(context) {
@@ -31,7 +31,8 @@ module.exports = {
31
31
  type: "object",
32
32
  properties: {
33
33
  allowElseIf: {
34
- type: "boolean"
34
+ type: "boolean",
35
+ default: true
35
36
  }
36
37
  },
37
38
  additionalProperties: false
@@ -30,7 +30,8 @@ module.exports = {
30
30
  type: "object",
31
31
  properties: {
32
32
  allowEmptyCatch: {
33
- type: "boolean"
33
+ type: "boolean",
34
+ default: false
34
35
  }
35
36
  },
36
37
  additionalProperties: false
@@ -89,7 +89,7 @@ module.exports = {
89
89
  {
90
90
  type: "object",
91
91
  properties: {
92
- allowIndirect: { type: "boolean" }
92
+ allowIndirect: { type: "boolean", default: false }
93
93
  },
94
94
  additionalProperties: false
95
95
  }
@@ -44,11 +44,11 @@ module.exports = {
44
44
  {
45
45
  type: "object",
46
46
  properties: {
47
- conditionalAssign: { type: "boolean" },
48
- nestedBinaryExpressions: { type: "boolean" },
49
- returnAssign: { type: "boolean" },
47
+ conditionalAssign: { type: "boolean", default: true },
48
+ nestedBinaryExpressions: { type: "boolean", default: true },
49
+ returnAssign: { type: "boolean", default: true },
50
50
  ignoreJSX: { enum: ["none", "all", "single-line", "multi-line"] },
51
- enforceForArrowConditionals: { type: "boolean" }
51
+ enforceForArrowConditionals: { type: "boolean", default: true }
52
52
  },
53
53
  additionalProperties: false
54
54
  }
@@ -69,12 +69,17 @@ module.exports = {
69
69
  type: "object",
70
70
  properties: {
71
71
  commentPattern: {
72
- type: "string"
72
+ type: "string",
73
+ default: ""
73
74
  }
74
75
  },
75
76
  additionalProperties: false
76
77
  }
77
- ]
78
+ ],
79
+ messages: {
80
+ case: "Expected a 'break' statement before 'case'.",
81
+ default: "Expected a 'break' statement before 'default'."
82
+ }
78
83
  },
79
84
 
80
85
  create(context) {
@@ -111,8 +116,7 @@ module.exports = {
111
116
  */
112
117
  if (fallthroughCase && !hasFallthroughComment(node, context, fallthroughCommentPattern)) {
113
118
  context.report({
114
- message: "Expected a 'break' statement before '{{type}}'.",
115
- data: { type: node.test ? "case" : "default" },
119
+ messageId: node.test ? "case" : "default",
116
120
  node
117
121
  });
118
122
  }
@@ -27,7 +27,11 @@ module.exports = {
27
27
  },
28
28
 
29
29
  schema: [],
30
- fixable: "code"
30
+ fixable: "code",
31
+ messages: {
32
+ leading: "A leading decimal point can be confused with a dot.",
33
+ trailing: "A trailing decimal point can be confused with a dot."
34
+ }
31
35
  },
32
36
 
33
37
  create(context) {
@@ -40,7 +44,7 @@ module.exports = {
40
44
  if (node.raw.startsWith(".")) {
41
45
  context.report({
42
46
  node,
43
- message: "A leading decimal point can be confused with a dot.",
47
+ messageId: "leading",
44
48
  fix(fixer) {
45
49
  const tokenBefore = sourceCode.getTokenBefore(node);
46
50
  const needsSpaceBefore = tokenBefore &&
@@ -54,7 +58,7 @@ module.exports = {
54
58
  if (node.raw.indexOf(".") === node.raw.length - 1) {
55
59
  context.report({
56
60
  node,
57
- message: "A trailing decimal point can be confused with a dot.",
61
+ messageId: "trailing",
58
62
  fix: fixer => fixer.insertTextAfter(node, "0")
59
63
  });
60
64
  }