Skip to content

Commit

Permalink
fix(experimental-utils): add back SourceCode.isSpaceBetweenTokens
Browse files Browse the repository at this point in the history
SourceCode.isSpaceBetween only exists in 6.7.0, so isSpaceBetweenTokens is a valid alternative until older versions are dead.
  • Loading branch information
bradzacher committed May 21, 2020
1 parent fe59f69 commit ae82ea4
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 8 deletions.
2 changes: 1 addition & 1 deletion packages/eslint-plugin/src/rules/array-type.ts
Expand Up @@ -147,7 +147,7 @@ export default util.createRule<Options, MessageIds>({
}

const nextToken = sourceCode.getTokenAfter(prevToken);
if (nextToken && sourceCode.isSpaceBetween(prevToken, nextToken)) {
if (nextToken && sourceCode.isSpaceBetweenTokens(prevToken, nextToken)) {
return false;
}

Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-plugin/src/rules/comma-spacing.ts
Expand Up @@ -111,7 +111,7 @@ export default createRule<Options, MessageIds>({
if (
prevToken &&
isTokenOnSameLine(prevToken, commaToken) &&
spaceBefore !== sourceCode.isSpaceBetween(prevToken, commaToken)
spaceBefore !== sourceCode.isSpaceBetweenTokens(prevToken, commaToken)
) {
context.report({
node: commaToken,
Expand Down Expand Up @@ -140,7 +140,7 @@ export default createRule<Options, MessageIds>({
if (
nextToken &&
isTokenOnSameLine(commaToken, nextToken) &&
spaceAfter !== sourceCode.isSpaceBetween(commaToken, nextToken)
spaceAfter !== sourceCode.isSpaceBetweenTokens(commaToken, nextToken)
) {
context.report({
node: commaToken,
Expand Down
Expand Up @@ -145,7 +145,7 @@ export default util.createRule<Options, MessageIds>({
rightToken = sourceCode.getFirstToken(node, util.isOpeningParenToken)!;
leftToken = sourceCode.getTokenBefore(rightToken)!;
}
const hasSpacing = sourceCode.isSpaceBetween(leftToken, rightToken);
const hasSpacing = sourceCode.isSpaceBetweenTokens(leftToken, rightToken);

if (hasSpacing && functionConfig === 'never') {
context.report({
Expand Down
2 changes: 2 additions & 0 deletions packages/experimental-utils/src/ts-eslint/ESLint.ts
Expand Up @@ -346,6 +346,8 @@ namespace ESLint {
* This class depends on the Node.js fs module and the file system, so you cannot use it in browsers.
*
* If you want to lint code on browsers, use the Linter class instead.
*
* @since 7.0.0
*/
class ESLint extends (ESLintESLint as typeof ESLintBase) {}

Expand Down
3 changes: 0 additions & 3 deletions packages/experimental-utils/src/ts-eslint/RuleTester.ts
Expand Up @@ -159,9 +159,6 @@ declare class RuleTesterBase {
static it?: (text: string, callback: () => void) => void;
}

/**
* @deprecated - use RuleTesterSafe instead
*/
class RuleTester extends (ESLintRuleTester as typeof RuleTesterBase) {}

export {
Expand Down
17 changes: 16 additions & 1 deletion packages/experimental-utils/src/ts-eslint/SourceCode.ts
Expand Up @@ -296,14 +296,29 @@ declare class SourceCodeBase extends TokenStore {
* Determines if two nodes or tokens have at least one whitespace character
* between them. Order does not matter. Returns false if the given nodes or
* tokens overlap.
* This was added in v6.7.0.
* @since 6.7.0
* @param first The first node or token to check between.
* @param second The second node or token to check between.
* @returns True if there is a whitespace character between any of the tokens found between the two given nodes or tokens.
*/
isSpaceBetween(
isSpaceBetween?(
first: TSESTree.Token | TSESTree.Comment | TSESTree.Node,
second: TSESTree.Token | TSESTree.Comment | TSESTree.Node,
): boolean;
/**
* Determines if two nodes or tokens have at least one whitespace character
* between them. Order does not matter. Returns false if the given nodes or
* tokens overlap.
* For backward compatibility, this method returns true if there are
* `JSXText` tokens that contain whitespace between the two.
* @param first The first node or token to check between.
* @param second The second node or token to check between.
* @returns {boolean} True if there is a whitespace character between
* any of the tokens found between the two given nodes or tokens.
* @deprecated in favor of isSpaceBetween
*/
isSpaceBetweenTokens(first: TSESTree.Token, second: TSESTree.Token): boolean;
/**
* The source code split into lines according to ECMA-262 specification.
* This is done to avoid each rule needing to do so separately.
Expand Down

0 comments on commit ae82ea4

Please sign in to comment.