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

Skip to content

Commit 44c583a

Browse files
refactor(experimental-utils): simplify eslint-utils' predicate types in ast-utils (typescript-eslint#3563)
1 parent abda961 commit 44c583a

File tree

1 file changed

+25
-58
lines changed
  • packages/experimental-utils/src/ast-utils/eslint-utils

1 file changed

+25
-58
lines changed

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

Lines changed: 25 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -5,59 +5,42 @@ type IsPunctuatorTokenWithValueFunction<Value extends string> = (
55
token: TSESTree.Token,
66
) => token is TSESTree.PunctuatorToken & { value: Value };
77

8-
const isArrowToken =
9-
eslintUtils.isArrowToken as IsPunctuatorTokenWithValueFunction<'=>'>;
10-
const isNotArrowToken = eslintUtils.isNotArrowToken as (
8+
type IsNotPunctuatorTokenWithValueFunction<Value extends string> = (
119
token: TSESTree.Token,
1210
) => token is Exclude<
1311
TSESTree.Token,
14-
TSESTree.PunctuatorToken & { value: '=>' }
12+
TSESTree.PunctuatorToken & { value: Value }
1513
>;
1614

15+
const isArrowToken =
16+
eslintUtils.isArrowToken as IsPunctuatorTokenWithValueFunction<'=>'>;
17+
const isNotArrowToken =
18+
eslintUtils.isNotArrowToken as IsNotPunctuatorTokenWithValueFunction<'=>'>;
19+
1720
const isClosingBraceToken =
1821
eslintUtils.isClosingBraceToken as IsPunctuatorTokenWithValueFunction<'}'>;
19-
const isNotClosingBraceToken = eslintUtils.isNotClosingBraceToken as (
20-
token: TSESTree.Token,
21-
) => token is Exclude<
22-
TSESTree.Token,
23-
TSESTree.PunctuatorToken & { value: '}' }
24-
>;
22+
const isNotClosingBraceToken =
23+
eslintUtils.isNotClosingBraceToken as IsNotPunctuatorTokenWithValueFunction<'}'>;
2524

2625
const isClosingBracketToken =
2726
eslintUtils.isClosingBracketToken as IsPunctuatorTokenWithValueFunction<']'>;
28-
const isNotClosingBracketToken = eslintUtils.isNotClosingBracketToken as (
29-
token: TSESTree.Token,
30-
) => token is Exclude<
31-
TSESTree.Token,
32-
TSESTree.PunctuatorToken & { value: ']' }
33-
>;
27+
const isNotClosingBracketToken =
28+
eslintUtils.isNotClosingBracketToken as IsNotPunctuatorTokenWithValueFunction<']'>;
3429

3530
const isClosingParenToken =
3631
eslintUtils.isClosingParenToken as IsPunctuatorTokenWithValueFunction<')'>;
37-
const isNotClosingParenToken = eslintUtils.isNotClosingParenToken as (
38-
token: TSESTree.Token,
39-
) => token is Exclude<
40-
TSESTree.Token,
41-
TSESTree.PunctuatorToken & { value: ')' }
42-
>;
32+
const isNotClosingParenToken =
33+
eslintUtils.isNotClosingParenToken as IsNotPunctuatorTokenWithValueFunction<')'>;
4334

4435
const isColonToken =
4536
eslintUtils.isColonToken as IsPunctuatorTokenWithValueFunction<':'>;
46-
const isNotColonToken = eslintUtils.isNotColonToken as (
47-
token: TSESTree.Token,
48-
) => token is Exclude<
49-
TSESTree.Token,
50-
TSESTree.PunctuatorToken & { value: ':' }
51-
>;
37+
const isNotColonToken =
38+
eslintUtils.isNotColonToken as IsNotPunctuatorTokenWithValueFunction<':'>;
5239

5340
const isCommaToken =
5441
eslintUtils.isCommaToken as IsPunctuatorTokenWithValueFunction<','>;
55-
const isNotCommaToken = eslintUtils.isNotCommaToken as (
56-
token: TSESTree.Token,
57-
) => token is Exclude<
58-
TSESTree.Token,
59-
TSESTree.PunctuatorToken & { value: ',' }
60-
>;
42+
const isNotCommaToken =
43+
eslintUtils.isNotCommaToken as IsNotPunctuatorTokenWithValueFunction<','>;
6144

6245
const isCommentToken = eslintUtils.isCommentToken as (
6346
token: TSESTree.Token,
@@ -68,39 +51,23 @@ const isNotCommentToken = eslintUtils.isNotCommentToken as (
6851

6952
const isOpeningBraceToken =
7053
eslintUtils.isOpeningBraceToken as IsPunctuatorTokenWithValueFunction<'{'>;
71-
const isNotOpeningBraceToken = eslintUtils.isNotOpeningBraceToken as (
72-
token: TSESTree.Token,
73-
) => token is Exclude<
74-
TSESTree.Token,
75-
TSESTree.PunctuatorToken & { value: '{' }
76-
>;
54+
const isNotOpeningBraceToken =
55+
eslintUtils.isNotOpeningBraceToken as IsNotPunctuatorTokenWithValueFunction<'{'>;
7756

7857
const isOpeningBracketToken =
7958
eslintUtils.isOpeningBracketToken as IsPunctuatorTokenWithValueFunction<'['>;
80-
const isNotOpeningBracketToken = eslintUtils.isNotOpeningBracketToken as (
81-
token: TSESTree.Token,
82-
) => token is Exclude<
83-
TSESTree.Token,
84-
TSESTree.PunctuatorToken & { value: '[' }
85-
>;
59+
const isNotOpeningBracketToken =
60+
eslintUtils.isNotOpeningBracketToken as IsNotPunctuatorTokenWithValueFunction<'['>;
8661

8762
const isOpeningParenToken =
8863
eslintUtils.isOpeningParenToken as IsPunctuatorTokenWithValueFunction<'('>;
89-
const isNotOpeningParenToken = eslintUtils.isNotOpeningParenToken as (
90-
token: TSESTree.Token,
91-
) => token is Exclude<
92-
TSESTree.Token,
93-
TSESTree.PunctuatorToken & { value: '(' }
94-
>;
64+
const isNotOpeningParenToken =
65+
eslintUtils.isNotOpeningParenToken as IsNotPunctuatorTokenWithValueFunction<'('>;
9566

9667
const isSemicolonToken =
9768
eslintUtils.isSemicolonToken as IsPunctuatorTokenWithValueFunction<';'>;
98-
const isNotSemicolonToken = eslintUtils.isNotSemicolonToken as (
99-
token: TSESTree.Token,
100-
) => token is Exclude<
101-
TSESTree.Token,
102-
TSESTree.PunctuatorToken & { value: ';' }
103-
>;
69+
const isNotSemicolonToken =
70+
eslintUtils.isNotSemicolonToken as IsNotPunctuatorTokenWithValueFunction<';'>;
10471

10572
export {
10673
isArrowToken,

0 commit comments

Comments
 (0)