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

Skip to content

Commit e2e76a7

Browse files
refactor(experimental-utils): simplify eslint-utils' predicate types in ast-utils (typescript-eslint#3550)
1 parent ffbb3cf commit e2e76a7

File tree

1 file changed

+23
-29
lines changed
  • packages/experimental-utils/src/ast-utils/eslint-utils

1 file changed

+23
-29
lines changed

packages/experimental-utils/src/ast-utils/eslint-utils/predicates.ts

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,57 @@
11
import * as eslintUtils from 'eslint-utils';
22
import { TSESTree } from '../../ts-estree';
33

4-
const isArrowToken = eslintUtils.isArrowToken as (
4+
type IsPunctuatorTokenWithValueFunction<Value extends string> = (
55
token: TSESTree.Token,
6-
) => token is TSESTree.PunctuatorToken & { value: '=>' };
6+
) => token is TSESTree.PunctuatorToken & { value: Value };
7+
8+
const isArrowToken =
9+
eslintUtils.isArrowToken as IsPunctuatorTokenWithValueFunction<'=>'>;
710
const isNotArrowToken = eslintUtils.isNotArrowToken as (
811
token: TSESTree.Token,
912
) => token is Exclude<
1013
TSESTree.Token,
1114
TSESTree.PunctuatorToken & { value: '=>' }
1215
>;
1316

14-
const isClosingBraceToken = eslintUtils.isClosingBraceToken as (
15-
token: TSESTree.Token,
16-
) => token is TSESTree.PunctuatorToken & { value: '}' };
17+
const isClosingBraceToken =
18+
eslintUtils.isClosingBraceToken as IsPunctuatorTokenWithValueFunction<'}'>;
1719
const isNotClosingBraceToken = eslintUtils.isNotClosingBraceToken as (
1820
token: TSESTree.Token,
1921
) => token is Exclude<
2022
TSESTree.Token,
2123
TSESTree.PunctuatorToken & { value: '}' }
2224
>;
2325

24-
const isClosingBracketToken = eslintUtils.isClosingBracketToken as (
25-
token: TSESTree.Token,
26-
) => token is TSESTree.PunctuatorToken & { value: ']' };
26+
const isClosingBracketToken =
27+
eslintUtils.isClosingBracketToken as IsPunctuatorTokenWithValueFunction<']'>;
2728
const isNotClosingBracketToken = eslintUtils.isNotClosingBracketToken as (
2829
token: TSESTree.Token,
2930
) => token is Exclude<
3031
TSESTree.Token,
3132
TSESTree.PunctuatorToken & { value: ']' }
3233
>;
3334

34-
const isClosingParenToken = eslintUtils.isClosingParenToken as (
35-
token: TSESTree.Token,
36-
) => token is TSESTree.PunctuatorToken & { value: ')' };
35+
const isClosingParenToken =
36+
eslintUtils.isClosingParenToken as IsPunctuatorTokenWithValueFunction<')'>;
3737
const isNotClosingParenToken = eslintUtils.isNotClosingParenToken as (
3838
token: TSESTree.Token,
3939
) => token is Exclude<
4040
TSESTree.Token,
4141
TSESTree.PunctuatorToken & { value: ')' }
4242
>;
4343

44-
const isColonToken = eslintUtils.isColonToken as (
45-
token: TSESTree.Token,
46-
) => token is TSESTree.PunctuatorToken & { value: ':' };
44+
const isColonToken =
45+
eslintUtils.isColonToken as IsPunctuatorTokenWithValueFunction<':'>;
4746
const isNotColonToken = eslintUtils.isNotColonToken as (
4847
token: TSESTree.Token,
4948
) => token is Exclude<
5049
TSESTree.Token,
5150
TSESTree.PunctuatorToken & { value: ':' }
5251
>;
5352

54-
const isCommaToken = eslintUtils.isCommaToken as (
55-
token: TSESTree.Token,
56-
) => token is TSESTree.PunctuatorToken & { value: ',' };
53+
const isCommaToken =
54+
eslintUtils.isCommaToken as IsPunctuatorTokenWithValueFunction<','>;
5755
const isNotCommaToken = eslintUtils.isNotCommaToken as (
5856
token: TSESTree.Token,
5957
) => token is Exclude<
@@ -68,39 +66,35 @@ const isNotCommentToken = eslintUtils.isNotCommentToken as (
6866
token: TSESTree.Token,
6967
) => token is Exclude<TSESTree.Token, TSESTree.Comment>;
7068

71-
const isOpeningBraceToken = eslintUtils.isOpeningBraceToken as (
72-
token: TSESTree.Token,
73-
) => token is TSESTree.PunctuatorToken & { value: '{' };
69+
const isOpeningBraceToken =
70+
eslintUtils.isOpeningBraceToken as IsPunctuatorTokenWithValueFunction<'{'>;
7471
const isNotOpeningBraceToken = eslintUtils.isNotOpeningBraceToken as (
7572
token: TSESTree.Token,
7673
) => token is Exclude<
7774
TSESTree.Token,
7875
TSESTree.PunctuatorToken & { value: '{' }
7976
>;
8077

81-
const isOpeningBracketToken = eslintUtils.isOpeningBracketToken as (
82-
token: TSESTree.Token,
83-
) => token is TSESTree.PunctuatorToken & { value: '[' };
78+
const isOpeningBracketToken =
79+
eslintUtils.isOpeningBracketToken as IsPunctuatorTokenWithValueFunction<'['>;
8480
const isNotOpeningBracketToken = eslintUtils.isNotOpeningBracketToken as (
8581
token: TSESTree.Token,
8682
) => token is Exclude<
8783
TSESTree.Token,
8884
TSESTree.PunctuatorToken & { value: '[' }
8985
>;
9086

91-
const isOpeningParenToken = eslintUtils.isOpeningParenToken as (
92-
token: TSESTree.Token,
93-
) => token is TSESTree.PunctuatorToken & { value: '(' };
87+
const isOpeningParenToken =
88+
eslintUtils.isOpeningParenToken as IsPunctuatorTokenWithValueFunction<'('>;
9489
const isNotOpeningParenToken = eslintUtils.isNotOpeningParenToken as (
9590
token: TSESTree.Token,
9691
) => token is Exclude<
9792
TSESTree.Token,
9893
TSESTree.PunctuatorToken & { value: '(' }
9994
>;
10095

101-
const isSemicolonToken = eslintUtils.isSemicolonToken as (
102-
token: TSESTree.Token,
103-
) => token is TSESTree.PunctuatorToken & { value: ';' };
96+
const isSemicolonToken =
97+
eslintUtils.isSemicolonToken as IsPunctuatorTokenWithValueFunction<';'>;
10498
const isNotSemicolonToken = eslintUtils.isNotSemicolonToken as (
10599
token: TSESTree.Token,
106100
) => token is Exclude<

0 commit comments

Comments
 (0)