Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ae82ea4

Browse files
committed
fix(experimental-utils): add back SourceCode.isSpaceBetweenTokens
SourceCode.isSpaceBetween only exists in 6.7.0, so isSpaceBetweenTokens is a valid alternative until older versions are dead.
1 parent fe59f69 commit ae82ea4

File tree

6 files changed

+22
-8
lines changed

6 files changed

+22
-8
lines changed

packages/eslint-plugin/src/rules/array-type.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ export default util.createRule<Options, MessageIds>({
147147
}
148148

149149
const nextToken = sourceCode.getTokenAfter(prevToken);
150-
if (nextToken && sourceCode.isSpaceBetween(prevToken, nextToken)) {
150+
if (nextToken && sourceCode.isSpaceBetweenTokens(prevToken, nextToken)) {
151151
return false;
152152
}
153153

packages/eslint-plugin/src/rules/comma-spacing.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ export default createRule<Options, MessageIds>({
111111
if (
112112
prevToken &&
113113
isTokenOnSameLine(prevToken, commaToken) &&
114-
spaceBefore !== sourceCode.isSpaceBetween(prevToken, commaToken)
114+
spaceBefore !== sourceCode.isSpaceBetweenTokens(prevToken, commaToken)
115115
) {
116116
context.report({
117117
node: commaToken,
@@ -140,7 +140,7 @@ export default createRule<Options, MessageIds>({
140140
if (
141141
nextToken &&
142142
isTokenOnSameLine(commaToken, nextToken) &&
143-
spaceAfter !== sourceCode.isSpaceBetween(commaToken, nextToken)
143+
spaceAfter !== sourceCode.isSpaceBetweenTokens(commaToken, nextToken)
144144
) {
145145
context.report({
146146
node: commaToken,

packages/eslint-plugin/src/rules/space-before-function-paren.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ export default util.createRule<Options, MessageIds>({
145145
rightToken = sourceCode.getFirstToken(node, util.isOpeningParenToken)!;
146146
leftToken = sourceCode.getTokenBefore(rightToken)!;
147147
}
148-
const hasSpacing = sourceCode.isSpaceBetween(leftToken, rightToken);
148+
const hasSpacing = sourceCode.isSpaceBetweenTokens(leftToken, rightToken);
149149

150150
if (hasSpacing && functionConfig === 'never') {
151151
context.report({

packages/experimental-utils/src/ts-eslint/ESLint.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,8 @@ namespace ESLint {
346346
* This class depends on the Node.js fs module and the file system, so you cannot use it in browsers.
347347
*
348348
* If you want to lint code on browsers, use the Linter class instead.
349+
*
350+
* @since 7.0.0
349351
*/
350352
class ESLint extends (ESLintESLint as typeof ESLintBase) {}
351353

packages/experimental-utils/src/ts-eslint/RuleTester.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,6 @@ declare class RuleTesterBase {
159159
static it?: (text: string, callback: () => void) => void;
160160
}
161161

162-
/**
163-
* @deprecated - use RuleTesterSafe instead
164-
*/
165162
class RuleTester extends (ESLintRuleTester as typeof RuleTesterBase) {}
166163

167164
export {

packages/experimental-utils/src/ts-eslint/SourceCode.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,14 +296,29 @@ declare class SourceCodeBase extends TokenStore {
296296
* Determines if two nodes or tokens have at least one whitespace character
297297
* between them. Order does not matter. Returns false if the given nodes or
298298
* tokens overlap.
299+
* This was added in v6.7.0.
300+
* @since 6.7.0
299301
* @param first The first node or token to check between.
300302
* @param second The second node or token to check between.
301303
* @returns True if there is a whitespace character between any of the tokens found between the two given nodes or tokens.
302304
*/
303-
isSpaceBetween(
305+
isSpaceBetween?(
304306
first: TSESTree.Token | TSESTree.Comment | TSESTree.Node,
305307
second: TSESTree.Token | TSESTree.Comment | TSESTree.Node,
306308
): boolean;
309+
/**
310+
* Determines if two nodes or tokens have at least one whitespace character
311+
* between them. Order does not matter. Returns false if the given nodes or
312+
* tokens overlap.
313+
* For backward compatibility, this method returns true if there are
314+
* `JSXText` tokens that contain whitespace between the two.
315+
* @param first The first node or token to check between.
316+
* @param second The second node or token to check between.
317+
* @returns {boolean} True if there is a whitespace character between
318+
* any of the tokens found between the two given nodes or tokens.
319+
* @deprecated in favor of isSpaceBetween
320+
*/
321+
isSpaceBetweenTokens(first: TSESTree.Token, second: TSESTree.Token): boolean;
307322
/**
308323
* The source code split into lines according to ECMA-262 specification.
309324
* This is done to avoid each rule needing to do so separately.

0 commit comments

Comments
 (0)