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
@@ -10,7 +10,6 @@ const debug = require("debug")("eslint:rules");
10
10
 
11
11
  /**
12
12
  * The `Map` object that loads each rule when it's accessed.
13
- *
14
13
  * @example
15
14
  * const rules = new LazyLoadingRuleMap([
16
15
  * ["eqeqeq", () => require("eqeqeq")],
@@ -32,8 +32,9 @@ module.exports = {
32
32
  // Helpers
33
33
  //--------------------------------------------------------------------------
34
34
 
35
+ // eslint-disable-next-line jsdoc/require-description
35
36
  /**
36
- * @param {ASTNode} node - any node
37
+ * @param {ASTNode} node any node
37
38
  * @returns {boolean} whether the given node structurally represents a directive
38
39
  */
39
40
  function looksLikeDirective(node) {
@@ -43,7 +44,7 @@ module.exports = {
43
44
 
44
45
  /**
45
46
  * Check to see if its a ES6 import declaration
46
- * @param {ASTNode} node - any node
47
+ * @param {ASTNode} node any node
47
48
  * @returns {boolean} whether the given node represents a import declaration
48
49
  */
49
50
  function looksLikeImport(node) {
@@ -53,8 +54,7 @@ module.exports = {
53
54
 
54
55
  /**
55
56
  * Checks whether a given node is a variable declaration or not.
56
- *
57
- * @param {ASTNode} node - any node
57
+ * @param {ASTNode} node any node
58
58
  * @returns {boolean} `true` if the node is a variable declaration.
59
59
  */
60
60
  function isVariableDeclaration(node) {
@@ -70,8 +70,8 @@ module.exports = {
70
70
 
71
71
  /**
72
72
  * Checks whether this variable is on top of the block body
73
- * @param {ASTNode} node - The node to check
74
- * @param {ASTNode[]} statements - collection of ASTNodes for the parent node block
73
+ * @param {ASTNode} node The node to check
74
+ * @param {ASTNode[]} statements collection of ASTNodes for the parent node block
75
75
  * @returns {boolean} True if var is on top otherwise false
76
76
  */
77
77
  function isVarOnTop(node, statements) {
@@ -99,8 +99,8 @@ module.exports = {
99
99
 
100
100
  /**
101
101
  * Checks whether variable is on top at the global level
102
- * @param {ASTNode} node - The node to check
103
- * @param {ASTNode} parent - Parent of the node
102
+ * @param {ASTNode} node The node to check
103
+ * @param {ASTNode} parent Parent of the node
104
104
  * @returns {void}
105
105
  */
106
106
  function globalVarCheck(node, parent) {
@@ -111,9 +111,9 @@ module.exports = {
111
111
 
112
112
  /**
113
113
  * Checks whether variable is on top at functional block scope level
114
- * @param {ASTNode} node - The node to check
115
- * @param {ASTNode} parent - Parent of the node
116
- * @param {ASTNode} grandParent - Parent of the node's parent
114
+ * @param {ASTNode} node The node to check
115
+ * @param {ASTNode} parent Parent of the node
116
+ * @param {ASTNode} grandParent Parent of the node's parent
117
117
  * @returns {void}
118
118
  */
119
119
  function blockScopeVarCheck(node, parent, grandParent) {
@@ -77,7 +77,7 @@ module.exports = {
77
77
 
78
78
  /**
79
79
  * Checks whether a given config has valid severity or not.
80
- * @param {number|string|Array} ruleConfig - The configuration for an individual rule.
80
+ * @param {number|string|Array} ruleConfig The configuration for an individual rule.
81
81
  * @returns {boolean} `true` if the configuration has valid severity.
82
82
  */
83
83
  isValidSeverity(ruleConfig) {
@@ -91,7 +91,7 @@ module.exports = {
91
91
 
92
92
  /**
93
93
  * Checks whether every rule of a given config has valid severity or not.
94
- * @param {Object} config - The configuration for rules.
94
+ * @param {Object} config The configuration for rules.
95
95
  * @returns {boolean} `true` if the configuration has valid severity.
96
96
  */
97
97
  isEverySeverityValid(config) {
@@ -28,8 +28,8 @@ function environment() {
28
28
 
29
29
  /**
30
30
  * Checks if a path is a child of a directory.
31
- * @param {string} parentPath - The parent path to check.
32
- * @param {string} childPath - The path to check.
31
+ * @param {string} parentPath The parent path to check.
32
+ * @param {string} childPath The path to check.
33
33
  * @returns {boolean} Whether or not the given path is a child of a directory.
34
34
  */
35
35
  function isChildOfDirectory(parentPath, childPath) {
@@ -38,8 +38,8 @@ function environment() {
38
38
 
39
39
  /**
40
40
  * Synchronously executes a shell command and formats the result.
41
- * @param {string} cmd - The command to execute.
42
- * @param {Array} args - The arguments to be executed with the command.
41
+ * @param {string} cmd The command to execute.
42
+ * @param {Array} args The arguments to be executed with the command.
43
43
  * @returns {string} The version returned by the command.
44
44
  */
45
45
  function execCommand(cmd, args) {
@@ -63,7 +63,7 @@ function environment() {
63
63
 
64
64
  /**
65
65
  * Normalizes a version number.
66
- * @param {string} versionStr - The string to normalize.
66
+ * @param {string} versionStr The string to normalize.
67
67
  * @returns {string} The normalized version number.
68
68
  */
69
69
  function normalizeVersionStr(versionStr) {
@@ -72,7 +72,7 @@ function environment() {
72
72
 
73
73
  /**
74
74
  * Gets bin version.
75
- * @param {string} bin - The bin to check.
75
+ * @param {string} bin The bin to check.
76
76
  * @returns {string} The normalized version returned by the command.
77
77
  */
78
78
  function getBinVersion(bin) {
@@ -88,8 +88,8 @@ function environment() {
88
88
 
89
89
  /**
90
90
  * Gets installed npm package version.
91
- * @param {string} pkg - The package to check.
92
- * @param {boolean} global - Whether to check globally or not.
91
+ * @param {string} pkg The package to check.
92
+ * @param {boolean} global Whether to check globally or not.
93
93
  * @returns {string} The normalized version returned by the command.
94
94
  */
95
95
  function getNpmPackageVersion(pkg, { global = false } = {}) {
@@ -65,6 +65,7 @@ class Traverser {
65
65
  this._leave = null;
66
66
  }
67
67
 
68
+ // eslint-disable-next-line jsdoc/require-description
68
69
  /**
69
70
  * @returns {ASTNode} The current node.
70
71
  */
@@ -72,6 +73,7 @@ class Traverser {
72
73
  return this._current;
73
74
  }
74
75
 
76
+ // eslint-disable-next-line jsdoc/require-description
75
77
  /**
76
78
  * @returns {ASTNode[]} The ancestor nodes.
77
79
  */
@@ -30,6 +30,7 @@ module.exports = {};
30
30
  * @property {Record<string, boolean>} [env] The environment settings.
31
31
  * @property {string | string[]} [extends] The path to other config files or the package name of shareable configs.
32
32
  * @property {Record<string, GlobalConf>} [globals] The global variable settings.
33
+ * @property {string | string[]} [ignorePatterns] The glob patterns that ignore to lint.
33
34
  * @property {boolean} [noInlineConfig] The flag that disables directive comments.
34
35
  * @property {OverrideConfigData[]} [overrides] The override settings per kind of files.
35
36
  * @property {string} [parser] The path to a parser or the package name of a parser.
@@ -91,6 +92,14 @@ module.exports = {};
91
92
  * @property {string} message The error message.
92
93
  * @property {string|null} ruleId The ID of the rule which makes this message.
93
94
  * @property {0|1|2} severity The severity of this message.
95
+ * @property {Array<{desc?: string, messageId?: string, fix: {range: [number, number], text: string}}>} [suggestions] Information for suggestions.
96
+ */
97
+
98
+ /**
99
+ * @typedef {Object} SuggestionResult
100
+ * @property {string} desc A short description.
101
+ * @property {string} [messageId] Id referencing a message for the description.
102
+ * @property {{ text: string, range: number[] }} fix fix result info
94
103
  */
95
104
 
96
105
  /**
@@ -78,6 +78,68 @@ function sortedMerge(tokens, comments) {
78
78
  return result;
79
79
  }
80
80
 
81
+ /**
82
+ * Determines if two nodes or tokens overlap.
83
+ * @param {ASTNode|Token} first The first node or token to check.
84
+ * @param {ASTNode|Token} second The second node or token to check.
85
+ * @returns {boolean} True if the two nodes or tokens overlap.
86
+ * @private
87
+ */
88
+ function nodesOrTokensOverlap(first, second) {
89
+ return (first.range[0] <= second.range[0] && first.range[1] >= second.range[0]) ||
90
+ (second.range[0] <= first.range[0] && second.range[1] >= first.range[0]);
91
+ }
92
+
93
+ /**
94
+ * Determines if two nodes or tokens have at least one whitespace character
95
+ * between them. Order does not matter. Returns false if the given nodes or
96
+ * tokens overlap.
97
+ * @param {SourceCode} sourceCode The source code object.
98
+ * @param {ASTNode|Token} first The first node or token to check between.
99
+ * @param {ASTNode|Token} second The second node or token to check between.
100
+ * @param {boolean} checkInsideOfJSXText If `true` is present, check inside of JSXText tokens for backward compatibility.
101
+ * @returns {boolean} True if there is a whitespace character between
102
+ * any of the tokens found between the two given nodes or tokens.
103
+ * @public
104
+ */
105
+ function isSpaceBetween(sourceCode, first, second, checkInsideOfJSXText) {
106
+ if (nodesOrTokensOverlap(first, second)) {
107
+ return false;
108
+ }
109
+
110
+ const [startingNodeOrToken, endingNodeOrToken] = first.range[1] <= second.range[0]
111
+ ? [first, second]
112
+ : [second, first];
113
+ const firstToken = sourceCode.getLastToken(startingNodeOrToken) || startingNodeOrToken;
114
+ const finalToken = sourceCode.getFirstToken(endingNodeOrToken) || endingNodeOrToken;
115
+ let currentToken = firstToken;
116
+
117
+ while (currentToken !== finalToken) {
118
+ const nextToken = sourceCode.getTokenAfter(currentToken, { includeComments: true });
119
+
120
+ if (
121
+ currentToken.range[1] !== nextToken.range[0] ||
122
+
123
+ /*
124
+ * For backward compatibility, check speces in JSXText.
125
+ * https://github.com/eslint/eslint/issues/12614
126
+ */
127
+ (
128
+ checkInsideOfJSXText &&
129
+ nextToken !== finalToken &&
130
+ nextToken.type === "JSXText" &&
131
+ /\s/u.test(nextToken.value)
132
+ )
133
+ ) {
134
+ return true;
135
+ }
136
+
137
+ currentToken = nextToken;
138
+ }
139
+
140
+ return false;
141
+ }
142
+
81
143
  //------------------------------------------------------------------------------
82
144
  // Public Interface
83
145
  //------------------------------------------------------------------------------
@@ -86,13 +148,13 @@ class SourceCode extends TokenStore {
86
148
 
87
149
  /**
88
150
  * Represents parsed source code.
89
- * @param {string|Object} textOrConfig - The source code text or config object.
90
- * @param {string} textOrConfig.text - The source code text.
91
- * @param {ASTNode} textOrConfig.ast - The Program node of the AST representing the code. This AST should be created from the text that BOM was stripped.
92
- * @param {Object|null} textOrConfig.parserServices - The parser services.
93
- * @param {ScopeManager|null} textOrConfig.scopeManager - The scope of this source code.
94
- * @param {Object|null} textOrConfig.visitorKeys - The visitor keys to traverse AST.
95
- * @param {ASTNode} [astIfNoConfig] - The Program node of the AST representing the code. This AST should be created from the text that BOM was stripped.
151
+ * @param {string|Object} textOrConfig The source code text or config object.
152
+ * @param {string} textOrConfig.text The source code text.
153
+ * @param {ASTNode} textOrConfig.ast The Program node of the AST representing the code. This AST should be created from the text that BOM was stripped.
154
+ * @param {Object|null} textOrConfig.parserServices The parser services.
155
+ * @param {ScopeManager|null} textOrConfig.scopeManager The scope of this source code.
156
+ * @param {Object|null} textOrConfig.visitorKeys The visitor keys to traverse AST.
157
+ * @param {ASTNode} [astIfNoConfig] The Program node of the AST representing the code. This AST should be created from the text that BOM was stripped.
96
158
  */
97
159
  constructor(textOrConfig, astIfNoConfig) {
98
160
  let text, ast, parserServices, scopeManager, visitorKeys;
@@ -411,19 +473,34 @@ class SourceCode extends TokenStore {
411
473
  }
412
474
 
413
475
  /**
414
- * Determines if two tokens have at least one whitespace character
415
- * between them. This completely disregards comments in making the
416
- * determination, so comments count as zero-length substrings.
417
- * @param {Token} first The token to check after.
418
- * @param {Token} second The token to check before.
419
- * @returns {boolean} True if there is only space between tokens, false
420
- * if there is anything other than whitespace between tokens.
476
+ * Determines if two nodes or tokens have at least one whitespace character
477
+ * between them. Order does not matter. Returns false if the given nodes or
478
+ * tokens overlap.
479
+ * @param {ASTNode|Token} first The first node or token to check between.
480
+ * @param {ASTNode|Token} second The second node or token to check between.
481
+ * @returns {boolean} True if there is a whitespace character between
482
+ * any of the tokens found between the two given nodes or tokens.
421
483
  * @public
422
484
  */
423
- isSpaceBetweenTokens(first, second) {
424
- const text = this.text.slice(first.range[1], second.range[0]);
485
+ isSpaceBetween(first, second) {
486
+ return isSpaceBetween(this, first, second, false);
487
+ }
425
488
 
426
- return /\s/u.test(text.replace(/\/\*.*?\*\//gu, ""));
489
+ /**
490
+ * Determines if two nodes or tokens have at least one whitespace character
491
+ * between them. Order does not matter. Returns false if the given nodes or
492
+ * tokens overlap.
493
+ * For backward compatibility, this method returns true if there are
494
+ * `JSXText` tokens that contain whitespaces between the two.
495
+ * @param {ASTNode|Token} first The first node or token to check between.
496
+ * @param {ASTNode|Token} second The second node or token to check between.
497
+ * @returns {boolean} True if there is a whitespace character between
498
+ * any of the tokens found between the two given nodes or tokens.
499
+ * @deprecated in favor of isSpaceBetween().
500
+ * @public
501
+ */
502
+ isSpaceBetweenTokens(first, second) {
503
+ return isSpaceBetween(this, first, second, true);
427
504
  }
428
505
 
429
506
  /**
@@ -22,11 +22,11 @@ module.exports = class BackwardTokenCommentCursor extends Cursor {
22
22
 
23
23
  /**
24
24
  * Initializes this cursor.
25
- * @param {Token[]} tokens - The array of tokens.
26
- * @param {Comment[]} comments - The array of comments.
27
- * @param {Object} indexMap - The map from locations to indices in `tokens`.
28
- * @param {number} startLoc - The start location of the iteration range.
29
- * @param {number} endLoc - The end location of the iteration range.
25
+ * @param {Token[]} tokens The array of tokens.
26
+ * @param {Comment[]} comments The array of comments.
27
+ * @param {Object} indexMap The map from locations to indices in `tokens`.
28
+ * @param {number} startLoc The start location of the iteration range.
29
+ * @param {number} endLoc The end location of the iteration range.
30
30
  */
31
31
  constructor(tokens, comments, indexMap, startLoc, endLoc) {
32
32
  super();
@@ -22,11 +22,11 @@ module.exports = class BackwardTokenCursor extends Cursor {
22
22
 
23
23
  /**
24
24
  * Initializes this cursor.
25
- * @param {Token[]} tokens - The array of tokens.
26
- * @param {Comment[]} comments - The array of comments.
27
- * @param {Object} indexMap - The map from locations to indices in `tokens`.
28
- * @param {number} startLoc - The start location of the iteration range.
29
- * @param {number} endLoc - The end location of the iteration range.
25
+ * @param {Token[]} tokens The array of tokens.
26
+ * @param {Comment[]} comments The array of comments.
27
+ * @param {Object} indexMap The map from locations to indices in `tokens`.
28
+ * @param {number} startLoc The start location of the iteration range.
29
+ * @param {number} endLoc The end location of the iteration range.
30
30
  */
31
31
  constructor(tokens, comments, indexMap, startLoc, endLoc) {
32
32
  super();
@@ -28,8 +28,8 @@ class CursorFactory {
28
28
 
29
29
  /**
30
30
  * Initializes this cursor.
31
- * @param {Function} TokenCursor - The class of the cursor which iterates tokens only.
32
- * @param {Function} TokenCommentCursor - The class of the cursor which iterates the mix of tokens and comments.
31
+ * @param {Function} TokenCursor The class of the cursor which iterates tokens only.
32
+ * @param {Function} TokenCommentCursor The class of the cursor which iterates the mix of tokens and comments.
33
33
  */
34
34
  constructor(TokenCursor, TokenCommentCursor) {
35
35
  this.TokenCursor = TokenCursor;
@@ -38,13 +38,12 @@ class CursorFactory {
38
38
 
39
39
  /**
40
40
  * Creates a base cursor instance that can be decorated by createCursor.
41
- *
42
- * @param {Token[]} tokens - The array of tokens.
43
- * @param {Comment[]} comments - The array of comments.
44
- * @param {Object} indexMap - The map from locations to indices in `tokens`.
45
- * @param {number} startLoc - The start location of the iteration range.
46
- * @param {number} endLoc - The end location of the iteration range.
47
- * @param {boolean} includeComments - The flag to iterate comments as well.
41
+ * @param {Token[]} tokens The array of tokens.
42
+ * @param {Comment[]} comments The array of comments.
43
+ * @param {Object} indexMap The map from locations to indices in `tokens`.
44
+ * @param {number} startLoc The start location of the iteration range.
45
+ * @param {number} endLoc The end location of the iteration range.
46
+ * @param {boolean} includeComments The flag to iterate comments as well.
48
47
  * @returns {Cursor} The created base cursor.
49
48
  */
50
49
  createBaseCursor(tokens, comments, indexMap, startLoc, endLoc, includeComments) {
@@ -55,16 +54,15 @@ class CursorFactory {
55
54
 
56
55
  /**
57
56
  * Creates a cursor that iterates tokens with normalized options.
58
- *
59
- * @param {Token[]} tokens - The array of tokens.
60
- * @param {Comment[]} comments - The array of comments.
61
- * @param {Object} indexMap - The map from locations to indices in `tokens`.
62
- * @param {number} startLoc - The start location of the iteration range.
63
- * @param {number} endLoc - The end location of the iteration range.
64
- * @param {boolean} includeComments - The flag to iterate comments as well.
65
- * @param {Function|null} filter - The predicate function to choose tokens.
66
- * @param {number} skip - The count of tokens the cursor skips.
67
- * @param {number} count - The maximum count of tokens the cursor iterates. Zero is no iteration for backward compatibility.
57
+ * @param {Token[]} tokens The array of tokens.
58
+ * @param {Comment[]} comments The array of comments.
59
+ * @param {Object} indexMap The map from locations to indices in `tokens`.
60
+ * @param {number} startLoc The start location of the iteration range.
61
+ * @param {number} endLoc The end location of the iteration range.
62
+ * @param {boolean} includeComments The flag to iterate comments as well.
63
+ * @param {Function|null} filter The predicate function to choose tokens.
64
+ * @param {number} skip The count of tokens the cursor skips.
65
+ * @param {number} count The maximum count of tokens the cursor iterates. Zero is no iteration for backward compatibility.
68
66
  * @returns {Cursor} The created cursor.
69
67
  */
70
68
  createCursor(tokens, comments, indexMap, startLoc, endLoc, includeComments, filter, skip, count) {
@@ -21,7 +21,7 @@ module.exports = class DecorativeCursor extends Cursor {
21
21
 
22
22
  /**
23
23
  * Initializes this cursor.
24
- * @param {Cursor} cursor - The cursor to be decorated.
24
+ * @param {Cursor} cursor The cursor to be decorated.
25
25
  */
26
26
  constructor(cursor) {
27
27
  super();
@@ -21,8 +21,8 @@ module.exports = class FilterCursor extends DecorativeCursor {
21
21
 
22
22
  /**
23
23
  * Initializes this cursor.
24
- * @param {Cursor} cursor - The cursor to be decorated.
25
- * @param {Function} predicate - The predicate function to decide tokens this cursor iterates.
24
+ * @param {Cursor} cursor The cursor to be decorated.
25
+ * @param {Function} predicate The predicate function to decide tokens this cursor iterates.
26
26
  */
27
27
  constructor(cursor, predicate) {
28
28
  super(cursor);
@@ -22,11 +22,11 @@ module.exports = class ForwardTokenCommentCursor extends Cursor {
22
22
 
23
23
  /**
24
24
  * Initializes this cursor.
25
- * @param {Token[]} tokens - The array of tokens.
26
- * @param {Comment[]} comments - The array of comments.
27
- * @param {Object} indexMap - The map from locations to indices in `tokens`.
28
- * @param {number} startLoc - The start location of the iteration range.
29
- * @param {number} endLoc - The end location of the iteration range.
25
+ * @param {Token[]} tokens The array of tokens.
26
+ * @param {Comment[]} comments The array of comments.
27
+ * @param {Object} indexMap The map from locations to indices in `tokens`.
28
+ * @param {number} startLoc The start location of the iteration range.
29
+ * @param {number} endLoc The end location of the iteration range.
30
30
  */
31
31
  constructor(tokens, comments, indexMap, startLoc, endLoc) {
32
32
  super();
@@ -22,11 +22,11 @@ module.exports = class ForwardTokenCursor extends Cursor {
22
22
 
23
23
  /**
24
24
  * Initializes this cursor.
25
- * @param {Token[]} tokens - The array of tokens.
26
- * @param {Comment[]} comments - The array of comments.
27
- * @param {Object} indexMap - The map from locations to indices in `tokens`.
28
- * @param {number} startLoc - The start location of the iteration range.
29
- * @param {number} endLoc - The end location of the iteration range.
25
+ * @param {Token[]} tokens The array of tokens.
26
+ * @param {Comment[]} comments The array of comments.
27
+ * @param {Object} indexMap The map from locations to indices in `tokens`.
28
+ * @param {number} startLoc The start location of the iteration range.
29
+ * @param {number} endLoc The end location of the iteration range.
30
30
  */
31
31
  constructor(tokens, comments, indexMap, startLoc, endLoc) {
32
32
  super();