eslint 4.10.0 → 4.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (103) hide show
  1. package/CHANGELOG.md +36 -22
  2. package/conf/default-cli-options.js +5 -3
  3. package/lib/ast-utils.js +81 -41
  4. package/lib/cli-engine.js +27 -12
  5. package/lib/code-path-analysis/code-path-analyzer.js +8 -4
  6. package/lib/code-path-analysis/code-path-segment.js +4 -2
  7. package/lib/code-path-analysis/code-path-state.js +4 -2
  8. package/lib/config/autoconfig.js +14 -12
  9. package/lib/config/config-file.js +8 -51
  10. package/lib/config/config-initializer.js +10 -6
  11. package/lib/config/config-ops.js +21 -21
  12. package/lib/config/config-rule.js +24 -24
  13. package/lib/config/config-validator.js +38 -36
  14. package/lib/config/plugins.js +8 -35
  15. package/lib/config.js +12 -8
  16. package/lib/formatters/junit.js +21 -15
  17. package/lib/formatters/tap.js +5 -3
  18. package/lib/ignored-paths.js +4 -2
  19. package/lib/linter.js +16 -10
  20. package/lib/rules/.eslintrc.yml +2 -2
  21. package/lib/rules/array-bracket-newline.js +20 -20
  22. package/lib/rules/array-bracket-spacing.js +28 -28
  23. package/lib/rules/array-callback-return.js +13 -9
  24. package/lib/rules/array-element-newline.js +8 -8
  25. package/lib/rules/arrow-body-style.js +12 -6
  26. package/lib/rules/arrow-parens.js +4 -2
  27. package/lib/rules/brace-style.js +14 -14
  28. package/lib/rules/computed-property-spacing.js +22 -22
  29. package/lib/rules/consistent-return.js +4 -4
  30. package/lib/rules/consistent-this.js +4 -2
  31. package/lib/rules/curly.js +13 -9
  32. package/lib/rules/dot-notation.js +5 -5
  33. package/lib/rules/func-call-spacing.js +4 -2
  34. package/lib/rules/getter-return.js +2 -1
  35. package/lib/rules/indent-legacy.js +20 -12
  36. package/lib/rules/indent.js +77 -73
  37. package/lib/rules/key-spacing.js +5 -3
  38. package/lib/rules/lines-around-directive.js +16 -12
  39. package/lib/rules/max-statements-per-line.js +5 -3
  40. package/lib/rules/newline-after-var.js +8 -6
  41. package/lib/rules/newline-before-return.js +9 -7
  42. package/lib/rules/no-await-in-loop.js +17 -9
  43. package/lib/rules/no-bitwise.js +5 -3
  44. package/lib/rules/no-catch-shadow.js +4 -2
  45. package/lib/rules/no-console.js +2 -1
  46. package/lib/rules/no-else-return.js +17 -11
  47. package/lib/rules/no-empty-character-class.js +11 -11
  48. package/lib/rules/no-extra-parens.js +16 -8
  49. package/lib/rules/no-extra-semi.js +5 -3
  50. package/lib/rules/no-global-assign.js +4 -2
  51. package/lib/rules/no-implicit-coercion.js +6 -6
  52. package/lib/rules/no-implied-eval.js +2 -1
  53. package/lib/rules/no-label-var.js +4 -2
  54. package/lib/rules/no-lone-blocks.js +3 -3
  55. package/lib/rules/no-loop-func.js +8 -4
  56. package/lib/rules/no-native-reassign.js +4 -2
  57. package/lib/rules/no-param-reassign.js +4 -2
  58. package/lib/rules/no-regex-spaces.js +1 -1
  59. package/lib/rules/no-restricted-properties.js +10 -10
  60. package/lib/rules/no-return-await.js +6 -6
  61. package/lib/rules/no-self-assign.js +4 -2
  62. package/lib/rules/no-sequences.js +6 -4
  63. package/lib/rules/no-trailing-spaces.js +13 -7
  64. package/lib/rules/no-unreachable.js +4 -2
  65. package/lib/rules/no-use-before-define.js +13 -11
  66. package/lib/rules/no-useless-call.js +1 -25
  67. package/lib/rules/no-useless-escape.js +23 -22
  68. package/lib/rules/no-useless-return.js +14 -8
  69. package/lib/rules/no-whitespace-before-property.js +4 -2
  70. package/lib/rules/object-curly-newline.js +9 -2
  71. package/lib/rules/object-curly-spacing.js +20 -20
  72. package/lib/rules/object-shorthand.js +41 -33
  73. package/lib/rules/operator-assignment.js +9 -9
  74. package/lib/rules/operator-linebreak.js +12 -10
  75. package/lib/rules/padding-line-between-statements.js +4 -2
  76. package/lib/rules/prefer-arrow-callback.js +12 -10
  77. package/lib/rules/prefer-const.js +18 -10
  78. package/lib/rules/prefer-destructuring.js +4 -2
  79. package/lib/rules/prefer-numeric-literals.js +4 -2
  80. package/lib/rules/prefer-promise-reject-errors.js +16 -16
  81. package/lib/rules/prefer-rest-params.js +4 -2
  82. package/lib/rules/prefer-spread.js +1 -25
  83. package/lib/rules/prefer-template.js +33 -29
  84. package/lib/rules/quote-props.js +8 -8
  85. package/lib/rules/semi-style.js +44 -19
  86. package/lib/rules/semi.js +5 -3
  87. package/lib/rules/sort-imports.js +5 -3
  88. package/lib/rules/space-unary-ops.js +61 -61
  89. package/lib/rules/strict.js +8 -8
  90. package/lib/rules/valid-typeof.js +4 -4
  91. package/lib/rules/wrap-iife.js +4 -4
  92. package/lib/rules/yoda.js +9 -7
  93. package/lib/testers/rule-tester.js +43 -34
  94. package/lib/token-store/backward-token-cursor.js +5 -3
  95. package/lib/token-store/forward-token-cursor.js +5 -3
  96. package/lib/token-store/utils.js +8 -4
  97. package/lib/util/glob.js +1 -1
  98. package/lib/util/naming.js +112 -0
  99. package/lib/util/node-event-generator.js +10 -10
  100. package/lib/util/safe-emitter.js +1 -1
  101. package/lib/util/source-code-fixer.js +4 -2
  102. package/lib/util/source-code.js +2 -1
  103. package/package.json +6 -5
