eslint 6.5.1 → 6.7.2

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 (197) hide show
  1. package/CHANGELOG.md +118 -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 +65 -34
  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-unexpected-multiline.js +8 -0
  122. package/lib/rules/no-unmodified-loop-condition.js +16 -29
  123. package/lib/rules/no-unneeded-ternary.js +3 -3
  124. package/lib/rules/no-unreachable.js +7 -7
  125. package/lib/rules/no-unsafe-finally.js +4 -7
  126. package/lib/rules/no-unsafe-negation.js +32 -9
  127. package/lib/rules/no-unused-expressions.js +11 -7
  128. package/lib/rules/no-unused-labels.js +3 -6
  129. package/lib/rules/no-unused-vars.js +22 -29
  130. package/lib/rules/no-use-before-define.js +10 -15
  131. package/lib/rules/no-useless-call.js +4 -4
  132. package/lib/rules/no-useless-computed-key.js +60 -33
  133. package/lib/rules/no-useless-concat.js +4 -4
  134. package/lib/rules/no-useless-constructor.js +14 -22
  135. package/lib/rules/no-useless-escape.js +29 -8
  136. package/lib/rules/no-useless-rename.js +7 -7
  137. package/lib/rules/no-useless-return.js +8 -15
  138. package/lib/rules/no-var.js +12 -25
  139. package/lib/rules/no-warning-comments.js +0 -1
  140. package/lib/rules/no-whitespace-before-property.js +3 -3
  141. package/lib/rules/object-curly-newline.js +7 -10
  142. package/lib/rules/object-curly-spacing.js +21 -22
  143. package/lib/rules/object-shorthand.js +1 -1
  144. package/lib/rules/one-var-declaration-per-line.js +2 -2
  145. package/lib/rules/operator-assignment.js +33 -3
  146. package/lib/rules/padded-blocks.js +1 -1
  147. package/lib/rules/padding-line-between-statements.js +0 -16
  148. package/lib/rules/prefer-arrow-callback.js +6 -6
  149. package/lib/rules/prefer-const.js +27 -28
  150. package/lib/rules/prefer-destructuring.js +1 -7
  151. package/lib/rules/prefer-exponentiation-operator.js +189 -0
  152. package/lib/rules/prefer-named-capture-group.js +0 -1
  153. package/lib/rules/prefer-numeric-literals.js +32 -4
  154. package/lib/rules/prefer-object-spread.js +7 -7
  155. package/lib/rules/prefer-rest-params.js +3 -6
  156. package/lib/rules/prefer-spread.js +4 -4
  157. package/lib/rules/prefer-template.js +5 -6
  158. package/lib/rules/quote-props.js +1 -1
  159. package/lib/rules/quotes.js +5 -6
  160. package/lib/rules/radix.js +5 -10
  161. package/lib/rules/require-await.js +10 -5
  162. package/lib/rules/require-yield.js +2 -2
  163. package/lib/rules/rest-spread-spacing.js +1 -1
  164. package/lib/rules/semi.js +6 -3
  165. package/lib/rules/sort-imports.js +3 -4
  166. package/lib/rules/sort-keys.js +1 -3
  167. package/lib/rules/space-before-blocks.js +1 -2
  168. package/lib/rules/space-in-parens.js +4 -4
  169. package/lib/rules/space-infix-ops.js +6 -6
  170. package/lib/rules/spaced-comment.js +20 -22
  171. package/lib/rules/strict.js +2 -4
  172. package/lib/rules/symbol-description.js +1 -2
  173. package/lib/rules/template-curly-spacing.js +2 -2
  174. package/lib/rules/use-isnan.js +40 -3
  175. package/lib/rules/utils/ast-utils.js +84 -85
  176. package/lib/rules/utils/fix-tracker.js +0 -6
  177. package/lib/rules/utils/lazy-loading-rule-map.js +0 -1
  178. package/lib/rules/vars-on-top.js +11 -11
  179. package/lib/shared/config-ops.js +2 -2
  180. package/lib/shared/runtime-info.js +8 -8
  181. package/lib/shared/traverser.js +2 -0
  182. package/lib/shared/types.js +9 -0
  183. package/lib/source-code/source-code.js +94 -17
  184. package/lib/source-code/token-store/backward-token-comment-cursor.js +5 -5
  185. package/lib/source-code/token-store/backward-token-cursor.js +5 -5
  186. package/lib/source-code/token-store/cursors.js +17 -19
  187. package/lib/source-code/token-store/decorative-cursor.js +1 -1
  188. package/lib/source-code/token-store/filter-cursor.js +2 -2
  189. package/lib/source-code/token-store/forward-token-comment-cursor.js +5 -5
  190. package/lib/source-code/token-store/forward-token-cursor.js +5 -5
  191. package/lib/source-code/token-store/index.js +86 -92
  192. package/lib/source-code/token-store/limit-cursor.js +2 -2
  193. package/lib/source-code/token-store/padded-token-cursor.js +7 -7
  194. package/lib/source-code/token-store/skip-cursor.js +2 -2
  195. package/lib/source-code/token-store/utils.js +9 -13
  196. package/package.json +9 -7
  197. package/lib/cli-engine/ignored-paths.js +0 -362
