eslint 6.5.0 → 6.7.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 (196) hide show
  1. package/CHANGELOG.md +115 -0
  2. package/README.md +10 -9
  3. package/conf/config-schema.js +1 -0
  4. package/conf/default-cli-options.js +1 -1
  5. package/lib/cli-engine/cascading-config-array-factory.js +40 -14
  6. package/lib/cli-engine/cli-engine.js +49 -21
  7. package/lib/cli-engine/config-array/config-array.js +13 -4
  8. package/lib/cli-engine/config-array/config-dependency.js +2 -0
  9. package/lib/cli-engine/config-array/extracted-config.js +27 -0
  10. package/lib/cli-engine/config-array/ignore-pattern.js +231 -0
  11. package/lib/cli-engine/config-array/index.js +2 -0
  12. package/lib/cli-engine/config-array/override-tester.js +2 -0
  13. package/lib/cli-engine/config-array-factory.js +120 -2
  14. package/lib/cli-engine/file-enumerator.js +51 -30
  15. package/lib/cli-engine/formatters/html.js +1 -0
  16. package/lib/init/autoconfig.js +1 -11
  17. package/lib/init/config-file.js +0 -1
  18. package/lib/init/config-initializer.js +4 -4
  19. package/lib/init/config-rule.js +1 -5
  20. package/lib/init/npm-utils.js +0 -5
  21. package/lib/linter/code-path-analysis/code-path-analyzer.js +24 -38
  22. package/lib/linter/code-path-analysis/code-path-segment.js +17 -25
  23. package/lib/linter/code-path-analysis/code-path-state.js +40 -81
  24. package/lib/linter/code-path-analysis/code-path.js +10 -11
  25. package/lib/linter/code-path-analysis/debug-helpers.js +8 -12
  26. package/lib/linter/code-path-analysis/fork-context.js +23 -34
  27. package/lib/linter/code-path-analysis/id-generator.js +2 -2
  28. package/lib/linter/linter.js +121 -95
  29. package/lib/linter/node-event-generator.js +3 -2
  30. package/lib/linter/report-translator.js +73 -7
  31. package/lib/rule-tester/rule-tester.js +46 -14
  32. package/lib/rules/accessor-pairs.js +8 -8
  33. package/lib/rules/array-bracket-newline.js +12 -15
  34. package/lib/rules/array-bracket-spacing.js +12 -12
  35. package/lib/rules/array-callback-return.js +6 -11
  36. package/lib/rules/array-element-newline.js +5 -8
  37. package/lib/rules/arrow-parens.js +0 -1
  38. package/lib/rules/block-scoped-var.js +3 -3
  39. package/lib/rules/block-spacing.js +4 -4
  40. package/lib/rules/camelcase.js +19 -6
  41. package/lib/rules/capitalized-comments.js +0 -7
  42. package/lib/rules/class-methods-use-this.js +3 -3
  43. package/lib/rules/comma-dangle.js +20 -25
  44. package/lib/rules/comma-spacing.js +1 -1
  45. package/lib/rules/computed-property-spacing.js +14 -14
  46. package/lib/rules/consistent-return.js +4 -5
  47. package/lib/rules/consistent-this.js +5 -5
  48. package/lib/rules/constructor-super.js +14 -16
  49. package/lib/rules/curly.js +12 -9
  50. package/lib/rules/default-param-last.js +1 -0
  51. package/lib/rules/dot-location.js +11 -12
  52. package/lib/rules/func-names.js +6 -6
  53. package/lib/rules/function-call-argument-newline.js +8 -6
  54. package/lib/rules/generator-star-spacing.js +4 -9
  55. package/lib/rules/getter-return.js +4 -7
  56. package/lib/rules/grouped-accessor-pairs.js +224 -0
  57. package/lib/rules/indent.js +13 -2
  58. package/lib/rules/index.js +5 -0
  59. package/lib/rules/init-declarations.js +2 -2
  60. package/lib/rules/jsx-quotes.js +1 -1
  61. package/lib/rules/keyword-spacing.js +32 -56
  62. package/lib/rules/lines-around-directive.js +1 -1
  63. package/lib/rules/max-len.js +0 -5
  64. package/lib/rules/max-statements-per-line.js +3 -7
  65. package/lib/rules/multiline-comment-style.js +237 -106
  66. package/lib/rules/multiline-ternary.js +3 -3
  67. package/lib/rules/newline-after-var.js +6 -7
  68. package/lib/rules/newline-before-return.js +8 -9
  69. package/lib/rules/newline-per-chained-call.js +2 -4
  70. package/lib/rules/no-class-assign.js +2 -2
  71. package/lib/rules/no-compare-neg-zero.js +1 -2
  72. package/lib/rules/no-cond-assign.js +14 -4
  73. package/lib/rules/no-confusing-arrow.js +2 -2
  74. package/lib/rules/no-console.js +4 -8
  75. package/lib/rules/no-const-assign.js +1 -1
  76. package/lib/rules/no-constructor-return.js +62 -0
  77. package/lib/rules/no-dupe-args.js +1 -1
  78. package/lib/rules/no-dupe-class-members.js +3 -4
  79. package/lib/rules/no-dupe-else-if.js +122 -0
  80. package/lib/rules/no-dupe-keys.js +6 -5
  81. package/lib/rules/no-duplicate-imports.js +14 -18
  82. package/lib/rules/no-else-return.js +0 -8
  83. package/lib/rules/no-empty-function.js +2 -4
  84. package/lib/rules/no-eval.js +10 -18
  85. package/lib/rules/no-ex-assign.js +1 -1
  86. package/lib/rules/no-extra-bind.js +5 -12
  87. package/lib/rules/no-extra-boolean-cast.js +0 -2
  88. package/lib/rules/no-extra-label.js +4 -9
  89. package/lib/rules/no-extra-parens.js +17 -15
  90. package/lib/rules/no-extra-semi.js +5 -6
  91. package/lib/rules/no-fallthrough.js +6 -6
  92. package/lib/rules/no-func-assign.js +3 -3
  93. package/lib/rules/no-global-assign.js +4 -4
  94. package/lib/rules/no-implicit-coercion.js +10 -10
  95. package/lib/rules/no-implicit-globals.js +90 -8
  96. package/lib/rules/no-implied-eval.js +0 -1
  97. package/lib/rules/no-inline-comments.js +25 -11
  98. package/lib/rules/no-invalid-this.js +17 -5
  99. package/lib/rules/no-labels.js +3 -6
  100. package/lib/rules/no-lone-blocks.js +1 -1
  101. package/lib/rules/no-loop-func.js +6 -11
  102. package/lib/rules/no-magic-numbers.js +6 -6
  103. package/lib/rules/no-misleading-character-class.js +14 -7
  104. package/lib/rules/no-mixed-operators.js +13 -22
  105. package/lib/rules/no-mixed-requires.js +0 -1
  106. package/lib/rules/no-multi-spaces.js +1 -1
  107. package/lib/rules/no-native-reassign.js +4 -4
  108. package/lib/rules/no-octal-escape.js +1 -1
  109. package/lib/rules/no-param-reassign.js +28 -7
  110. package/lib/rules/no-redeclare.js +1 -1
  111. package/lib/rules/no-regex-spaces.js +0 -1
  112. package/lib/rules/no-restricted-imports.js +11 -11
  113. package/lib/rules/no-self-assign.js +12 -13
  114. package/lib/rules/no-sequences.js +3 -3
  115. package/lib/rules/no-setter-return.js +227 -0
  116. package/lib/rules/no-shadow.js +1 -4
  117. package/lib/rules/no-tabs.js +8 -2
  118. package/lib/rules/no-this-before-super.js +12 -13
  119. package/lib/rules/no-trailing-spaces.js +19 -7
  120. package/lib/rules/no-underscore-dangle.js +23 -4
  121. package/lib/rules/no-unmodified-loop-condition.js +16 -29
  122. package/lib/rules/no-unneeded-ternary.js +3 -3
  123. package/lib/rules/no-unreachable.js +7 -7
  124. package/lib/rules/no-unsafe-finally.js +4 -7
  125. package/lib/rules/no-unsafe-negation.js +32 -9
  126. package/lib/rules/no-unused-expressions.js +11 -7
  127. package/lib/rules/no-unused-labels.js +3 -6
  128. package/lib/rules/no-unused-vars.js +22 -29
  129. package/lib/rules/no-use-before-define.js +10 -15
  130. package/lib/rules/no-useless-call.js +4 -4
  131. package/lib/rules/no-useless-computed-key.js +60 -33
  132. package/lib/rules/no-useless-concat.js +4 -4
  133. package/lib/rules/no-useless-constructor.js +14 -22
  134. package/lib/rules/no-useless-escape.js +29 -8
  135. package/lib/rules/no-useless-rename.js +15 -7
  136. package/lib/rules/no-useless-return.js +8 -15
  137. package/lib/rules/no-var.js +12 -25
  138. package/lib/rules/no-warning-comments.js +0 -1
  139. package/lib/rules/no-whitespace-before-property.js +3 -3
  140. package/lib/rules/object-curly-newline.js +7 -10
  141. package/lib/rules/object-curly-spacing.js +21 -22
  142. package/lib/rules/object-shorthand.js +1 -1
  143. package/lib/rules/one-var-declaration-per-line.js +2 -2
  144. package/lib/rules/operator-assignment.js +33 -3
  145. package/lib/rules/padded-blocks.js +1 -1
  146. package/lib/rules/padding-line-between-statements.js +0 -16
  147. package/lib/rules/prefer-arrow-callback.js +6 -6
  148. package/lib/rules/prefer-const.js +27 -28
  149. package/lib/rules/prefer-destructuring.js +1 -7
  150. package/lib/rules/prefer-exponentiation-operator.js +189 -0
  151. package/lib/rules/prefer-named-capture-group.js +0 -1
  152. package/lib/rules/prefer-numeric-literals.js +32 -4
  153. package/lib/rules/prefer-object-spread.js +7 -7
  154. package/lib/rules/prefer-rest-params.js +3 -6
  155. package/lib/rules/prefer-spread.js +4 -4
  156. package/lib/rules/prefer-template.js +5 -6
  157. package/lib/rules/quote-props.js +1 -1
  158. package/lib/rules/quotes.js +5 -6
  159. package/lib/rules/radix.js +5 -10
  160. package/lib/rules/require-await.js +10 -5
  161. package/lib/rules/require-yield.js +2 -2
  162. package/lib/rules/rest-spread-spacing.js +1 -1
  163. package/lib/rules/semi.js +6 -3
  164. package/lib/rules/sort-imports.js +3 -4
  165. package/lib/rules/sort-keys.js +1 -3
  166. package/lib/rules/space-before-blocks.js +1 -2
  167. package/lib/rules/space-in-parens.js +4 -4
  168. package/lib/rules/space-infix-ops.js +6 -6
  169. package/lib/rules/spaced-comment.js +20 -22
  170. package/lib/rules/strict.js +2 -4
  171. package/lib/rules/symbol-description.js +1 -2
  172. package/lib/rules/template-curly-spacing.js +2 -2
  173. package/lib/rules/use-isnan.js +40 -3
  174. package/lib/rules/utils/ast-utils.js +84 -85
  175. package/lib/rules/utils/fix-tracker.js +0 -6
  176. package/lib/rules/utils/lazy-loading-rule-map.js +0 -1
  177. package/lib/rules/vars-on-top.js +11 -11
  178. package/lib/shared/config-ops.js +2 -2
  179. package/lib/shared/runtime-info.js +8 -8
  180. package/lib/shared/traverser.js +2 -0
  181. package/lib/shared/types.js +9 -0
  182. package/lib/source-code/source-code.js +62 -17
  183. package/lib/source-code/token-store/backward-token-comment-cursor.js +5 -5
  184. package/lib/source-code/token-store/backward-token-cursor.js +5 -5
  185. package/lib/source-code/token-store/cursors.js +17 -19
  186. package/lib/source-code/token-store/decorative-cursor.js +1 -1
  187. package/lib/source-code/token-store/filter-cursor.js +2 -2
  188. package/lib/source-code/token-store/forward-token-comment-cursor.js +5 -5
  189. package/lib/source-code/token-store/forward-token-cursor.js +5 -5
  190. package/lib/source-code/token-store/index.js +86 -92
  191. package/lib/source-code/token-store/limit-cursor.js +2 -2
  192. package/lib/source-code/token-store/padded-token-cursor.js +7 -7
  193. package/lib/source-code/token-store/skip-cursor.js +2 -2
  194. package/lib/source-code/token-store/utils.js +9 -13
  195. package/package.json +9 -7
  196. package/lib/cli-engine/ignored-paths.js +0 -362