@@ -189,12 +189,12 @@ module.exports = {
189
189
  const sourceCode = context.getSourceCode();
190
190
 
191
191
  /**
192
- * Reports an error and autofixes the node
193
- * @param {ASTNode} node - An ast node to report the error on.
194
- * @param {string} recommendation - The recommended code for the issue
195
- * @param {bool} shouldFix - Whether this report should fix the node
196
- * @returns {void}
197
- */
192
+ * Reports an error and autofixes the node
193
+ * @param {ASTNode} node - An ast node to report the error on.
194
+ * @param {string} recommendation - The recommended code for the issue
195
+ * @param {bool} shouldFix - Whether this report should fix the node
196
+ * @returns {void}
197
+ */
198
198
  function report(node, recommendation, shouldFix) {
199
199
  shouldFix = typeof shouldFix === "undefined" ? true : shouldFix;
200
200
 
@@ -125,7 +125,8 @@ module.exports = {
125
125
  "CallExpression:exit"(node) {
126
126
  if (node === last(last(impliedEvalAncestorsStack))) {
127
127
 
128
- /* Destroys the entire sub-stack, rather than just using
128
+ /*
129
+ * Destroys the entire sub-stack, rather than just using
129
130
  * last(impliedEvalAncestorsStack).pop(), as a CallExpression is
130
131
  * always the bottom of a impliedEvalAncestorsStack substack.
131
132
  */
@@ -54,8 +54,10 @@ module.exports = {
54
54
  // Fetch the innermost scope.
55
55
  const scope = context.getScope();
56
56
 
57
- // Recursively find the identifier walking up the scope, starting
58
- // with the innermost scope.
57
+ /*
58
+ * Recursively find the identifier walking up the scope, starting
59
+ * with the innermost scope.
60
+ */
59
61
  if (findIdentifier(scope, node.label.name)) {
60
62
  context.report({ node, message: "Found identifier with same name as label." });
61
63
  }
@@ -30,7 +30,7 @@ module.exports = {
30
30
  * Reports a node as invalid.
31
31
  * @param {ASTNode} node - The node to be reported.
32
32
  * @returns {void}
33
- */
33
+ */
34
34
  function report(node) {
35
35
  const message = node.parent.type === "BlockStatement" ? "Nested block is redundant." : "Block is redundant.";
36
36
 
@@ -41,7 +41,7 @@ module.exports = {
41
41
  * Checks for any ocurrence of a BlockStatement in a place where lists of statements can appear
42
42
  * @param {ASTNode} node The node to check
43
43
  * @returns {boolean} True if the node is a lone block.
44
- */
44
+ */
45
45
  function isLoneBlock(node) {
46
46
  return node.parent.type === "BlockStatement" ||
47
47
  node.parent.type === "Program" ||
@@ -54,7 +54,7 @@ module.exports = {
54
54
  * Checks the enclosing block of the current node for block-level bindings,
55
55
  * and "marks it" as valid if any.
56
56
  * @returns {void}
57
- */
57
+ */
58
58
  function markLoneBlock() {
59
59
  if (loneBlocks.length === 0) {
60
60
  return;
@@ -105,8 +105,10 @@ function isSafe(loopNode, reference) {
105
105
  return true;
106
106
  }
107
107
 
108
- // Variables which are declared by `let` in the loop is safe.
109
- // It's a different instance from the next loop step's.
108
+ /*
109
+ * Variables which are declared by `let` in the loop is safe.
110
+ * It's a different instance from the next loop step's.
111
+ */
110
112
  if (kind === "let" &&
111
113
  declaration.range[0] > loopNode.range[0] &&
112
114
  declaration.range[1] < loopNode.range[1]
@@ -114,8 +116,10 @@ function isSafe(loopNode, reference) {
114
116
  return true;
115
117
  }
116
118
 
117
- // WriteReferences which exist after this border are unsafe because those
118
- // can modify the variable.
119
+ /*
120
+ * WriteReferences which exist after this border are unsafe because those
121
+ * can modify the variable.
122
+ */
119
123
  const border = getTopLoopNode(
120
124
  loopNode,
121
125
  (kind === "let") ? declaration : null
@@ -53,8 +53,10 @@ module.exports = {
53
53
  if (reference.init === false &&
54
54
  reference.isWrite() &&
55
55
 
56
- // Destructuring assignments can have multiple default value,
57
- // so possibly there are multiple writeable references for the same identifier.
56
+ /*
57
+ * Destructuring assignments can have multiple default value,
58
+ * so possibly there are multiple writeable references for the same identifier.
59
+ */
58
60
  (index === 0 || references[index - 1].identifier !== identifier)
59
61
  ) {
60
62
  context.report({
@@ -127,8 +127,10 @@ module.exports = {
127
127
  if (identifier &&
128
128
  !reference.init &&
129
129
 
130
- // Destructuring assignments can have multiple default value,
131
- // so possibly there are multiple writeable references for the same identifier.
130
+ /*
131
+ * Destructuring assignments can have multiple default value,
132
+ * so possibly there are multiple writeable references for the same identifier.
133
+ */
132
134
  (index === 0 || references[index - 1].identifier !== identifier)
133
135
  ) {
134
136
  if (reference.isWrite()) {
@@ -32,7 +32,7 @@ module.exports = {
32
32
  * @param {ASTNode} node node to validate
33
33
  * @param {string} value regular expression to validate
34
34
  * @param {number} valueStart The start location of the regex/string literal. It will always be the case that
35
- `sourceCode.getText().slice(valueStart, valueStart + value.length) === value`
35
+ * `sourceCode.getText().slice(valueStart, valueStart + value.length) === value`
36
36
  * @returns {void}
37
37
  * @private
38
38
  */
@@ -92,12 +92,12 @@ module.exports = {
92
92
  });
93
93
 
94
94
  /**
95
- * Checks to see whether a property access is restricted, and reports it if so.
96
- * @param {ASTNode} node The node to report
97
- * @param {string} objectName The name of the object
98
- * @param {string} propertyName The name of the property
99
- * @returns {undefined}
100
- */
95
+ * Checks to see whether a property access is restricted, and reports it if so.
96
+ * @param {ASTNode} node The node to report
97
+ * @param {string} objectName The name of the object
98
+ * @param {string} propertyName The name of the property
99
+ * @returns {undefined}
100
+ */
101
101
  function checkPropertyAccess(node, objectName, propertyName) {
102
102
  if (propertyName === null) {
103
103
  return;
@@ -135,10 +135,10 @@ module.exports = {
135
135
  }
136
136
 
137
137
  /**
138
- * Checks property accesses in a destructuring assignment expression, e.g. `var foo; ({foo} = bar);`
139
- * @param {ASTNode} node An AssignmentExpression or AssignmentPattern node
140
- * @returns {undefined}
141
- */
138
+ * Checks property accesses in a destructuring assignment expression, e.g. `var foo; ({foo} = bar);`
139
+ * @param {ASTNode} node An AssignmentExpression or AssignmentPattern node
140
+ * @returns {undefined}
141
+ */
142
142
  function checkDestructuringAssignment(node) {
143
143
  if (node.right.type === "Identifier") {
144
144
  const objectName = node.right.name;
@@ -40,12 +40,12 @@ module.exports = {
40
40
  }
41
41
 
42
42
  /**
43
- * Determines whether a thrown error from this node will be caught/handled within this function rather than immediately halting
44
- * this function. For example, a statement in a `try` block will always have an error handler. A statement in
45
- * a `catch` block will only have an error handler if there is also a `finally` block.
46
- * @param {ASTNode} node A node representing a location where an could be thrown
47
- * @returns {boolean} `true` if a thrown error will be caught/handled in this function
48
- */
43
+ * Determines whether a thrown error from this node will be caught/handled within this function rather than immediately halting
44
+ * this function. For example, a statement in a `try` block will always have an error handler. A statement in
45
+ * a `catch` block will only have an error handler if there is also a `finally` block.
46
+ * @param {ASTNode} node A node representing a location where an could be thrown
47
+ * @returns {boolean} `true` if a thrown error will be caught/handled in this function
48
+ */
49
49
  function hasErrorHandler(node) {
50
50
  let ancestor = node;
51
51
 
@@ -114,8 +114,10 @@ function eachSelfAssignment(left, right, props, report) {
114
114
  right.properties.length >= 1
115
115
  ) {
116
116
 
117
- // Gets the index of the last spread property.
118
- // It's possible to overwrite properties followed by it.
117
+ /*
118
+ * Gets the index of the last spread property.
119
+ * It's possible to overwrite properties followed by it.
120
+ */
119
121
  let startJ = 0;
120
122
 
121
123
  for (let i = right.properties.length - 1; i >= 0; --i) {
@@ -40,10 +40,12 @@ module.exports = {
40
40
  WithStatement: "object",
41
41
  ArrowFunctionExpression: "body"
42
42
 
43
- // Omitting CallExpression - commas are parsed as argument separators
44
- // Omitting NewExpression - commas are parsed as argument separators
45
- // Omitting ForInStatement - parts aren't individually parenthesised
46
- // Omitting ForStatement - parts aren't individually parenthesised
43
+ /*
44
+ * Omitting CallExpression - commas are parsed as argument separators
45
+ * Omitting NewExpression - commas are parsed as argument separators
46
+ * Omitting ForInStatement - parts aren't individually parenthesised
47
+ * Omitting ForStatement - parts aren't individually parenthesised
48
+ */
47
49
  };
48
50
 
49
51
  /**
@@ -101,8 +101,10 @@ module.exports = {
101
101
 
102
102
  Program: function checkTrailingSpaces(node) {
103
103
 
104
- // Let's hack. Since Espree does not return whitespace nodes,
105
- // fetch the source code and do matching via regexps.
104
+ /*
105
+ * Let's hack. Since Espree does not return whitespace nodes,
106
+ * fetch the source code and do matching via regexps.
107
+ */
106
108
 
107
109
  const re = new RegExp(NONBLANK),
108
110
  skipMatch = new RegExp(SKIP_BLANK),
@@ -117,9 +119,11 @@ module.exports = {
117
119
  for (let i = 0, ii = lines.length; i < ii; i++) {
118
120
  const matches = re.exec(lines[i]);
119
121
 
120
- // Always add linebreak length to line length to accommodate for line break (\n or \r\n)
121
- // Because during the fix time they also reserve one spot in the array.
122
- // Usually linebreak length is 2 for \r\n (CRLF) and 1 for \n (LF)
122
+ /*
123
+ * Always add linebreak length to line length to accommodate for line break (\n or \r\n)
124
+ * Because during the fix time they also reserve one spot in the array.
125
+ * Usually linebreak length is 2 for \r\n (CRLF) and 1 for \n (LF)
126
+ */
123
127
  const linebreakLength = linebreaks && linebreaks[i] ? linebreaks[i].length : 1;
124
128
  const lineLength = lines[i].length + linebreakLength;
125
129
 
@@ -140,8 +144,10 @@ module.exports = {
140
144
  continue;
141
145
  }
142
146
 
143
- // If the line has only whitespace, and skipBlankLines
144
- // is true, don't report it
147
+ /*
148
+ * If the line has only whitespace, and skipBlankLines
149
+ * is true, don't report it
150
+ */
145
151
  if (skipBlankLines && skipMatch.test(lines[i])) {
146
152
  totalLength += lineLength;
147
153
  continue;
@@ -145,8 +145,10 @@ module.exports = {
145
145
  nextNode = node;
146
146
  }
147
147
 
148
- // Report the current range since this statement is reachable or is
149
- // not consecutive to the current range.
148
+ /*
149
+ * Report the current range since this statement is reachable or is
150
+ * not consecutive to the current range.
151
+ */
150
152
  if (!range.isEmpty) {
151
153
  context.report({
152
154
  message: "Unreachable code.",
@@ -59,11 +59,11 @@ function isOuterClass(variable, reference) {
59
59
  }
60
60
 
61
61
  /**
62
- * Checks whether or not a given variable is a variable declaration in an upper function scope.
63
- * @param {eslint-scope.Variable} variable - A variable to check.
64
- * @param {eslint-scope.Reference} reference - A reference to check.
65
- * @returns {boolean} `true` if the variable is a variable declaration.
66
- */
62
+ * Checks whether or not a given variable is a variable declaration in an upper function scope.
63
+ * @param {eslint-scope.Variable} variable - A variable to check.
64
+ * @param {eslint-scope.Reference} reference - A reference to check.
65
+ * @returns {boolean} `true` if the variable is a variable declaration.
66
+ */
67
67
  function isOuterVariable(variable, reference) {
68
68
  return (
69
69
  variable.defs[0].type === "Variable" &&
@@ -194,12 +194,14 @@ module.exports = {
194
194
  scope.references.forEach(reference => {
195
195
  const variable = reference.resolved;
196
196
 
197
- // Skips when the reference is:
198
- // - initialization's.
199
- // - referring to an undefined variable.
200
- // - referring to a global environment variable (there're no identifiers).
201
- // - located preceded by the variable (except in initializers).
202
- // - allowed by options.
197
+ /*
198
+ * Skips when the reference is:
199
+ * - initialization's.
200
+ * - referring to an undefined variable.
201
+ * - referring to a global environment variable (there're no identifiers).
202
+ * - located preceded by the variable (except in initializers).
203
+ * - allowed by options.
204
+ */
203
205
  if (reference.init ||
204
206
  !variable ||
205
207
  variable.identifiers.length === 0 ||
@@ -28,30 +28,6 @@ function isCallOrNonVariadicApply(node) {
28
28
  );
29
29
  }
30
30
 
31
- /**
32
- * Checks whether or not the tokens of two given nodes are same.
33
- * @param {ASTNode} left - A node 1 to compare.
34
- * @param {ASTNode} right - A node 2 to compare.
35
- * @param {SourceCode} sourceCode - The ESLint source code object.
36
- * @returns {boolean} the source code for the given node.
37
- */
38
- function equalTokens(left, right, sourceCode) {
39
- const tokensL = sourceCode.getTokens(left);
40
- const tokensR = sourceCode.getTokens(right);
41
-
42
- if (tokensL.length !== tokensR.length) {
43
- return false;
44
- }
45
- for (let i = 0; i < tokensL.length; ++i) {
46
- if (tokensL[i].type !== tokensR[i].type ||
47
- tokensL[i].value !== tokensR[i].value
48
- ) {
49
- return false;
50
- }
51
- }
52
-
53
- return true;
54
- }
55
31
 
56
32
  /**
57
33
  * Checks whether or not `thisArg` is not changed by `.call()`/`.apply()`.
@@ -64,7 +40,7 @@ function isValidThisArg(expectedThis, thisArg, sourceCode) {
64
40
  if (!expectedThis) {
65
41
  return astUtils.isNullOrUndefined(thisArg);
66
42
  }
67
- return equalTokens(expectedThis, thisArg, sourceCode);
43
+ return astUtils.equalTokens(expectedThis, thisArg, sourceCode);
68
44
  }
69
45
 
70
46
  //------------------------------------------------------------------------------
@@ -12,11 +12,11 @@ const astUtils = require("../ast-utils");
12
12
  //------------------------------------------------------------------------------
13
13
 
14
14
  /**
15
- * Returns the union of two sets.
16
- * @param {Set} setA The first set
17
- * @param {Set} setB The second set
18
- * @returns {Set} The union of the two sets
19
- */
15
+ * Returns the union of two sets.
16
+ * @param {Set} setA The first set
17
+ * @param {Set} setB The second set
18
+ * @returns {Set} The union of the two sets
19
+ */
20
20
  function union(setA, setB) {
21
21
  return new Set(function *() {
22
22
  yield* setA;
@@ -29,22 +29,22 @@ const REGEX_GENERAL_ESCAPES = new Set("\\bcdDfnrsStvwWxu0123456789]");
29
29
  const REGEX_NON_CHARCLASS_ESCAPES = union(REGEX_GENERAL_ESCAPES, new Set("^/.$*+?[{}|()B"));
30
30
 
31
31
  /**
32
- * Parses a regular expression into a list of characters with character class info.
33
- * @param {string} regExpText The raw text used to create the regular expression
34
- * @returns {Object[]} A list of characters, each with info on escaping and whether they're in a character class.
35
- * @example
36
- *
37
- * parseRegExp('a\\b[cd-]')
38
- *
39
- * returns:
40
- * [
41
- * {text: 'a', index: 0, escaped: false, inCharClass: false, startsCharClass: false, endsCharClass: false},
42
- * {text: 'b', index: 2, escaped: true, inCharClass: false, startsCharClass: false, endsCharClass: false},
43
- * {text: 'c', index: 4, escaped: false, inCharClass: true, startsCharClass: true, endsCharClass: false},
44
- * {text: 'd', index: 5, escaped: false, inCharClass: true, startsCharClass: false, endsCharClass: false},
45
- * {text: '-', index: 6, escaped: false, inCharClass: true, startsCharClass: false, endsCharClass: false}
46
- * ]
47
- */
32
+ * Parses a regular expression into a list of characters with character class info.
33
+ * @param {string} regExpText The raw text used to create the regular expression
34
+ * @returns {Object[]} A list of characters, each with info on escaping and whether they're in a character class.
35
+ * @example
36
+ *
37
+ * parseRegExp('a\\b[cd-]')
38
+ *
39
+ * returns:
40
+ * [
41
+ * {text: 'a', index: 0, escaped: false, inCharClass: false, startsCharClass: false, endsCharClass: false},
42
+ * {text: 'b', index: 2, escaped: true, inCharClass: false, startsCharClass: false, endsCharClass: false},
43
+ * {text: 'c', index: 4, escaped: false, inCharClass: true, startsCharClass: true, endsCharClass: false},
44
+ * {text: 'd', index: 5, escaped: false, inCharClass: true, startsCharClass: false, endsCharClass: false},
45
+ * {text: '-', index: 6, escaped: false, inCharClass: true, startsCharClass: false, endsCharClass: false}
46
+ * ]
47
+ */
48
48
  function parseRegExp(regExpText) {
49
49
  const charList = [];
50
50
 
@@ -130,7 +130,8 @@ module.exports = {
130
130
  isUnnecessaryEscape = match.input[match.index + 2] !== "{";
131
131
  } else if (escapedChar === "{") {
132
132
 
133
- /* Warn if `\{` is not preceded by `$`. If preceded by `$`, escaping
133
+ /*
134
+ * Warn if `\{` is not preceded by `$`. If preceded by `$`, escaping
134
135
  * is necessary and the rule should not warn. If preceded by `/$`, the rule
135
136
  * will warn for the `/$` instead, as it is the first unnecessarily escaped character.
136
137
  */
@@ -222,10 +222,12 @@ module.exports = {
222
222
  fix(fixer) {
223
223
  if (isRemovable(node)) {
224
224
 
225
- // Extend the replacement range to include the
226
- // entire function to avoid conflicting with
227
- // no-else-return.
228
- // https://github.com/eslint/eslint/issues/8026
225
+ /*
226
+ * Extend the replacement range to include the
227
+ * entire function to avoid conflicting with
228
+ * no-else-return.
229
+ * https://github.com/eslint/eslint/issues/8026
230
+ */
229
231
  return new FixTracker(fixer, context.getSourceCode())
230
232
  .retainEnclosingFunction(node)
231
233
  .remove(node);
@@ -238,8 +240,10 @@ module.exports = {
238
240
  scopeInfo = scopeInfo.upper;
239
241
  },
240
242
 
241
- // Initializes segments.
242
- // NOTE: This event is notified for only reachable segments.
243
+ /*
244
+ * Initializes segments.
245
+ * NOTE: This event is notified for only reachable segments.
246
+ */
243
247
  onCodePathSegmentStart(segment) {
244
248
  const info = {
245
249
  uselessReturns: getUselessReturns([], segment.allPrevSegments),
@@ -270,8 +274,10 @@ module.exports = {
270
274
  scopeInfo.uselessReturns.push(node);
271
275
  },
272
276
 
273
- // Registers for all statement nodes except FunctionDeclaration, BlockStatement, BreakStatement.
274
- // Removes return statements of the current segments from the useless return statement list.
277
+ /*
278
+ * Registers for all statement nodes except FunctionDeclaration, BlockStatement, BreakStatement.
279
+ * Removes return statements of the current segments from the useless return statement list.
280
+ */
275
281
  ClassDeclaration: markReturnStatementsOnCurrentSegmentsAsUsed,
276
282
  ContinueStatement: markReturnStatementsOnCurrentSegmentsAsUsed,
277
283
  DebuggerStatement: markReturnStatementsOnCurrentSegmentsAsUsed,
@@ -53,8 +53,10 @@ module.exports = {
53
53
  fix(fixer) {
54
54
  if (!node.computed && astUtils.isDecimalInteger(node.object)) {
55
55
 
56
- // If the object is a number literal, fixing it to something like 5.toString() would cause a SyntaxError.
57
- // Don't fix this case.
56
+ /*
57
+ * If the object is a number literal, fixing it to something like 5.toString() would cause a SyntaxError.
58
+ * Don't fix this case.
59
+ */
58
60
  return null;
59
61
  }
60
62
  return fixer.replaceTextRange([leftToken.range[1], rightToken.range[0]], replacementText);
@@ -131,8 +131,15 @@ module.exports = {
131
131
  */
132
132
  function check(node) {
133
133
  const options = normalizedOptions[node.type];
134
- const openBrace = sourceCode.getFirstToken(node);
135
- const closeBrace = sourceCode.getLastToken(node);
134
+ const openBrace = sourceCode.getFirstToken(node, token => token.value === "{");
135
+ let closeBrace;
136
+
137
+ if (node.typeAnnotation) {
138
+ closeBrace = sourceCode.getTokenBefore(node.typeAnnotation);
139
+ } else {
140
+ closeBrace = sourceCode.getLastToken(node);
141
+ }
142
+
136
143
  let first = sourceCode.getTokenAfter(openBrace, { includeComments: true });
137
144
  let last = sourceCode.getTokenBefore(closeBrace, { includeComments: true });
138
145
  const needsLinebreaks = (
@@ -65,11 +65,11 @@ module.exports = {
65
65
  //--------------------------------------------------------------------------
66
66
 
67
67
  /**
68
- * Reports that there shouldn't be a space after the first token
69
- * @param {ASTNode} node - The node to report in the event of an error.
70
- * @param {Token} token - The token to use for the report.
71
- * @returns {void}
72
- */
68
+ * Reports that there shouldn't be a space after the first token
69
+ * @param {ASTNode} node - The node to report in the event of an error.
70
+ * @param {Token} token - The token to use for the report.
71
+ * @returns {void}
72
+ */
73
73
  function reportNoBeginningSpace(node, token) {
74
74
  context.report({
75
75
  node,
@@ -87,11 +87,11 @@ module.exports = {
87
87
  }
88
88
 
89
89
  /**
90
- * Reports that there shouldn't be a space before the last token
91
- * @param {ASTNode} node - The node to report in the event of an error.
92
- * @param {Token} token - The token to use for the report.
93
- * @returns {void}
94
- */
90
+ * Reports that there shouldn't be a space before the last token
91
+ * @param {ASTNode} node - The node to report in the event of an error.
92
+ * @param {Token} token - The token to use for the report.
93
+ * @returns {void}
94
+ */
95
95
  function reportNoEndingSpace(node, token) {
96
96
  context.report({
97
97
  node,
@@ -109,11 +109,11 @@ module.exports = {
109
109
  }
110
110
 
111
111
  /**
112
- * Reports that there should be a space after the first token
113
- * @param {ASTNode} node - The node to report in the event of an error.
114
- * @param {Token} token - The token to use for the report.
115
- * @returns {void}
116
- */
112
+ * Reports that there should be a space after the first token
113
+ * @param {ASTNode} node - The node to report in the event of an error.
114
+ * @param {Token} token - The token to use for the report.
115
+ * @returns {void}
116
+ */
117
117
  function reportRequiredBeginningSpace(node, token) {
118
118
  context.report({
119
119
  node,
@@ -129,11 +129,11 @@ module.exports = {
129
129
  }
130
130
 
131
131
  /**
132
- * Reports that there should be a space before the last token
133
- * @param {ASTNode} node - The node to report in the event of an error.
134
- * @param {Token} token - The token to use for the report.
135
- * @returns {void}
136
- */
132
+ * Reports that there should be a space before the last token
133
+ * @param {ASTNode} node - The node to report in the event of an error.
134
+ * @param {Token} token - The token to use for the report.
135
+ * @returns {void}
136
+ */
137
137
  function reportRequiredEndingSpace(node, token) {
138
138
  context.report({
139
139
  node,