@@ -43,8 +43,7 @@ function getUseStrictDirectives(statements) {
43
43
 
44
44
  /**
45
45
  * Checks whether a given parameter is a simple parameter.
46
- *
47
- * @param {ASTNode} node - A pattern node to check.
46
+ * @param {ASTNode} node A pattern node to check.
48
47
  * @returns {boolean} `true` if the node is an Identifier node.
49
48
  */
50
49
  function isSimpleParameter(node) {
@@ -53,8 +52,7 @@ function isSimpleParameter(node) {
53
52
 
54
53
  /**
55
54
  * Checks whether a given parameter list is a simple parameter list.
56
- *
57
- * @param {ASTNode[]} params - A parameter list to check.
55
+ * @param {ASTNode[]} params A parameter list to check.
58
56
  * @returns {boolean} `true` if the every parameter is an Identifier node.
59
57
  */
60
58
  function isSimpleParameterList(params) {
@@ -38,8 +38,7 @@ module.exports = {
38
38
  /**
39
39
  * Reports if node does not conform the rule in case rule is set to
40
40
  * report missing description
41
- *
42
- * @param {ASTNode} node - A CallExpression node to check.
41
+ * @param {ASTNode} node A CallExpression node to check.
43
42
  * @returns {void}
44
43
  */
45
44
  function checkArgument(node) {
@@ -53,7 +53,7 @@ module.exports = {
53
53
 
54
54
  /**
55
55
  * Checks spacing before `}` of a given token.
56
- * @param {Token} token - A token to check. This is a Template token.
56
+ * @param {Token} token A token to check. This is a Template token.
57
57
  * @returns {void}
58
58
  */
59
59
  function checkSpacingBefore(token) {
@@ -82,7 +82,7 @@ module.exports = {
82
82
 
83
83
  /**
84
84
  * Checks spacing after `${` of a given token.
85
- * @param {Token} token - A token to check. This is a Template token.
85
+ * @param {Token} token A token to check. This is a Template token.
86
86
  * @returns {void}
87
87
  */
88
88
  function checkSpacingAfter(token) {
@@ -5,6 +5,12 @@
5
5
 
6
6
  "use strict";
7
7
 
8
+ //------------------------------------------------------------------------------
9
+ // Requirements
10
+ //------------------------------------------------------------------------------
11
+
12
+ const astUtils = require("./utils/ast-utils");
13
+
8
14
  //------------------------------------------------------------------------------
9
15
  // Helpers
10
16
  //------------------------------------------------------------------------------
@@ -40,6 +46,10 @@ module.exports = {
40
46
  enforceForSwitchCase: {
41
47
  type: "boolean",
42
48
  default: false
49
+ },
50
+ enforceForIndexOf: {
51
+ type: "boolean",
52
+ default: false
43
53
  }
44
54
  },
45
55
  additionalProperties: false
@@ -49,16 +59,18 @@ module.exports = {
49
59
  messages: {
50
60
  comparisonWithNaN: "Use the isNaN function to compare with NaN.",
51
61
  switchNaN: "'switch(NaN)' can never match a case clause. Use Number.isNaN instead of the switch.",
52
- caseNaN: "'case NaN' can never match. Use Number.isNaN before the switch."
62
+ caseNaN: "'case NaN' can never match. Use Number.isNaN before the switch.",
63
+ indexOfNaN: "Array prototype method '{{ methodName }}' cannot find NaN."
53
64
  }
54
65
  },
55
66
 
56
67
  create(context) {
57
68
 
58
69
  const enforceForSwitchCase = context.options[0] && context.options[0].enforceForSwitchCase;
70
+ const enforceForIndexOf = context.options[0] && context.options[0].enforceForIndexOf;
59
71
 
60
72
  /**
61
- * Checks the given `BinaryExpression` node.
73
+ * Checks the given `BinaryExpression` node for `foo === NaN` and other comparisons.
62
74
  * @param {ASTNode} node The node to check.
63
75
  * @returns {void}
64
76
  */
@@ -72,7 +84,7 @@ module.exports = {
72
84
  }
73
85
 
74
86
  /**
75
- * Checks the discriminant and all case clauses of the given `SwitchStatement` node.
87
+ * Checks the discriminant and all case clauses of the given `SwitchStatement` node for `switch(NaN)` and `case NaN:`
76
88
  * @param {ASTNode} node The node to check.
77
89
  * @returns {void}
78
90
  */
@@ -88,6 +100,27 @@ module.exports = {
88
100
  }
89
101
  }
90
102
 
103
+ /**
104
+ * Checks the the given `CallExpression` node for `.indexOf(NaN)` and `.lastIndexOf(NaN)`.
105
+ * @param {ASTNode} node The node to check.
106
+ * @returns {void}
107
+ */
108
+ function checkCallExpression(node) {
109
+ const callee = node.callee;
110
+
111
+ if (callee.type === "MemberExpression") {
112
+ const methodName = astUtils.getStaticPropertyName(callee);
113
+
114
+ if (
115
+ (methodName === "indexOf" || methodName === "lastIndexOf") &&
116
+ node.arguments.length === 1 &&
117
+ isNaNIdentifier(node.arguments[0])
118
+ ) {
119
+ context.report({ node, messageId: "indexOfNaN", data: { methodName } });
120
+ }
121
+ }
122
+ }
123
+
91
124
  const listeners = {
92
125
  BinaryExpression: checkBinaryExpression
93
126
  };
@@ -96,6 +129,10 @@ module.exports = {
96
129
  listeners.SwitchStatement = checkSwitchStatement;
97
130
  }
98
131
 
132
+ if (enforceForIndexOf) {
133
+ listeners.CallExpression = checkCallExpression;
134
+ }
135
+
99
136
  return listeners;
100
137
  }
101
138
  };
@@ -42,9 +42,9 @@ const OCTAL_ESCAPE_PATTERN = /^(?:[^\\]|\\[^0-7]|\\0(?![0-9]))*\\(?:[1-7]|0[0-9]
42
42
 
43
43
  /**
44
44
  * Checks reference if is non initializer and writable.
45
- * @param {Reference} reference - A reference to check.
46
- * @param {int} index - The index of the reference in the references.
47
- * @param {Reference[]} references - The array that the reference belongs to.
45
+ * @param {Reference} reference A reference to check.
46
+ * @param {int} index The index of the reference in the references.
47
+ * @param {Reference[]} references The array that the reference belongs to.
48
48
  * @returns {boolean} Success/Failure
49
49
  * @private
50
50
  */
@@ -68,8 +68,7 @@ function isModifyingReference(reference, index, references) {
68
68
 
69
69
  /**
70
70
  * Checks whether the given string starts with uppercase or not.
71
- *
72
- * @param {string} s - The string to check.
71
+ * @param {string} s The string to check.
73
72
  * @returns {boolean} `true` if the string starts with uppercase.
74
73
  */
75
74
  function startsWithUpperCase(s) {
@@ -78,7 +77,7 @@ function startsWithUpperCase(s) {
78
77
 
79
78
  /**
80
79
  * Checks whether or not a node is a constructor.
81
- * @param {ASTNode} node - A function node to check.
80
+ * @param {ASTNode} node A function node to check.
82
81
  * @returns {boolean} Wehether or not a node is a constructor.
83
82
  */
84
83
  function isES5Constructor(node) {
@@ -87,7 +86,7 @@ function isES5Constructor(node) {
87
86
 
88
87
  /**
89
88
  * Finds a function node from ancestors of a node.
90
- * @param {ASTNode} node - A start node to find.
89
+ * @param {ASTNode} node A start node to find.
91
90
  * @returns {Node|null} A found function node.
92
91
  */
93
92
  function getUpperFunction(node) {
@@ -106,8 +105,7 @@ function getUpperFunction(node) {
106
105
  * - ArrowFunctionExpression
107
106
  * - FunctionDeclaration
108
107
  * - FunctionExpression
109
- *
110
- * @param {ASTNode|null} node - A node to check.
108
+ * @param {ASTNode|null} node A node to check.
111
109
  * @returns {boolean} `true` if the node is a function node.
112
110
  */
113
111
  function isFunction(node) {
@@ -123,8 +121,7 @@ function isFunction(node) {
123
121
  * - ForOfStatement
124
122
  * - ForStatement
125
123
  * - WhileStatement
126
- *
127
- * @param {ASTNode|null} node - A node to check.
124
+ * @param {ASTNode|null} node A node to check.
128
125
  * @returns {boolean} `true` if the node is a loop node.
129
126
  */
130
127
  function isLoop(node) {
@@ -133,8 +130,7 @@ function isLoop(node) {
133
130
 
134
131
  /**
135
132
  * Checks whether the given node is in a loop or not.
136
- *
137
- * @param {ASTNode} node - The node to check.
133
+ * @param {ASTNode} node The node to check.
138
134
  * @returns {boolean} `true` if the node is in a loop.
139
135
  */
140
136
  function isInLoop(node) {
@@ -149,7 +145,7 @@ function isInLoop(node) {
149
145
 
150
146
  /**
151
147
  * Checks whether or not a node is `null` or `undefined`.
152
- * @param {ASTNode} node - A node to check.
148
+ * @param {ASTNode} node A node to check.
153
149
  * @returns {boolean} Whether or not the node is a `null` or `undefined`.
154
150
  * @public
155
151
  */
@@ -163,7 +159,7 @@ function isNullOrUndefined(node) {
163
159
 
164
160
  /**
165
161
  * Checks whether or not a node is callee.
166
- * @param {ASTNode} node - A node to check.
162
+ * @param {ASTNode} node A node to check.
167
163
  * @returns {boolean} Whether or not the node is callee.
168
164
  */
169
165
  function isCallee(node) {
@@ -172,7 +168,7 @@ function isCallee(node) {
172
168
 
173
169
  /**
174
170
  * Checks whether or not a node is `Reflect.apply`.
175
- * @param {ASTNode} node - A node to check.
171
+ * @param {ASTNode} node A node to check.
176
172
  * @returns {boolean} Whether or not the node is a `Reflect.apply`.
177
173
  */
178
174
  function isReflectApply(node) {
@@ -188,7 +184,7 @@ function isReflectApply(node) {
188
184
 
189
185
  /**
190
186
  * Checks whether or not a node is `Array.from`.
191
- * @param {ASTNode} node - A node to check.
187
+ * @param {ASTNode} node A node to check.
192
188
  * @returns {boolean} Whether or not the node is a `Array.from`.
193
189
  */
194
190
  function isArrayFromMethod(node) {
@@ -204,7 +200,7 @@ function isArrayFromMethod(node) {
204
200
 
205
201
  /**
206
202
  * Checks whether or not a node is a method which has `thisArg`.
207
- * @param {ASTNode} node - A node to check.
203
+ * @param {ASTNode} node A node to check.
208
204
  * @returns {boolean} Whether or not the node is a method which has `thisArg`.
209
205
  */
210
206
  function isMethodWhichHasThisArg(node) {
@@ -223,7 +219,7 @@ function isMethodWhichHasThisArg(node) {
223
219
 
224
220
  /**
225
221
  * Creates the negate function of the given function.
226
- * @param {Function} f - The function to negate.
222
+ * @param {Function} f The function to negate.
227
223
  * @returns {Function} Negated function.
228
224
  */
229
225
  function negate(f) {
@@ -232,8 +228,8 @@ function negate(f) {
232
228
 
233
229
  /**
234
230
  * Checks whether or not a node has a `@this` tag in its comments.
235
- * @param {ASTNode} node - A node to check.
236
- * @param {SourceCode} sourceCode - A SourceCode instance to get comments.
231
+ * @param {ASTNode} node A node to check.
232
+ * @param {SourceCode} sourceCode A SourceCode instance to get comments.
237
233
  * @returns {boolean} Whether or not the node has a `@this` tag in its comments.
238
234
  */
239
235
  function hasJSDocThisTag(node, sourceCode) {
@@ -268,8 +264,7 @@ function isParenthesised(sourceCode, node) {
268
264
 
269
265
  /**
270
266
  * Checks if the given token is an arrow token or not.
271
- *
272
- * @param {Token} token - The token to check.
267
+ * @param {Token} token The token to check.
273
268
  * @returns {boolean} `true` if the token is an arrow token.
274
269
  */
275
270
  function isArrowToken(token) {
@@ -278,8 +273,7 @@ function isArrowToken(token) {
278
273
 
279
274
  /**
280
275
  * Checks if the given token is a comma token or not.
281
- *
282
- * @param {Token} token - The token to check.
276
+ * @param {Token} token The token to check.
283
277
  * @returns {boolean} `true` if the token is a comma token.
284
278
  */
285
279
  function isCommaToken(token) {
@@ -288,8 +282,7 @@ function isCommaToken(token) {
288
282
 
289
283
  /**
290
284
  * Checks if the given token is a dot token or not.
291
- *
292
- * @param {Token} token - The token to check.
285
+ * @param {Token} token The token to check.
293
286
  * @returns {boolean} `true` if the token is a dot token.
294
287
  */
295
288
  function isDotToken(token) {
@@ -298,8 +291,7 @@ function isDotToken(token) {
298
291
 
299
292
  /**
300
293
  * Checks if the given token is a semicolon token or not.
301
- *
302
- * @param {Token} token - The token to check.
294
+ * @param {Token} token The token to check.
303
295
  * @returns {boolean} `true` if the token is a semicolon token.
304
296
  */
305
297
  function isSemicolonToken(token) {
@@ -308,8 +300,7 @@ function isSemicolonToken(token) {
308
300
 
309
301
  /**
310
302
  * Checks if the given token is a colon token or not.
311
- *
312
- * @param {Token} token - The token to check.
303
+ * @param {Token} token The token to check.
313
304
  * @returns {boolean} `true` if the token is a colon token.
314
305
  */
315
306
  function isColonToken(token) {
@@ -318,8 +309,7 @@ function isColonToken(token) {
318
309
 
319
310
  /**
320
311
  * Checks if the given token is an opening parenthesis token or not.
321
- *
322
- * @param {Token} token - The token to check.
312
+ * @param {Token} token The token to check.
323
313
  * @returns {boolean} `true` if the token is an opening parenthesis token.
324
314
  */
325
315
  function isOpeningParenToken(token) {
@@ -328,8 +318,7 @@ function isOpeningParenToken(token) {
328
318
 
329
319
  /**
330
320
  * Checks if the given token is a closing parenthesis token or not.
331
- *
332
- * @param {Token} token - The token to check.
321
+ * @param {Token} token The token to check.
333
322
  * @returns {boolean} `true` if the token is a closing parenthesis token.
334
323
  */
335
324
  function isClosingParenToken(token) {
@@ -338,8 +327,7 @@ function isClosingParenToken(token) {
338
327
 
339
328
  /**
340
329
  * Checks if the given token is an opening square bracket token or not.
341
- *
342
- * @param {Token} token - The token to check.
330
+ * @param {Token} token The token to check.
343
331
  * @returns {boolean} `true` if the token is an opening square bracket token.
344
332
  */
345
333
  function isOpeningBracketToken(token) {
@@ -348,8 +336,7 @@ function isOpeningBracketToken(token) {
348
336
 
349
337
  /**
350
338
  * Checks if the given token is a closing square bracket token or not.
351
- *
352
- * @param {Token} token - The token to check.
339
+ * @param {Token} token The token to check.
353
340
  * @returns {boolean} `true` if the token is a closing square bracket token.
354
341
  */
355
342
  function isClosingBracketToken(token) {
@@ -358,8 +345,7 @@ function isClosingBracketToken(token) {
358
345
 
359
346
  /**
360
347
  * Checks if the given token is an opening brace token or not.
361
- *
362
- * @param {Token} token - The token to check.
348
+ * @param {Token} token The token to check.
363
349
  * @returns {boolean} `true` if the token is an opening brace token.
364
350
  */
365
351
  function isOpeningBraceToken(token) {
@@ -368,8 +354,7 @@ function isOpeningBraceToken(token) {
368
354
 
369
355
  /**
370
356
  * Checks if the given token is a closing brace token or not.
371
- *
372
- * @param {Token} token - The token to check.
357
+ * @param {Token} token The token to check.
373
358
  * @returns {boolean} `true` if the token is a closing brace token.
374
359
  */
375
360
  function isClosingBraceToken(token) {
@@ -378,8 +363,7 @@ function isClosingBraceToken(token) {
378
363
 
379
364
  /**
380
365
  * Checks if the given token is a comment token or not.
381
- *
382
- * @param {Token} token - The token to check.
366
+ * @param {Token} token The token to check.
383
367
  * @returns {boolean} `true` if the token is a comment token.
384
368
  */
385
369
  function isCommentToken(token) {
@@ -388,8 +372,7 @@ function isCommentToken(token) {
388
372
 
389
373
  /**
390
374
  * Checks if the given token is a keyword token or not.
391
- *
392
- * @param {Token} token - The token to check.
375
+ * @param {Token} token The token to check.
393
376
  * @returns {boolean} `true` if the token is a keyword token.
394
377
  */
395
378
  function isKeywordToken(token) {
@@ -398,9 +381,8 @@ function isKeywordToken(token) {
398
381
 
399
382
  /**
400
383
  * Gets the `(` token of the given function node.
401
- *
402
- * @param {ASTNode} node - The function node to get.
403
- * @param {SourceCode} sourceCode - The source code object to get tokens.
384
+ * @param {ASTNode} node The function node to get.
385
+ * @param {SourceCode} sourceCode The source code object to get tokens.
404
386
  * @returns {Token} `(` token.
405
387
  */
406
388
  function getOpeningParenOfParams(node, sourceCode) {
@@ -411,9 +393,9 @@ function getOpeningParenOfParams(node, sourceCode) {
411
393
 
412
394
  /**
413
395
  * Checks whether or not the tokens of two given nodes are same.
414
- * @param {ASTNode} left - A node 1 to compare.
415
- * @param {ASTNode} right - A node 2 to compare.
416
- * @param {SourceCode} sourceCode - The ESLint source code object.
396
+ * @param {ASTNode} left A node 1 to compare.
397
+ * @param {ASTNode} right A node 2 to compare.
398
+ * @param {SourceCode} sourceCode The ESLint source code object.
417
399
  * @returns {boolean} the source code for the given node.
418
400
  */
419
401
  function equalTokens(left, right, sourceCode) {
@@ -447,8 +429,8 @@ module.exports = {
447
429
 
448
430
  /**
449
431
  * Determines whether two adjacent tokens are on the same line.
450
- * @param {Object} left - The left token object.
451
- * @param {Object} right - The right token object.
432
+ * @param {Object} left The left token object.
433
+ * @param {Object} right The right token object.
452
434
  * @returns {boolean} Whether or not the tokens are on the same line.
453
435
  * @public
454
436
  */
@@ -494,7 +476,7 @@ module.exports = {
494
476
 
495
477
  /**
496
478
  * Checks whether or not a given node is a string literal.
497
- * @param {ASTNode} node - A node to check.
479
+ * @param {ASTNode} node A node to check.
498
480
  * @returns {boolean} `true` if the node is a string literal.
499
481
  */
500
482
  isStringLiteral(node) {
@@ -514,8 +496,7 @@ module.exports = {
514
496
  * - ForStatement
515
497
  * - SwitchStatement
516
498
  * - WhileStatement
517
- *
518
- * @param {ASTNode} node - A node to check.
499
+ * @param {ASTNode} node A node to check.
519
500
  * @returns {boolean} `true` if the node is breakable.
520
501
  */
521
502
  isBreakableStatement(node) {
@@ -524,7 +505,7 @@ module.exports = {
524
505
 
525
506
  /**
526
507
  * Gets references which are non initializer and writable.
527
- * @param {Reference[]} references - An array of references.
508
+ * @param {Reference[]} references An array of references.
528
509
  * @returns {Reference[]} An array of only references which are non initializer and writable.
529
510
  * @public
530
511
  */
@@ -568,7 +549,6 @@ module.exports = {
568
549
  * consequent;
569
550
  *
570
551
  * When taking this `IfStatement`, returns `consequent;` statement.
571
- *
572
552
  * @param {ASTNode} A node to get.
573
553
  * @returns {ASTNode|null} The trailing statement's node.
574
554
  */
@@ -576,9 +556,8 @@ module.exports = {
576
556
 
577
557
  /**
578
558
  * Finds the variable by a given name in a given scope and its upper scopes.
579
- *
580
- * @param {eslint-scope.Scope} initScope - A scope to start find.
581
- * @param {string} name - A variable name to find.
559
+ * @param {eslint-scope.Scope} initScope A scope to start find.
560
+ * @param {string} name A variable name to find.
582
561
  * @returns {eslint-scope.Variable|null} A found variable or `null`.
583
562
  */
584
563
  getVariableByName(initScope, name) {
@@ -602,24 +581,31 @@ module.exports = {
602
581
  *
603
582
  * First, this checks the node:
604
583
  *
605
- * - The function name does not start with uppercase (it's a constructor).
584
+ * - The function name does not start with uppercase. It's a convention to capitalize the names
585
+ * of constructor functions. This check is not performed if `capIsConstructor` is set to `false`.
606
586
  * - The function does not have a JSDoc comment that has a @this tag.
607
587
  *
608
588
  * Next, this checks the location of the node.
609
589
  * If the location is below, this judges `this` is valid.
610
590
  *
611
591
  * - The location is not on an object literal.
612
- * - The location is not assigned to a variable which starts with an uppercase letter.
592
+ * - The location is not assigned to a variable which starts with an uppercase letter. Applies to anonymous
593
+ * functions only, as the name of the variable is considered to be the name of the function in this case.
594
+ * This check is not performed if `capIsConstructor` is set to `false`.
613
595
  * - The location is not on an ES2015 class.
614
596
  * - Its `bind`/`call`/`apply` method is not called directly.
615
597
  * - The function is not a callback of array methods (such as `.forEach()`) if `thisArg` is given.
616
- *
617
- * @param {ASTNode} node - A function node to check.
618
- * @param {SourceCode} sourceCode - A SourceCode instance to get comments.
598
+ * @param {ASTNode} node A function node to check.
599
+ * @param {SourceCode} sourceCode A SourceCode instance to get comments.
600
+ * @param {boolean} [capIsConstructor = true] `false` disables the assumption that functions which name starts
601
+ * with an uppercase or are assigned to a variable which name starts with an uppercase are constructors.
619
602
  * @returns {boolean} The function node is the default `this` binding.
620
603
  */
621
- isDefaultThisBinding(node, sourceCode) {
622
- if (isES5Constructor(node) || hasJSDocThisTag(node, sourceCode)) {
604
+ isDefaultThisBinding(node, sourceCode, { capIsConstructor = true } = {}) {
605
+ if (
606
+ (capIsConstructor && isES5Constructor(node)) ||
607
+ hasJSDocThisTag(node, sourceCode)
608
+ ) {
623
609
  return false;
624
610
  }
625
611
  const isAnonymous = node.id === null;
@@ -693,6 +679,7 @@ module.exports = {
693
679
  return false;
694
680
  }
695
681
  if (
682
+ capIsConstructor &&
696
683
  isAnonymous &&
697
684
  parent.left.type === "Identifier" &&
698
685
  startsWithUpperCase(parent.left.name)
@@ -707,6 +694,7 @@ module.exports = {
707
694
  */
708
695
  case "VariableDeclarator":
709
696
  return !(
697
+ capIsConstructor &&
710
698
  isAnonymous &&
711
699
  parent.init === currentNode &&
712
700
  parent.id.type === "Identifier" &&
@@ -861,8 +849,7 @@ module.exports = {
861
849
 
862
850
  /**
863
851
  * Checks whether the given node is an empty block node or not.
864
- *
865
- * @param {ASTNode|null} node - The node to check.
852
+ * @param {ASTNode|null} node The node to check.
866
853
  * @returns {boolean} `true` if the node is an empty block.
867
854
  */
868
855
  isEmptyBlock(node) {
@@ -871,8 +858,7 @@ module.exports = {
871
858
 
872
859
  /**
873
860
  * Checks whether the given node is an empty function node or not.
874
- *
875
- * @param {ASTNode|null} node - The node to check.
861
+ * @param {ASTNode|null} node The node to check.
876
862
  * @returns {boolean} `true` if the node is an empty function.
877
863
  */
878
864
  isEmptyFunction(node) {
@@ -906,8 +892,7 @@ module.exports = {
906
892
  * let a = {["a" + "b"]: 1} // => null
907
893
  * let a = {[tag`b`]: 1} // => null
908
894
  * let a = {[`${b}`]: 1} // => null
909
- *
910
- * @param {ASTNode} node - The node to get.
895
+ * @param {ASTNode} node The node to get.
911
896
  * @returns {string|null} The property name if static. Otherwise, null.
912
897
  */
913
898
  getStaticPropertyName(node) {
@@ -950,7 +935,7 @@ module.exports = {
950
935
 
951
936
  /**
952
937
  * Get directives from directive prologue of a Program or Function node.
953
- * @param {ASTNode} node - The node to check.
938
+ * @param {ASTNode} node The node to check.
954
939
  * @returns {ASTNode[]} The directives found in the directive prologue.
955
940
  */
956
941
  getDirectivePrologue(node) {
@@ -989,7 +974,7 @@ module.exports = {
989
974
  /**
990
975
  * Determines whether this node is a decimal integer literal. If a node is a decimal integer literal, a dot added
991
976
  * after the node will be parsed as a decimal point, rather than a property-access dot.
992
- * @param {ASTNode} node - The node to check.
977
+ * @param {ASTNode} node The node to check.
993
978
  * @returns {boolean} `true` if this node is a decimal integer.
994
979
  * @example
995
980
  *
@@ -1011,7 +996,7 @@ module.exports = {
1011
996
  /**
1012
997
  * Determines whether this token is a decimal integer numeric token.
1013
998
  * This is similar to isDecimalInteger(), but for tokens.
1014
- * @param {Token} token - The token to check.
999
+ * @param {Token} token The token to check.
1015
1000
  * @returns {boolean} `true` if this token is a decimal integer.
1016
1001
  */
1017
1002
  isDecimalIntegerNumericToken(token) {
@@ -1063,8 +1048,7 @@ module.exports = {
1063
1048
  * - `class A { static async foo() {} }` .... `static async method 'foo'`
1064
1049
  * - `class A { static get foo() {} }` ...... `static getter 'foo'`
1065
1050
  * - `class A { static set foo(a) {} }` ..... `static setter 'foo'`
1066
- *
1067
- * @param {ASTNode} node - The function node to get.
1051
+ * @param {ASTNode} node The function node to get.
1068
1052
  * @returns {string} The name and kind of the function node.
1069
1053
  */
1070
1054
  getFunctionNameWithKind(node) {
@@ -1198,9 +1182,8 @@ module.exports = {
1198
1182
  * ^^^^^^^^^^^^^^
1199
1183
  * - `class A { static set foo(a) {} }`
1200
1184
  * ^^^^^^^^^^^^^^
1201
- *
1202
- * @param {ASTNode} node - The function node to get.
1203
- * @param {SourceCode} sourceCode - The source code object to get tokens.
1185
+ * @param {ASTNode} node The function node to get.
1186
+ * @param {SourceCode} sourceCode The source code object to get tokens.
1204
1187
  * @returns {string} The location of the function node for reporting.
1205
1188
  */
1206
1189
  getFunctionHeadLoc(node, sourceCode) {
@@ -1227,6 +1210,23 @@ module.exports = {
1227
1210
  };
1228
1211
  },
1229
1212
 
1213
+ /**
1214
+ * Gets next location when the result is not out of bound, otherwise returns null.
1215
+ * @param {SourceCode} sourceCode The sourceCode
1216
+ * @param {{line: number, column: number}} location The location
1217
+ * @returns {{line: number, column: number} | null} Next location
1218
+ */
1219
+ getNextLocation(sourceCode, location) {
1220
+ const index = sourceCode.getIndexFromLoc(location);
1221
+
1222
+ // Avoid out of bound location
1223
+ if (index + 1 > sourceCode.text.length) {
1224
+ return null;
1225
+ }
1226
+
1227
+ return sourceCode.getLocFromIndex(index + 1);
1228
+ },
1229
+
1230
1230
  /**
1231
1231
  * Gets the parenthesized text of a node. This is similar to sourceCode.getText(node), but it also includes any parentheses
1232
1232
  * surrounding the node.
@@ -1384,7 +1384,6 @@ module.exports = {
1384
1384
  * "\00", "\01" ... "\09"
1385
1385
  *
1386
1386
  * "\0", when not followed by a digit, is not an octal escape sequence.
1387
- *
1388
1387
  * @param {string} rawString A string in its raw representation.
1389
1388
  * @returns {boolean} `true` if the string contains at least one octal escape sequence.
1390
1389
  */
@@ -23,7 +23,6 @@ class FixTracker {
23
23
 
24
24
  /**
25
25
  * Create a new FixTracker.
26
- *
27
26
  * @param {ruleFixer} fixer A ruleFixer instance.
28
27
  * @param {SourceCode} sourceCode A SourceCode object for the current code.
29
28
  */
@@ -36,7 +35,6 @@ class FixTracker {
36
35
  /**
37
36
  * Mark the given range as "retained", meaning that other fixes may not
38
37
  * may not modify this region in the same pass.
39
- *
40
38
  * @param {int[]} range The range to retain.
41
39
  * @returns {FixTracker} The same RuleFixer, for chained calls.
42
40
  */
@@ -50,7 +48,6 @@ class FixTracker {
50
48
  * mark it as retained, meaning that other fixes may not modify it in this
51
49
  * pass. This is useful for avoiding conflicts in fixes that modify control
52
50
  * flow.
53
- *
54
51
  * @param {ASTNode} node The node to use as a starting point.
55
52
  * @returns {FixTracker} The same RuleFixer, for chained calls.
56
53
  */
@@ -65,7 +62,6 @@ class FixTracker {
65
62
  * range as retained, meaning that other fixes may not modify it in this
66
63
  * pass. This is useful for avoiding conflicts in fixes that make a small
67
64
  * change to the code where the AST should not be changed.
68
- *
69
65
  * @param {ASTNode|Token} nodeOrToken The node or token to use as a starting
70
66
  * point. The token to the left and right are use in the range.
71
67
  * @returns {FixTracker} The same RuleFixer, for chained calls.
@@ -80,7 +76,6 @@ class FixTracker {
80
76
  /**
81
77
  * Create a fix command that replaces the given range with the given text,
82
78
  * accounting for any retained ranges.
83
- *
84
79
  * @param {int[]} range The range to remove in the fix.
85
80
  * @param {string} text The text to insert in place of the range.
86
81
  * @returns {Object} The fix command.
@@ -108,7 +103,6 @@ class FixTracker {
108
103
  /**
109
104
  * Create a fix command that removes the given node or token, accounting for
110
105
  * any retained ranges.
111
- *
112
106
  * @param {ASTNode|Token} nodeOrToken The node or token to remove.
113
107
  * @returns {Object} The fix command.
114
108
  */