eslint 6.3.0 → 6.6.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 (189) hide show
  1. package/CHANGELOG.md +126 -0
  2. package/README.md +11 -10
  3. package/bin/eslint.js +38 -12
  4. package/lib/cli-engine/cascading-config-array-factory.js +2 -1
  5. package/lib/cli-engine/cli-engine.js +11 -11
  6. package/lib/cli-engine/config-array/config-array.js +0 -4
  7. package/lib/cli-engine/config-array/config-dependency.js +2 -0
  8. package/lib/cli-engine/config-array/override-tester.js +4 -2
  9. package/lib/cli-engine/config-array-factory.js +7 -1
  10. package/lib/cli-engine/file-enumerator.js +5 -3
  11. package/lib/cli-engine/formatters/html.js +1 -0
  12. package/lib/cli-engine/ignored-paths.js +4 -3
  13. package/lib/cli-engine/lint-result-cache.js +0 -1
  14. package/lib/cli.js +13 -12
  15. package/lib/init/autoconfig.js +1 -11
  16. package/lib/init/config-file.js +0 -1
  17. package/lib/init/config-initializer.js +0 -1
  18. package/lib/init/config-rule.js +3 -7
  19. package/lib/init/npm-utils.js +1 -6
  20. package/lib/linter/code-path-analysis/code-path-analyzer.js +24 -38
  21. package/lib/linter/code-path-analysis/code-path-segment.js +17 -25
  22. package/lib/linter/code-path-analysis/code-path-state.js +40 -81
  23. package/lib/linter/code-path-analysis/code-path.js +10 -11
  24. package/lib/linter/code-path-analysis/debug-helpers.js +9 -13
  25. package/lib/linter/code-path-analysis/fork-context.js +23 -34
  26. package/lib/linter/code-path-analysis/id-generator.js +2 -2
  27. package/lib/linter/linter.js +121 -96
  28. package/lib/linter/node-event-generator.js +3 -2
  29. package/lib/options.js +6 -0
  30. package/lib/rule-tester/rule-tester.js +7 -10
  31. package/lib/rules/accessor-pairs.js +59 -19
  32. package/lib/rules/array-bracket-newline.js +12 -15
  33. package/lib/rules/array-bracket-spacing.js +12 -12
  34. package/lib/rules/array-callback-return.js +6 -11
  35. package/lib/rules/array-element-newline.js +5 -8
  36. package/lib/rules/arrow-parens.js +0 -1
  37. package/lib/rules/block-scoped-var.js +3 -3
  38. package/lib/rules/block-spacing.js +4 -4
  39. package/lib/rules/capitalized-comments.js +2 -9
  40. package/lib/rules/class-methods-use-this.js +3 -3
  41. package/lib/rules/comma-dangle.js +15 -23
  42. package/lib/rules/comma-spacing.js +1 -1
  43. package/lib/rules/computed-property-spacing.js +28 -11
  44. package/lib/rules/consistent-return.js +4 -5
  45. package/lib/rules/consistent-this.js +5 -5
  46. package/lib/rules/constructor-super.js +14 -16
  47. package/lib/rules/curly.js +3 -5
  48. package/lib/rules/default-param-last.js +62 -0
  49. package/lib/rules/dot-location.js +11 -12
  50. package/lib/rules/eqeqeq.js +7 -19
  51. package/lib/rules/func-names.js +6 -6
  52. package/lib/rules/function-call-argument-newline.js +5 -5
  53. package/lib/rules/generator-star-spacing.js +4 -9
  54. package/lib/rules/getter-return.js +4 -7
  55. package/lib/rules/indent-legacy.js +1 -1
  56. package/lib/rules/indent.js +46 -8
  57. package/lib/rules/index.js +3 -0
  58. package/lib/rules/init-declarations.js +2 -2
  59. package/lib/rules/jsx-quotes.js +1 -1
  60. package/lib/rules/keyword-spacing.js +32 -56
  61. package/lib/rules/lines-around-directive.js +1 -1
  62. package/lib/rules/max-len.js +0 -5
  63. package/lib/rules/max-statements-per-line.js +3 -7
  64. package/lib/rules/multiline-ternary.js +3 -3
  65. package/lib/rules/new-parens.js +5 -1
  66. package/lib/rules/newline-after-var.js +6 -7
  67. package/lib/rules/newline-before-return.js +8 -9
  68. package/lib/rules/newline-per-chained-call.js +2 -4
  69. package/lib/rules/no-class-assign.js +2 -2
  70. package/lib/rules/no-compare-neg-zero.js +1 -2
  71. package/lib/rules/no-confusing-arrow.js +2 -2
  72. package/lib/rules/no-console.js +4 -8
  73. package/lib/rules/no-const-assign.js +1 -1
  74. package/lib/rules/no-dupe-args.js +1 -1
  75. package/lib/rules/no-dupe-class-members.js +3 -4
  76. package/lib/rules/no-dupe-keys.js +6 -5
  77. package/lib/rules/no-duplicate-imports.js +14 -18
  78. package/lib/rules/no-else-return.js +0 -8
  79. package/lib/rules/no-empty-function.js +2 -4
  80. package/lib/rules/no-eval.js +10 -18
  81. package/lib/rules/no-ex-assign.js +1 -1
  82. package/lib/rules/no-extra-bind.js +12 -13
  83. package/lib/rules/no-extra-boolean-cast.js +1 -3
  84. package/lib/rules/no-extra-label.js +13 -10
  85. package/lib/rules/no-extra-parens.js +32 -17
  86. package/lib/rules/no-extra-semi.js +5 -6
  87. package/lib/rules/no-fallthrough.js +6 -6
  88. package/lib/rules/no-func-assign.js +3 -3
  89. package/lib/rules/no-global-assign.js +4 -4
  90. package/lib/rules/no-implicit-coercion.js +10 -10
  91. package/lib/rules/no-implied-eval.js +0 -1
  92. package/lib/rules/no-import-assign.js +238 -0
  93. package/lib/rules/no-invalid-this.js +1 -3
  94. package/lib/rules/no-labels.js +3 -6
  95. package/lib/rules/no-lone-blocks.js +7 -2
  96. package/lib/rules/no-loop-func.js +6 -11
  97. package/lib/rules/no-magic-numbers.js +6 -6
  98. package/lib/rules/no-misleading-character-class.js +14 -7
  99. package/lib/rules/no-mixed-operators.js +13 -22
  100. package/lib/rules/no-mixed-requires.js +0 -1
  101. package/lib/rules/no-multi-spaces.js +1 -1
  102. package/lib/rules/no-native-reassign.js +4 -4
  103. package/lib/rules/no-obj-calls.js +29 -9
  104. package/lib/rules/no-octal-escape.js +14 -8
  105. package/lib/rules/no-param-reassign.js +28 -7
  106. package/lib/rules/no-redeclare.js +1 -1
  107. package/lib/rules/no-regex-spaces.js +105 -45
  108. package/lib/rules/no-restricted-imports.js +11 -11
  109. package/lib/rules/no-self-assign.js +18 -18
  110. package/lib/rules/no-sequences.js +5 -5
  111. package/lib/rules/no-shadow.js +1 -4
  112. package/lib/rules/no-tabs.js +8 -2
  113. package/lib/rules/no-this-before-super.js +12 -13
  114. package/lib/rules/no-trailing-spaces.js +19 -7
  115. package/lib/rules/no-undef-init.js +7 -1
  116. package/lib/rules/no-unmodified-loop-condition.js +16 -29
  117. package/lib/rules/no-unneeded-ternary.js +3 -3
  118. package/lib/rules/no-unreachable.js +7 -7
  119. package/lib/rules/no-unsafe-finally.js +4 -7
  120. package/lib/rules/no-unsafe-negation.js +34 -19
  121. package/lib/rules/no-unused-expressions.js +11 -7
  122. package/lib/rules/no-unused-labels.js +3 -6
  123. package/lib/rules/no-unused-vars.js +22 -29
  124. package/lib/rules/no-use-before-define.js +10 -15
  125. package/lib/rules/no-useless-call.js +4 -4
  126. package/lib/rules/no-useless-concat.js +4 -4
  127. package/lib/rules/no-useless-constructor.js +14 -22
  128. package/lib/rules/no-useless-escape.js +3 -5
  129. package/lib/rules/no-useless-rename.js +32 -20
  130. package/lib/rules/no-useless-return.js +11 -17
  131. package/lib/rules/no-var.js +12 -25
  132. package/lib/rules/no-warning-comments.js +0 -1
  133. package/lib/rules/no-whitespace-before-property.js +3 -3
  134. package/lib/rules/object-curly-newline.js +7 -10
  135. package/lib/rules/object-curly-spacing.js +14 -15
  136. package/lib/rules/object-shorthand.js +36 -10
  137. package/lib/rules/one-var-declaration-per-line.js +2 -2
  138. package/lib/rules/operator-assignment.js +22 -1
  139. package/lib/rules/padded-blocks.js +1 -1
  140. package/lib/rules/padding-line-between-statements.js +0 -16
  141. package/lib/rules/prefer-arrow-callback.js +6 -6
  142. package/lib/rules/prefer-const.js +13 -21
  143. package/lib/rules/prefer-destructuring.js +1 -7
  144. package/lib/rules/prefer-named-capture-group.js +3 -16
  145. package/lib/rules/prefer-numeric-literals.js +35 -3
  146. package/lib/rules/prefer-object-spread.js +7 -7
  147. package/lib/rules/prefer-regex-literals.js +125 -0
  148. package/lib/rules/prefer-rest-params.js +3 -6
  149. package/lib/rules/prefer-spread.js +4 -4
  150. package/lib/rules/prefer-template.js +5 -6
  151. package/lib/rules/quote-props.js +1 -1
  152. package/lib/rules/quotes.js +11 -6
  153. package/lib/rules/radix.js +5 -10
  154. package/lib/rules/require-await.js +2 -5
  155. package/lib/rules/require-yield.js +2 -2
  156. package/lib/rules/rest-spread-spacing.js +1 -1
  157. package/lib/rules/sort-imports.js +3 -4
  158. package/lib/rules/sort-keys.js +1 -3
  159. package/lib/rules/space-before-blocks.js +1 -2
  160. package/lib/rules/space-before-function-paren.js +12 -1
  161. package/lib/rules/space-in-parens.js +81 -75
  162. package/lib/rules/space-infix-ops.js +5 -5
  163. package/lib/rules/spaced-comment.js +15 -18
  164. package/lib/rules/strict.js +2 -4
  165. package/lib/rules/symbol-description.js +1 -2
  166. package/lib/rules/template-curly-spacing.js +2 -2
  167. package/lib/rules/use-isnan.js +104 -6
  168. package/lib/rules/utils/ast-utils.js +53 -81
  169. package/lib/rules/utils/fix-tracker.js +0 -6
  170. package/lib/rules/utils/lazy-loading-rule-map.js +0 -1
  171. package/lib/rules/vars-on-top.js +11 -11
  172. package/lib/shared/config-ops.js +2 -2
  173. package/lib/shared/logging.js +2 -0
  174. package/lib/shared/runtime-info.js +163 -0
  175. package/lib/shared/traverser.js +2 -0
  176. package/lib/source-code/source-code.js +11 -12
  177. package/lib/source-code/token-store/backward-token-comment-cursor.js +5 -5
  178. package/lib/source-code/token-store/backward-token-cursor.js +5 -5
  179. package/lib/source-code/token-store/cursors.js +17 -19
  180. package/lib/source-code/token-store/decorative-cursor.js +1 -1
  181. package/lib/source-code/token-store/filter-cursor.js +2 -2
  182. package/lib/source-code/token-store/forward-token-comment-cursor.js +5 -5
  183. package/lib/source-code/token-store/forward-token-cursor.js +5 -5
  184. package/lib/source-code/token-store/index.js +86 -92
  185. package/lib/source-code/token-store/limit-cursor.js +2 -2
  186. package/lib/source-code/token-store/padded-token-cursor.js +7 -7
  187. package/lib/source-code/token-store/skip-cursor.js +2 -2
  188. package/lib/source-code/token-store/utils.js +9 -13
  189. package/package.json +8 -5