@@ -27,8 +27,7 @@ const DEFAULT_OPTIONS = Object.freeze({
27
27
  /**
28
28
  * Checks whether or not a trailing comma is allowed in a given node.
29
29
  * If the `lastItem` is `RestElement` or `RestProperty`, it disallows trailing commas.
30
- *
31
- * @param {ASTNode} lastItem - The node of the last element in the given node.
30
+ * @param {ASTNode} lastItem The node of the last element in the given node.
32
31
  * @returns {boolean} `true` if a trailing comma is allowed.
33
32
  */
34
33
  function isTrailingCommaAllowed(lastItem) {
@@ -41,20 +40,18 @@ function isTrailingCommaAllowed(lastItem) {
41
40
 
42
41
  /**
43
42
  * Normalize option value.
44
- *
45
- * @param {string|Object|undefined} optionValue - The 1st option value to normalize.
43
+ * @param {string|Object|undefined} optionValue The 1st option value to normalize.
44
+ * @param {number} ecmaVersion The normalized ECMAScript version.
46
45
  * @returns {Object} The normalized option value.
47
46
  */
48
- function normalizeOptions(optionValue) {
47
+ function normalizeOptions(optionValue, ecmaVersion) {
49
48
  if (typeof optionValue === "string") {
50
49
  return {
51
50
  arrays: optionValue,
52
51
  objects: optionValue,
53
52
  imports: optionValue,
54
53
  exports: optionValue,
55
-
56
- // For backward compatibility, always ignore functions.
57
- functions: "ignore"
54
+ functions: (!ecmaVersion || ecmaVersion < 8) ? "ignore" : optionValue
58
55
  };
59
56
  }
60
57
  if (typeof optionValue === "object" && optionValue !== null) {
@@ -137,12 +134,13 @@ module.exports = {
137
134
  },
138
135
 
139
136
  create(context) {
140
- const options = normalizeOptions(context.options[0]);
137
+ const options = normalizeOptions(context.options[0], context.parserOptions.ecmaVersion);
138
+
141
139
  const sourceCode = context.getSourceCode();
142
140
 
143
141
  /**
144
142
  * Gets the last item of the given node.
145
- * @param {ASTNode} node - The node to get.
143
+ * @param {ASTNode} node The node to get.
146
144
  * @returns {ASTNode|null} The last node or null.
147
145
  */
148
146
  function getLastItem(node) {
@@ -172,9 +170,8 @@ module.exports = {
172
170
  * Gets the trailing comma token of the given node.
173
171
  * If the trailing comma does not exist, this returns the token which is
174
172
  * the insertion point of the trailing comma token.
175
- *
176
- * @param {ASTNode} node - The node to get.
177
- * @param {ASTNode} lastItem - The last item of the node.
173
+ * @param {ASTNode} node The node to get.
174
+ * @param {ASTNode} lastItem The last item of the node.
178
175
  * @returns {Token} The trailing comma token or the insertion point.
179
176
  */
180
177
  function getTrailingToken(node, lastItem) {
@@ -199,8 +196,7 @@ module.exports = {
199
196
  * Checks whether or not a given node is multiline.
200
197
  * This rule handles a given node as multiline when the closing parenthesis
201
198
  * and the last element are not on the same line.
202
- *
203
- * @param {ASTNode} node - A node to check.
199
+ * @param {ASTNode} node A node to check.
204
200
  * @returns {boolean} `true` if the node is multiline.
205
201
  */
206
202
  function isMultiline(node) {
@@ -218,8 +214,7 @@ module.exports = {
218
214
 
219
215
  /**
220
216
  * Reports a trailing comma if it exists.
221
- *
222
- * @param {ASTNode} node - A node to check. Its type is one of
217
+ * @param {ASTNode} node A node to check. Its type is one of
223
218
  * ObjectExpression, ObjectPattern, ArrayExpression, ArrayPattern,
224
219
  * ImportDeclaration, and ExportNamedDeclaration.
225
220
  * @returns {void}
@@ -236,7 +231,7 @@ module.exports = {
236
231
  if (astUtils.isCommaToken(trailingToken)) {
237
232
  context.report({
238
233
  node: lastItem,
239
- loc: trailingToken.loc.start,
234
+ loc: trailingToken.loc,
240
235
  messageId: "unexpected",
241
236
  fix(fixer) {
242
237
  return fixer.remove(trailingToken);
@@ -251,8 +246,7 @@ module.exports = {
251
246
  *
252
247
  * If a given node is `ArrayPattern` which has `RestElement`, the trailing
253
248
  * comma is disallowed, so report if it exists.
254
- *
255
- * @param {ASTNode} node - A node to check. Its type is one of
249
+ * @param {ASTNode} node A node to check. Its type is one of
256
250
  * ObjectExpression, ObjectPattern, ArrayExpression, ArrayPattern,
257
251
  * ImportDeclaration, and ExportNamedDeclaration.
258
252
  * @returns {void}
@@ -273,7 +267,10 @@ module.exports = {
273
267
  if (trailingToken.value !== ",") {
274
268
  context.report({
275
269
  node: lastItem,
276
- loc: trailingToken.loc.end,
270
+ loc: {
271
+ start: trailingToken.loc.end,
272
+ end: astUtils.getNextLocation(sourceCode, trailingToken.loc.end)
273
+ },
277
274
  messageId: "missing",
278
275
  fix(fixer) {
279
276
  return fixer.insertTextAfter(trailingToken, ",");
@@ -286,8 +283,7 @@ module.exports = {
286
283
  * If a given node is multiline, reports the last element of a given node
287
284
  * when it does not have a trailing comma.
288
285
  * Otherwise, reports a trailing comma if it exists.
289
- *
290
- * @param {ASTNode} node - A node to check. Its type is one of
286
+ * @param {ASTNode} node A node to check. Its type is one of
291
287
  * ObjectExpression, ObjectPattern, ArrayExpression, ArrayPattern,
292
288
  * ImportDeclaration, and ExportNamedDeclaration.
293
289
  * @returns {void}
@@ -304,8 +300,7 @@ module.exports = {
304
300
  * Only if a given node is not multiline, reports the last element of a given node
305
301
  * when it does not have a trailing comma.
306
302
  * Otherwise, reports a trailing comma if it exists.
307
- *
308
- * @param {ASTNode} node - A node to check. Its type is one of
303
+ * @param {ASTNode} node A node to check. Its type is one of
309
304
  * ObjectExpression, ObjectPattern, ArrayExpression, ArrayPattern,
310
305
  * ImportDeclaration, and ExportNamedDeclaration.
311
306
  * @returns {void}
@@ -105,7 +105,7 @@ module.exports = {
105
105
 
106
106
  /**
107
107
  * Validates the spacing around a comma token.
108
- * @param {Object} tokens - The tokens to be validated.
108
+ * @param {Object} tokens The tokens to be validated.
109
109
  * @param {Token} tokens.comma The token representing the comma.
110
110
  * @param {Token} [tokens.left] The last token before the comma.
111
111
  * @param {Token} [tokens.right] The first token after the comma.
@@ -59,9 +59,9 @@ module.exports = {
59
59
 
60
60
  /**
61
61
  * Reports that there shouldn't be a space after the first token
62
- * @param {ASTNode} node - The node to report in the event of an error.
63
- * @param {Token} token - The token to use for the report.
64
- * @param {Token} tokenAfter - The token after `token`.
62
+ * @param {ASTNode} node The node to report in the event of an error.
63
+ * @param {Token} token The token to use for the report.
64
+ * @param {Token} tokenAfter The token after `token`.
65
65
  * @returns {void}
66
66
  */
67
67
  function reportNoBeginningSpace(node, token, tokenAfter) {
@@ -80,9 +80,9 @@ module.exports = {
80
80
 
81
81
  /**
82
82
  * Reports that there shouldn't be a space before the last token
83
- * @param {ASTNode} node - The node to report in the event of an error.
84
- * @param {Token} token - The token to use for the report.
85
- * @param {Token} tokenBefore - The token before `token`.
83
+ * @param {ASTNode} node The node to report in the event of an error.
84
+ * @param {Token} token The token to use for the report.
85
+ * @param {Token} tokenBefore The token before `token`.
86
86
  * @returns {void}
87
87
  */
88
88
  function reportNoEndingSpace(node, token, tokenBefore) {
@@ -101,8 +101,8 @@ module.exports = {
101
101
 
102
102
  /**
103
103
  * Reports that there should be a space after the first token
104
- * @param {ASTNode} node - The node to report in the event of an error.
105
- * @param {Token} token - The token to use for the report.
104
+ * @param {ASTNode} node The node to report in the event of an error.
105
+ * @param {Token} token The token to use for the report.
106
106
  * @returns {void}
107
107
  */
108
108
  function reportRequiredBeginningSpace(node, token) {
@@ -121,8 +121,8 @@ module.exports = {
121
121
 
122
122
  /**
123
123
  * Reports that there should be a space before the last token
124
- * @param {ASTNode} node - The node to report in the event of an error.
125
- * @param {Token} token - The token to use for the report.
124
+ * @param {ASTNode} node The node to report in the event of an error.
125
+ * @param {Token} token The token to use for the report.
126
126
  * @returns {void}
127
127
  */
128
128
  function reportRequiredEndingSpace(node, token) {
@@ -153,10 +153,10 @@ module.exports = {
153
153
 
154
154
  const property = node[propertyName];
155
155
 
156
- const before = sourceCode.getTokenBefore(property),
157
- first = sourceCode.getFirstToken(property),
158
- last = sourceCode.getLastToken(property),
159
- after = sourceCode.getTokenAfter(property);
156
+ const before = sourceCode.getTokenBefore(property, astUtils.isOpeningBracketToken),
157
+ first = sourceCode.getTokenAfter(before, { includeComments: true }),
158
+ after = sourceCode.getTokenAfter(property, astUtils.isClosingBracketToken),
159
+ last = sourceCode.getTokenBefore(after, { includeComments: true });
160
160
 
161
161
  if (astUtils.isTokenOnSameLine(before, first)) {
162
162
  if (propertyNameMustBeSpaced) {
@@ -18,8 +18,8 @@ const astUtils = require("./utils/ast-utils");
18
18
 
19
19
  /**
20
20
  * Checks whether or not a given node is an `Identifier` node which was named a given name.
21
- * @param {ASTNode} node - A node to check.
22
- * @param {string} name - An expected name of the node.
21
+ * @param {ASTNode} node A node to check.
22
+ * @param {string} name An expected name of the node.
23
23
  * @returns {boolean} `true` if the node is an `Identifier` node which was named as expected.
24
24
  */
25
25
  function isIdentifier(node, name) {
@@ -28,7 +28,7 @@ function isIdentifier(node, name) {
28
28
 
29
29
  /**
30
30
  * Checks whether or not a given code path segment is unreachable.
31
- * @param {CodePathSegment} segment - A CodePathSegment to check.
31
+ * @param {CodePathSegment} segment A CodePathSegment to check.
32
32
  * @returns {boolean} `true` if the segment is unreachable.
33
33
  */
34
34
  function isUnreachable(segment) {
@@ -88,8 +88,7 @@ module.exports = {
88
88
  /**
89
89
  * Checks whether of not the implicit returning is consistent if the last
90
90
  * code path segment is reachable.
91
- *
92
- * @param {ASTNode} node - A program/function node to check.
91
+ * @param {ASTNode} node A program/function node to check.
93
92
  * @returns {void}
94
93
  */
95
94
  function checkLastSegment(node) {
@@ -46,8 +46,8 @@ module.exports = {
46
46
  /**
47
47
  * Reports that a variable declarator or assignment expression is assigning
48
48
  * a non-'this' value to the specified alias.
49
- * @param {ASTNode} node - The assigning node.
50
- * @param {string} name - the name of the alias that was incorrectly used.
49
+ * @param {ASTNode} node The assigning node.
50
+ * @param {string} name the name of the alias that was incorrectly used.
51
51
  * @returns {void}
52
52
  */
53
53
  function reportBadAssignment(node, name) {
@@ -57,9 +57,9 @@ module.exports = {
57
57
  /**
58
58
  * Checks that an assignment to an identifier only assigns 'this' to the
59
59
  * appropriate alias, and the alias is only assigned to 'this'.
60
- * @param {ASTNode} node - The assigning node.
61
- * @param {Identifier} name - The name of the variable assigned to.
62
- * @param {Expression} value - The value of the assignment.
60
+ * @param {ASTNode} node The assigning node.
61
+ * @param {Identifier} name The name of the variable assigned to.
62
+ * @param {Expression} value The value of the assignment.
63
63
  * @returns {void}
64
64
  */
65
65
  function checkAssignment(node, name, value) {
@@ -11,8 +11,7 @@
11
11
 
12
12
  /**
13
13
  * Checks whether a given code path segment is reachable or not.
14
- *
15
- * @param {CodePathSegment} segment - A code path segment to check.
14
+ * @param {CodePathSegment} segment A code path segment to check.
16
15
  * @returns {boolean} `true` if the segment is reachable.
17
16
  */
18
17
  function isReachable(segment) {
@@ -21,7 +20,7 @@ function isReachable(segment) {
21
20
 
22
21
  /**
23
22
  * Checks whether or not a given node is a constructor.
24
- * @param {ASTNode} node - A node to check. This node type is one of
23
+ * @param {ASTNode} node A node to check. This node type is one of
25
24
  * `Program`, `FunctionDeclaration`, `FunctionExpression`, and
26
25
  * `ArrowFunctionExpression`.
27
26
  * @returns {boolean} `true` if the node is a constructor.
@@ -36,8 +35,7 @@ function isConstructorFunction(node) {
36
35
 
37
36
  /**
38
37
  * Checks whether a given node can be a constructor or not.
39
- *
40
- * @param {ASTNode} node - A node to check.
38
+ * @param {ASTNode} node A node to check.
41
39
  * @returns {boolean} `true` if the node can be a constructor.
42
40
  */
43
41
  function isPossibleConstructor(node) {
@@ -137,7 +135,7 @@ module.exports = {
137
135
 
138
136
  /**
139
137
  * Gets the flag which shows `super()` is called in some paths.
140
- * @param {CodePathSegment} segment - A code path segment to get.
138
+ * @param {CodePathSegment} segment A code path segment to get.
141
139
  * @returns {boolean} The flag which shows `super()` is called in some paths
142
140
  */
143
141
  function isCalledInSomePath(segment) {
@@ -146,7 +144,7 @@ module.exports = {
146
144
 
147
145
  /**
148
146
  * Gets the flag which shows `super()` is called in all paths.
149
- * @param {CodePathSegment} segment - A code path segment to get.
147
+ * @param {CodePathSegment} segment A code path segment to get.
150
148
  * @returns {boolean} The flag which shows `super()` is called in all paths.
151
149
  */
152
150
  function isCalledInEveryPath(segment) {
@@ -168,8 +166,8 @@ module.exports = {
168
166
 
169
167
  /**
170
168
  * Stacks a constructor information.
171
- * @param {CodePath} codePath - A code path which was started.
172
- * @param {ASTNode} node - The current node.
169
+ * @param {CodePath} codePath A code path which was started.
170
+ * @param {ASTNode} node The current node.
173
171
  * @returns {void}
174
172
  */
175
173
  onCodePathStart(codePath, node) {
@@ -200,8 +198,8 @@ module.exports = {
200
198
  /**
201
199
  * Pops a constructor information.
202
200
  * And reports if `super()` lacked.
203
- * @param {CodePath} codePath - A code path which was ended.
204
- * @param {ASTNode} node - The current node.
201
+ * @param {CodePath} codePath A code path which was ended.
202
+ * @param {ASTNode} node The current node.
205
203
  * @returns {void}
206
204
  */
207
205
  onCodePathEnd(codePath, node) {
@@ -231,7 +229,7 @@ module.exports = {
231
229
 
232
230
  /**
233
231
  * Initialize information of a given code path segment.
234
- * @param {CodePathSegment} segment - A code path segment to initialize.
232
+ * @param {CodePathSegment} segment A code path segment to initialize.
235
233
  * @returns {void}
236
234
  */
237
235
  onCodePathSegmentStart(segment) {
@@ -258,9 +256,9 @@ module.exports = {
258
256
  /**
259
257
  * Update information of the code path segment when a code path was
260
258
  * looped.
261
- * @param {CodePathSegment} fromSegment - The code path segment of the
259
+ * @param {CodePathSegment} fromSegment The code path segment of the
262
260
  * end of a loop.
263
- * @param {CodePathSegment} toSegment - A code path segment of the head
261
+ * @param {CodePathSegment} toSegment A code path segment of the head
264
262
  * of a loop.
265
263
  * @returns {void}
266
264
  */
@@ -303,7 +301,7 @@ module.exports = {
303
301
 
304
302
  /**
305
303
  * Checks for a call of `super()`.
306
- * @param {ASTNode} node - A CallExpression node to check.
304
+ * @param {ASTNode} node A CallExpression node to check.
307
305
  * @returns {void}
308
306
  */
309
307
  "CallExpression:exit"(node) {
@@ -358,7 +356,7 @@ module.exports = {
358
356
 
359
357
  /**
360
358
  * Set the mark to the returned path as `super()` was called.
361
- * @param {ASTNode} node - A ReturnStatement node to check.
359
+ * @param {ASTNode} node A ReturnStatement node to check.
362
360
  * @returns {void}
363
361
  */
364
362
  ReturnStatement(node) {
@@ -97,10 +97,15 @@ module.exports = {
97
97
  * @private
98
98
  */
99
99
  function isOneLiner(node) {
100
- const first = sourceCode.getFirstToken(node),
101
- last = sourceCode.getLastToken(node);
100
+ if (node.type === "EmptyStatement") {
101
+ return true;
102
+ }
102
103
 
103
- return first.loc.start.line === last.loc.end.line;
104
+ const first = sourceCode.getFirstToken(node);
105
+ const last = sourceCode.getLastToken(node);
106
+ const lastExcludingSemicolon = astUtils.isSemicolonToken(last) ? sourceCode.getTokenBefore(last) : last;
107
+
108
+ return first.loc.start.line === lastExcludingSemicolon.loc.end.line;
104
109
  }
105
110
 
106
111
  /**
@@ -119,8 +124,7 @@ module.exports = {
119
124
 
120
125
  /**
121
126
  * Checks if the given token is an `else` token or not.
122
- *
123
- * @param {Token} token - The token to check.
127
+ * @param {Token} token The token to check.
124
128
  * @returns {boolean} `true` if the token is an `else` token.
125
129
  */
126
130
  function isElseKeywordToken(token) {
@@ -129,7 +133,7 @@ module.exports = {
129
133
 
130
134
  /**
131
135
  * Gets the `else` keyword token of a given `IfStatement` node.
132
- * @param {ASTNode} node - A `IfStatement` node to get.
136
+ * @param {ASTNode} node A `IfStatement` node to get.
133
137
  * @returns {Token} The `else` keyword token.
134
138
  */
135
139
  function getElseKeyword(node) {
@@ -143,8 +147,7 @@ module.exports = {
143
147
  * 1. The given node has the `alternate` node.
144
148
  * 2. There is a `IfStatement` which doesn't have `alternate` node in the
145
149
  * trailing statement chain of the `consequent` node.
146
- *
147
- * @param {ASTNode} node - A IfStatement node to check.
150
+ * @param {ASTNode} node A IfStatement node to check.
148
151
  * @returns {boolean} `true` if the node requires braces of the consequent chunk.
149
152
  */
150
153
  function requiresBraceOfConsequent(node) {
@@ -242,7 +245,7 @@ module.exports = {
242
245
  if (node.type === "IfStatement" && node.consequent === body && requiresBraceOfConsequent(node)) {
243
246
  expected = true;
244
247
  } else if (multiOnly) {
245
- if (hasBlock && body.body.length === 1) {
248
+ if (hasBlock && body.body.length === 1 && !isLexicalDeclaration(body.body[0])) {
246
249
  expected = false;
247
250
  }
248
251
  } else if (multiLine) {
@@ -25,6 +25,7 @@ module.exports = {
25
25
 
26
26
  create(context) {
27
27
 
28
+ // eslint-disable-next-line jsdoc/require-description
28
29
  /**
29
30
  * @param {ASTNode} node function node
30
31
  * @returns {void}
@@ -47,19 +47,18 @@ module.exports = {
47
47
 
48
48
  /**
49
49
  * Reports if the dot between object and property is on the correct loccation.
50
- * @param {ASTNode} obj The object owning the property.
51
- * @param {ASTNode} prop The property of the object.
52
- * @param {ASTNode} node The corresponding node of the token.
50
+ * @param {ASTNode} node The `MemberExpression` node.
53
51
  * @returns {void}
54
52
  */
55
- function checkDotLocation(obj, prop, node) {
56
- const dot = sourceCode.getTokenBefore(prop);
53
+ function checkDotLocation(node) {
54
+ const property = node.property;
55
+ const dot = sourceCode.getTokenBefore(property);
57
56
 
58
57
  // `obj` expression can be parenthesized, but those paren tokens are not a part of the `obj` node.
59
58
  const tokenBeforeDot = sourceCode.getTokenBefore(dot);
60
59
 
61
60
  const textBeforeDot = sourceCode.getText().slice(tokenBeforeDot.range[1], dot.range[0]);
62
- const textAfterDot = sourceCode.getText().slice(dot.range[1], prop.range[0]);
61
+ const textAfterDot = sourceCode.getText().slice(dot.range[1], property.range[0]);
63
62
 
64
63
  if (onObject) {
65
64
  if (!astUtils.isTokenOnSameLine(tokenBeforeDot, dot)) {
@@ -67,17 +66,17 @@ module.exports = {
67
66
 
68
67
  context.report({
69
68
  node,
70
- loc: dot.loc.start,
69
+ loc: dot.loc,
71
70
  messageId: "expectedDotAfterObject",
72
- fix: fixer => fixer.replaceTextRange([tokenBeforeDot.range[1], prop.range[0]], `${neededTextAfterToken}.${textBeforeDot}${textAfterDot}`)
71
+ fix: fixer => fixer.replaceTextRange([tokenBeforeDot.range[1], property.range[0]], `${neededTextAfterToken}.${textBeforeDot}${textAfterDot}`)
73
72
  });
74
73
  }
75
- } else if (!astUtils.isTokenOnSameLine(dot, prop)) {
74
+ } else if (!astUtils.isTokenOnSameLine(dot, property)) {
76
75
  context.report({
77
76
  node,
78
- loc: dot.loc.start,
77
+ loc: dot.loc,
79
78
  messageId: "expectedDotBeforeProperty",
80
- fix: fixer => fixer.replaceTextRange([tokenBeforeDot.range[1], prop.range[0]], `${textBeforeDot}${textAfterDot}.`)
79
+ fix: fixer => fixer.replaceTextRange([tokenBeforeDot.range[1], property.range[0]], `${textBeforeDot}${textAfterDot}.`)
81
80
  });
82
81
  }
83
82
  }
@@ -89,7 +88,7 @@ module.exports = {
89
88
  */
90
89
  function checkNode(node) {
91
90
  if (!node.computed) {
92
- checkDotLocation(node.object, node.property, node);
91
+ checkDotLocation(node);
93
92
  }
94
93
  }
95
94
 
@@ -13,7 +13,7 @@ const astUtils = require("./utils/ast-utils");
13
13
 
14
14
  /**
15
15
  * Checks whether or not a given variable is a function name.
16
- * @param {eslint-scope.Variable} variable - A variable to check.
16
+ * @param {eslint-scope.Variable} variable A variable to check.
17
17
  * @returns {boolean} `true` if the variable is a function name.
18
18
  */
19
19
  function isFunctionName(variable) {
@@ -73,7 +73,7 @@ module.exports = {
73
73
 
74
74
  /**
75
75
  * Returns the config option for the given node.
76
- * @param {ASTNode} node - A node to get the config for.
76
+ * @param {ASTNode} node A node to get the config for.
77
77
  * @returns {string} The config option.
78
78
  */
79
79
  function getConfigForNode(node) {
@@ -91,7 +91,7 @@ module.exports = {
91
91
  /**
92
92
  * Determines whether the current FunctionExpression node is a get, set, or
93
93
  * shorthand method in an object literal or a class.
94
- * @param {ASTNode} node - A node to check.
94
+ * @param {ASTNode} node A node to check.
95
95
  * @returns {boolean} True if the node is a get, set, or shorthand method.
96
96
  */
97
97
  function isObjectOrClassMethod(node) {
@@ -109,7 +109,7 @@ module.exports = {
109
109
  /**
110
110
  * Determines whether the current FunctionExpression node has a name that would be
111
111
  * inferred from context in a conforming ES6 environment.
112
- * @param {ASTNode} node - A node to check.
112
+ * @param {ASTNode} node A node to check.
113
113
  * @returns {boolean} True if the node would have a name assigned automatically.
114
114
  */
115
115
  function hasInferredName(node) {
@@ -125,7 +125,7 @@ module.exports = {
125
125
 
126
126
  /**
127
127
  * Reports that an unnamed function should be named
128
- * @param {ASTNode} node - The node to report in the event of an error.
128
+ * @param {ASTNode} node The node to report in the event of an error.
129
129
  * @returns {void}
130
130
  */
131
131
  function reportUnexpectedUnnamedFunction(node) {
@@ -139,7 +139,7 @@ module.exports = {
139
139
 
140
140
  /**
141
141
  * Reports that a named function should be unnamed
142
- * @param {ASTNode} node - The node to report in the event of an error.
142
+ * @param {ASTNode} node The node to report in the event of an error.
143
143
  * @returns {void}
144
144
  */
145
145
  function reportUnexpectedNamedFunction(node) {
@@ -40,13 +40,13 @@ module.exports = {
40
40
  const checkers = {
41
41
  unexpected: {
42
42
  messageId: "unexpectedLineBreak",
43
- check: (prevToken, currentToken) => prevToken.loc.start.line !== currentToken.loc.start.line,
43
+ check: (prevToken, currentToken) => prevToken.loc.end.line !== currentToken.loc.start.line,
44
44
  createFix: (token, tokenBefore) => fixer =>
45
45
  fixer.replaceTextRange([tokenBefore.range[1], token.range[0]], " ")
46
46
  },
47
47
  missing: {
48
48
  messageId: "missingLineBreak",
49
- check: (prevToken, currentToken) => prevToken.loc.start.line === currentToken.loc.start.line,
49
+ check: (prevToken, currentToken) => prevToken.loc.end.line === currentToken.loc.start.line,
50
50
  createFix: (token, tokenBefore) => fixer =>
51
51
  fixer.replaceTextRange([tokenBefore.range[1], token.range[0]], "\n")
52
52
  }
@@ -61,7 +61,7 @@ module.exports = {
61
61
  */
62
62
  function checkArguments(node, checker) {
63
63
  for (let i = 1; i < node.arguments.length; i++) {
64
- const prevArgToken = sourceCode.getFirstToken(node.arguments[i - 1]);
64
+ const prevArgToken = sourceCode.getLastToken(node.arguments[i - 1]);
65
65
  const currentArgToken = sourceCode.getFirstToken(node.arguments[i]);
66
66
 
67
67
  if (checker.check(prevArgToken, currentArgToken)) {
@@ -70,6 +70,8 @@ module.exports = {
70
70
  { includeComments: true }
71
71
  );
72
72
 
73
+ const hasLineCommentBefore = tokenBefore.type === "Line";
74
+
73
75
  context.report({
74
76
  node,
75
77
  loc: {
@@ -77,7 +79,7 @@ module.exports = {
77
79
  end: currentArgToken.loc.start
78
80
  },
79
81
  messageId: checker.messageId,
80
- fix: checker.createFix(currentArgToken, tokenBefore)
82
+ fix: hasLineCommentBefore ? null : checker.createFix(currentArgToken, tokenBefore)
81
83
  });
82
84
  }
83
85
  }
@@ -101,10 +103,10 @@ module.exports = {
101
103
  } else if (option === "always") {
102
104
  checkArguments(node, checkers.missing);
103
105
  } else if (option === "consistent") {
104
- const firstArgToken = sourceCode.getFirstToken(node.arguments[0]);
106
+ const firstArgToken = sourceCode.getLastToken(node.arguments[0]);
105
107
  const secondArgToken = sourceCode.getFirstToken(node.arguments[1]);
106
108
 
107
- if (firstArgToken.loc.start.line === secondArgToken.loc.start.line) {
109
+ if (firstArgToken.loc.end.line === secondArgToken.loc.start.line) {
108
110
  checkArguments(node, checkers.unexpected);
109
111
  } else {
110
112
  checkArguments(node, checkers.missing);
@@ -78,9 +78,8 @@ module.exports = {
78
78
 
79
79
  /**
80
80
  * Returns resolved option definitions based on an option and defaults
81
- *
82
- * @param {any} option - The option object or string value
83
- * @param {Object} defaults - The defaults to use if options are not present
81
+ * @param {any} option The option object or string value
82
+ * @param {Object} defaults The defaults to use if options are not present
84
83
  * @returns {Object} the resolved object definition
85
84
  */
86
85
  function optionToDefinition(option, defaults) {
@@ -107,8 +106,7 @@ module.exports = {
107
106
 
108
107
  /**
109
108
  * Checks if the given token is a star token or not.
110
- *
111
- * @param {Token} token - The token to check.
109
+ * @param {Token} token The token to check.
112
110
  * @returns {boolean} `true` if the token is a star token.
113
111
  */
114
112
  function isStarToken(token) {
@@ -117,8 +115,7 @@ module.exports = {
117
115
 
118
116
  /**
119
117
  * Gets the generator star token of the given function node.
120
- *
121
- * @param {ASTNode} node - The function node to get.
118
+ * @param {ASTNode} node The function node to get.
122
119
  * @returns {Token} Found star token.
123
120
  */
124
121
  function getStarToken(node) {
@@ -139,7 +136,6 @@ module.exports = {
139
136
 
140
137
  /**
141
138
  * Checks the spacing between two tokens before or after the star token.
142
- *
143
139
  * @param {string} kind Either "named", "anonymous", or "method"
144
140
  * @param {string} side Either "before" or "after".
145
141
  * @param {Token} leftToken `function` keyword token if side is "before", or
@@ -173,7 +169,6 @@ module.exports = {
173
169
 
174
170
  /**
175
171
  * Enforces the spacing around the star if node is a generator function.
176
- *
177
172
  * @param {ASTNode} node A function expression or declaration node.
178
173
  * @returns {void}
179
174
  */