@@ -59,7 +59,7 @@ module.exports = {
59
59
  * Determines whether an option is set, relative to the spacing option.
60
60
  * If spaced is "always", then check whether option is set to false.
61
61
  * If spaced is "never", then check whether option is set to true.
62
- * @param {Object} option - The option to exclude.
62
+ * @param {Object} option The option to exclude.
63
63
  * @returns {boolean} Whether or not the property is excluded.
64
64
  */
65
65
  function isOptionSet(option) {
@@ -79,8 +79,8 @@ module.exports = {
79
79
 
80
80
  /**
81
81
  * Reports that there shouldn't be a space after the first token
82
- * @param {ASTNode} node - The node to report in the event of an error.
83
- * @param {Token} token - The token to use for the report.
82
+ * @param {ASTNode} node The node to report in the event of an error.
83
+ * @param {Token} token The token to use for the report.
84
84
  * @returns {void}
85
85
  */
86
86
  function reportNoBeginningSpace(node, token) {
@@ -101,8 +101,8 @@ module.exports = {
101
101
 
102
102
  /**
103
103
  * Reports that there shouldn't be a space before the last 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 reportNoEndingSpace(node, token) {
@@ -123,8 +123,8 @@ module.exports = {
123
123
 
124
124
  /**
125
125
  * Reports that there should be a space after the first token
126
- * @param {ASTNode} node - The node to report in the event of an error.
127
- * @param {Token} token - The token to use for the report.
126
+ * @param {ASTNode} node The node to report in the event of an error.
127
+ * @param {Token} token The token to use for the report.
128
128
  * @returns {void}
129
129
  */
130
130
  function reportRequiredBeginningSpace(node, token) {
@@ -143,8 +143,8 @@ module.exports = {
143
143
 
144
144
  /**
145
145
  * Reports that there should be a space before the last token
146
- * @param {ASTNode} node - The node to report in the event of an error.
147
- * @param {Token} token - The token to use for the report.
146
+ * @param {ASTNode} node The node to report in the event of an error.
147
+ * @param {Token} token The token to use for the report.
148
148
  * @returns {void}
149
149
  */
150
150
  function reportRequiredEndingSpace(node, token) {
@@ -163,7 +163,7 @@ module.exports = {
163
163
 
164
164
  /**
165
165
  * Determines if a node is an object type
166
- * @param {ASTNode} node - The node to check.
166
+ * @param {ASTNode} node The node to check.
167
167
  * @returns {boolean} Whether or not the node is an object type.
168
168
  */
169
169
  function isObjectType(node) {
@@ -172,7 +172,7 @@ module.exports = {
172
172
 
173
173
  /**
174
174
  * Determines if a node is an array type
175
- * @param {ASTNode} node - The node to check.
175
+ * @param {ASTNode} node The node to check.
176
176
  * @returns {boolean} Whether or not the node is an array type.
177
177
  */
178
178
  function isArrayType(node) {
@@ -181,7 +181,7 @@ module.exports = {
181
181
 
182
182
  /**
183
183
  * Validates the spacing around array brackets
184
- * @param {ASTNode} node - The node we're checking for spacing
184
+ * @param {ASTNode} node The node we're checking for spacing
185
185
  * @returns {void}
186
186
  */
187
187
  function validateArraySpacing(node) {
@@ -22,8 +22,7 @@ const TARGET_METHODS = /^(?:every|filter|find(?:Index)?|map|reduce(?:Right)?|som
22
22
 
23
23
  /**
24
24
  * Checks a given code path segment is reachable.
25
- *
26
- * @param {CodePathSegment} segment - A segment to check.
25
+ * @param {CodePathSegment} segment A segment to check.
27
26
  * @returns {boolean} `true` if the segment is reachable.
28
27
  */
29
28
  function isReachable(segment) {
@@ -35,9 +34,8 @@ function isReachable(segment) {
35
34
  *
36
35
  * - FunctionExpression -> the function name or `function` keyword.
37
36
  * - ArrowFunctionExpression -> `=>` token.
38
- *
39
- * @param {ASTNode} node - A function node to get.
40
- * @param {SourceCode} sourceCode - A source code to get tokens.
37
+ * @param {ASTNode} node A function node to get.
38
+ * @param {SourceCode} sourceCode A source code to get tokens.
41
39
  * @returns {ASTNode|Token} The node or the token of a location.
42
40
  */
43
41
  function getLocation(node, sourceCode) {
@@ -50,8 +48,7 @@ function getLocation(node, sourceCode) {
50
48
  /**
51
49
  * Checks a given node is a MemberExpression node which has the specified name's
52
50
  * property.
53
- *
54
- * @param {ASTNode} node - A node to check.
51
+ * @param {ASTNode} node A node to check.
55
52
  * @returns {boolean} `true` if the node is a MemberExpression node which has
56
53
  * the specified name's property
57
54
  */
@@ -65,8 +62,7 @@ function isTargetMethod(node) {
65
62
  /**
66
63
  * Checks whether or not a given node is a function expression which is the
67
64
  * callback of an array method.
68
- *
69
- * @param {ASTNode} node - A node to check. This is one of
65
+ * @param {ASTNode} node A node to check. This is one of
70
66
  * FunctionExpression or ArrowFunctionExpression.
71
67
  * @returns {boolean} `true` if the node is the callback of an array method.
72
68
  */
@@ -188,8 +184,7 @@ module.exports = {
188
184
  *
189
185
  * If the last code path segment is reachable, there are paths which are not
190
186
  * returned or thrown.
191
- *
192
- * @param {ASTNode} node - A node to check.
187
+ * @param {ASTNode} node A node to check.
193
188
  * @returns {void}
194
189
  */
195
190
  function checkLastSegment(node) {
@@ -62,8 +62,7 @@ module.exports = {
62
62
 
63
63
  /**
64
64
  * Normalizes a given option value.
65
- *
66
- * @param {string|Object|undefined} providedOption - An option value to parse.
65
+ * @param {string|Object|undefined} providedOption An option value to parse.
67
66
  * @returns {{multiline: boolean, minItems: number}} Normalized option object.
68
67
  */
69
68
  function normalizeOptionValue(providedOption) {
@@ -90,8 +89,7 @@ module.exports = {
90
89
 
91
90
  /**
92
91
  * Normalizes a given option value.
93
- *
94
- * @param {string|Object|undefined} options - An option value to parse.
92
+ * @param {string|Object|undefined} options An option value to parse.
95
93
  * @returns {{ArrayExpression: {multiline: boolean, minItems: number}, ArrayPattern: {multiline: boolean, minItems: number}}} Normalized option object.
96
94
  */
97
95
  function normalizeOptions(options) {
@@ -102,7 +100,7 @@ module.exports = {
102
100
 
103
101
  /**
104
102
  * Reports that there shouldn't be a line break after the first token
105
- * @param {Token} token - The token to use for the report.
103
+ * @param {Token} token The token to use for the report.
106
104
  * @returns {void}
107
105
  */
108
106
  function reportNoLineBreak(token) {
@@ -151,7 +149,7 @@ module.exports = {
151
149
 
152
150
  /**
153
151
  * Reports that there should be a line break after the first token
154
- * @param {Token} token - The token to use for the report.
152
+ * @param {Token} token The token to use for the report.
155
153
  * @returns {void}
156
154
  */
157
155
  function reportRequiredLineBreak(token) {
@@ -171,8 +169,7 @@ module.exports = {
171
169
 
172
170
  /**
173
171
  * Reports a given node if it violated this rule.
174
- *
175
- * @param {ASTNode} node - A node to check. This is an ObjectExpression node or an ObjectPattern node.
172
+ * @param {ASTNode} node A node to check. This is an ObjectExpression node or an ObjectPattern node.
176
173
  * @returns {void}
177
174
  */
178
175
  function check(node) {
@@ -16,7 +16,6 @@ const astUtils = require("./utils/ast-utils");
16
16
 
17
17
  /**
18
18
  * Get location should be reported by AST node.
19
- *
20
19
  * @param {ASTNode} node AST Node.
21
20
  * @returns {Location} Location information.
22
21
  */
@@ -31,7 +31,7 @@ module.exports = {
31
31
 
32
32
  /**
33
33
  * Makes a block scope.
34
- * @param {ASTNode} node - A node of a scope.
34
+ * @param {ASTNode} node A node of a scope.
35
35
  * @returns {void}
36
36
  */
37
37
  function enterScope(node) {
@@ -48,7 +48,7 @@ module.exports = {
48
48
 
49
49
  /**
50
50
  * Reports a given reference.
51
- * @param {eslint-scope.Reference} reference - A reference to report.
51
+ * @param {eslint-scope.Reference} reference A reference to report.
52
52
  * @returns {void}
53
53
  */
54
54
  function report(reference) {
@@ -59,7 +59,7 @@ module.exports = {
59
59
 
60
60
  /**
61
61
  * Finds and reports references which are outside of valid scopes.
62
- * @param {ASTNode} node - A node to get variables.
62
+ * @param {ASTNode} node A node to get variables.
63
63
  * @returns {void}
64
64
  */
65
65
  function checkForVariables(node) {
@@ -41,7 +41,7 @@ module.exports = {
41
41
 
42
42
  /**
43
43
  * Gets the open brace token from a given node.
44
- * @param {ASTNode} node - A BlockStatement/SwitchStatement node to get.
44
+ * @param {ASTNode} node A BlockStatement/SwitchStatement node to get.
45
45
  * @returns {Token} The token of the open brace.
46
46
  */
47
47
  function getOpenBrace(node) {
@@ -58,8 +58,8 @@ module.exports = {
58
58
  * Checks whether or not:
59
59
  * - given tokens are on same line.
60
60
  * - there is/isn't a space between given tokens.
61
- * @param {Token} left - A token to check.
62
- * @param {Token} right - The token which is next to `left`.
61
+ * @param {Token} left A token to check.
62
+ * @param {Token} right The token which is next to `left`.
63
63
  * @returns {boolean}
64
64
  * When the option is `"always"`, `true` if there are one or more spaces between given tokens.
65
65
  * When the option is `"never"`, `true` if there are not any spaces between given tokens.
@@ -74,7 +74,7 @@ module.exports = {
74
74
 
75
75
  /**
76
76
  * Reports invalid spacing style inside braces.
77
- * @param {ASTNode} node - A BlockStatement/SwitchStatement node to get.
77
+ * @param {ASTNode} node A BlockStatement/SwitchStatement node to get.
78
78
  * @returns {void}
79
79
  */
80
80
  function checkSpacingInsideBraces(node) {
@@ -54,23 +54,21 @@ const DEFAULTS = {
54
54
  * set is returned. Options specified in overrides will take priority
55
55
  * over options specified in the main options object, which will in
56
56
  * turn take priority over the rule's defaults.
57
- *
58
57
  * @param {Object|string} rawOptions The user-provided options.
59
58
  * @param {string} which Either "line" or "block".
60
59
  * @returns {Object} The normalized options.
61
60
  */
62
- function getNormalizedOptions(rawOptions = {}, which) {
61
+ function getNormalizedOptions(rawOptions, which) {
63
62
  return Object.assign({}, DEFAULTS, rawOptions[which] || rawOptions);
64
63
  }
65
64
 
66
65
  /**
67
66
  * Get normalized options for block and line comments.
68
- *
69
67
  * @param {Object|string} rawOptions The user-provided options.
70
68
  * @returns {Object} An object with "Line" and "Block" keys and corresponding
71
69
  * normalized options objects.
72
70
  */
73
- function getAllNormalizedOptions(rawOptions) {
71
+ function getAllNormalizedOptions(rawOptions = {}) {
74
72
  return {
75
73
  Line: getNormalizedOptions(rawOptions, "line"),
76
74
  Block: getNormalizedOptions(rawOptions, "block")
@@ -82,7 +80,6 @@ function getAllNormalizedOptions(rawOptions) {
82
80
  * options.
83
81
  *
84
82
  * This is done in order to avoid invoking the RegExp constructor repeatedly.
85
- *
86
83
  * @param {Object} normalizedOptions The normalized rule options.
87
84
  * @returns {void}
88
85
  */
@@ -162,7 +159,6 @@ module.exports = {
162
159
  * Also, it follows from this definition that only block comments can
163
160
  * be considered as possibly inline. This is because line comments
164
161
  * would consume any following tokens on the same line as the comment.
165
- *
166
162
  * @param {ASTNode} comment The comment node to check.
167
163
  * @returns {boolean} True if the comment is an inline comment, false
168
164
  * otherwise.
@@ -181,7 +177,6 @@ module.exports = {
181
177
 
182
178
  /**
183
179
  * Determine if a comment follows another comment.
184
- *
185
180
  * @param {ASTNode} comment The comment to check.
186
181
  * @returns {boolean} True if the comment follows a valid comment.
187
182
  */
@@ -196,7 +191,6 @@ module.exports = {
196
191
 
197
192
  /**
198
193
  * Check a comment to determine if it is valid for this rule.
199
- *
200
194
  * @param {ASTNode} comment The comment node to process.
201
195
  * @param {Object} options The options for checking this comment.
202
196
  * @returns {boolean} True if the comment is valid, false otherwise.
@@ -261,7 +255,6 @@ module.exports = {
261
255
 
262
256
  /**
263
257
  * Process a comment to determine if it needs to be reported.
264
- *
265
258
  * @param {ASTNode} comment The comment node to process.
266
259
  * @returns {void}
267
260
  */
@@ -61,7 +61,7 @@ module.exports = {
61
61
 
62
62
  /**
63
63
  * Check if the node is an instance method
64
- * @param {ASTNode} node - node to check
64
+ * @param {ASTNode} node node to check
65
65
  * @returns {boolean} True if its an instance method
66
66
  * @private
67
67
  */
@@ -71,7 +71,7 @@ module.exports = {
71
71
 
72
72
  /**
73
73
  * Check if the node is an instance method not excluded by config
74
- * @param {ASTNode} node - node to check
74
+ * @param {ASTNode} node node to check
75
75
  * @returns {boolean} True if it is an instance method, and not excluded by config
76
76
  * @private
77
77
  */
@@ -84,7 +84,7 @@ module.exports = {
84
84
  * Checks if we are leaving a function that is a method, and reports if 'this' has not been used.
85
85
  * Static methods and the constructor are exempt.
86
86
  * Then pops the context off the stack.
87
- * @param {ASTNode} node - A function node that was entered.
87
+ * @param {ASTNode} node A function node that was entered.
88
88
  * @returns {void}
89
89
  * @private
90
90
  */
@@ -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}
@@ -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}
@@ -286,8 +280,7 @@ module.exports = {
286
280
  * If a given node is multiline, reports the last element of a given node
287
281
  * when it does not have a trailing comma.
288
282
  * Otherwise, reports a trailing comma if it exists.
289
- *
290
- * @param {ASTNode} node - A node to check. Its type is one of
283
+ * @param {ASTNode} node A node to check. Its type is one of
291
284
  * ObjectExpression, ObjectPattern, ArrayExpression, ArrayPattern,
292
285
  * ImportDeclaration, and ExportNamedDeclaration.
293
286
  * @returns {void}
@@ -304,8 +297,7 @@ module.exports = {
304
297
  * Only if a given node is not multiline, reports the last element of a given node
305
298
  * when it does not have a trailing comma.
306
299
  * Otherwise, reports a trailing comma if it exists.
307
- *
308
- * @param {ASTNode} node - A node to check. Its type is one of
300
+ * @param {ASTNode} node A node to check. Its type is one of
309
301
  * ObjectExpression, ObjectPattern, ArrayExpression, ArrayPattern,
310
302
  * ImportDeclaration, and ExportNamedDeclaration.
311
303
  * @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.
@@ -26,6 +26,16 @@ module.exports = {
26
26
  schema: [
27
27
  {
28
28
  enum: ["always", "never"]
29
+ },
30
+ {
31
+ type: "object",
32
+ properties: {
33
+ enforceForClassMembers: {
34
+ type: "boolean",
35
+ default: false
36
+ }
37
+ },
38
+ additionalProperties: false
29
39
  }
30
40
  ],
31
41
 
@@ -41,6 +51,7 @@ module.exports = {
41
51
  create(context) {
42
52
  const sourceCode = context.getSourceCode();
43
53
  const propertyNameMustBeSpaced = context.options[0] === "always"; // default is "never"
54
+ const enforceForClassMembers = context.options[1] && context.options[1].enforceForClassMembers;
44
55
 
45
56
  //--------------------------------------------------------------------------
46
57
  // Helpers
@@ -48,9 +59,9 @@ module.exports = {
48
59
 
49
60
  /**
50
61
  * Reports that there shouldn't be a space after the first token
51
- * @param {ASTNode} node - The node to report in the event of an error.
52
- * @param {Token} token - The token to use for the report.
53
- * @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`.
54
65
  * @returns {void}
55
66
  */
56
67
  function reportNoBeginningSpace(node, token, tokenAfter) {
@@ -69,9 +80,9 @@ module.exports = {
69
80
 
70
81
  /**
71
82
  * Reports that there shouldn't be a space before the last token
72
- * @param {ASTNode} node - The node to report in the event of an error.
73
- * @param {Token} token - The token to use for the report.
74
- * @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`.
75
86
  * @returns {void}
76
87
  */
77
88
  function reportNoEndingSpace(node, token, tokenBefore) {
@@ -90,8 +101,8 @@ module.exports = {
90
101
 
91
102
  /**
92
103
  * Reports that there should be a space after the first token
93
- * @param {ASTNode} node - The node to report in the event of an error.
94
- * @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.
95
106
  * @returns {void}
96
107
  */
97
108
  function reportRequiredBeginningSpace(node, token) {
@@ -110,8 +121,8 @@ module.exports = {
110
121
 
111
122
  /**
112
123
  * Reports that there should be a space before the last 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.
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.
115
126
  * @returns {void}
116
127
  */
117
128
  function reportRequiredEndingSpace(node, token) {
@@ -178,10 +189,16 @@ module.exports = {
178
189
  // Public
179
190
  //--------------------------------------------------------------------------
180
191
 
181
- return {
192
+ const listeners = {
182
193
  Property: checkSpacing("key"),
183
194
  MemberExpression: checkSpacing("property")
184
195
  };
185
196
 
197
+ if (enforceForClassMembers) {
198
+ listeners.MethodDefinition = checkSpacing("key");
199
+ }
200
+
201
+ return listeners;
202
+
186
203
  }
187
204
  };
@@ -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) {