Skip to content

Commit 700e2cc

Browse files
refactor: use isNodeOfType from ASTUtils instead of own version (#556)
1 parent e20fc33 commit 700e2cc

File tree

2 files changed

+45
-32
lines changed

2 files changed

+45
-32
lines changed

Diff for: lib/node-utils/is-node-of-type.ts

+42-29
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,61 @@
1-
import { AST_NODE_TYPES, TSESTree } from '@typescript-eslint/utils';
1+
import { AST_NODE_TYPES, ASTUtils } from '@typescript-eslint/utils';
22

3-
const isNodeOfType =
4-
<NodeType extends AST_NODE_TYPES>(nodeType: NodeType) =>
5-
(
6-
node: TSESTree.Node | null | undefined
7-
): node is TSESTree.Node & { type: NodeType } =>
8-
node?.type === nodeType;
9-
10-
export const isArrayExpression = isNodeOfType(AST_NODE_TYPES.ArrayExpression);
11-
export const isArrowFunctionExpression = isNodeOfType(
3+
export const isArrayExpression = ASTUtils.isNodeOfType(
4+
AST_NODE_TYPES.ArrayExpression
5+
);
6+
export const isArrowFunctionExpression = ASTUtils.isNodeOfType(
127
AST_NODE_TYPES.ArrowFunctionExpression
138
);
14-
export const isBlockStatement = isNodeOfType(AST_NODE_TYPES.BlockStatement);
15-
export const isCallExpression = isNodeOfType(AST_NODE_TYPES.CallExpression);
16-
export const isExpressionStatement = isNodeOfType(
9+
export const isBlockStatement = ASTUtils.isNodeOfType(
10+
AST_NODE_TYPES.BlockStatement
11+
);
12+
export const isCallExpression = ASTUtils.isNodeOfType(
13+
AST_NODE_TYPES.CallExpression
14+
);
15+
export const isExpressionStatement = ASTUtils.isNodeOfType(
1716
AST_NODE_TYPES.ExpressionStatement
1817
);
19-
export const isVariableDeclaration = isNodeOfType(
18+
export const isVariableDeclaration = ASTUtils.isNodeOfType(
2019
AST_NODE_TYPES.VariableDeclaration
2120
);
22-
export const isAssignmentExpression = isNodeOfType(
21+
export const isAssignmentExpression = ASTUtils.isNodeOfType(
2322
AST_NODE_TYPES.AssignmentExpression
2423
);
25-
export const isSequenceExpression = isNodeOfType(
24+
export const isSequenceExpression = ASTUtils.isNodeOfType(
2625
AST_NODE_TYPES.SequenceExpression
2726
);
28-
export const isImportDeclaration = isNodeOfType(
27+
export const isImportDeclaration = ASTUtils.isNodeOfType(
2928
AST_NODE_TYPES.ImportDeclaration
3029
);
31-
export const isImportDefaultSpecifier = isNodeOfType(
30+
export const isImportDefaultSpecifier = ASTUtils.isNodeOfType(
3231
AST_NODE_TYPES.ImportDefaultSpecifier
3332
);
34-
export const isImportNamespaceSpecifier = isNodeOfType(
33+
export const isImportNamespaceSpecifier = ASTUtils.isNodeOfType(
3534
AST_NODE_TYPES.ImportNamespaceSpecifier
3635
);
37-
export const isImportSpecifier = isNodeOfType(AST_NODE_TYPES.ImportSpecifier);
38-
export const isJSXAttribute = isNodeOfType(AST_NODE_TYPES.JSXAttribute);
39-
export const isLiteral = isNodeOfType(AST_NODE_TYPES.Literal);
40-
export const isMemberExpression = isNodeOfType(AST_NODE_TYPES.MemberExpression);
41-
export const isNewExpression = isNodeOfType(AST_NODE_TYPES.NewExpression);
42-
export const isObjectExpression = isNodeOfType(AST_NODE_TYPES.ObjectExpression);
43-
export const isObjectPattern = isNodeOfType(AST_NODE_TYPES.ObjectPattern);
44-
export const isProperty = isNodeOfType(AST_NODE_TYPES.Property);
45-
export const isReturnStatement = isNodeOfType(AST_NODE_TYPES.ReturnStatement);
46-
export const isFunctionExpression = isNodeOfType(
36+
export const isImportSpecifier = ASTUtils.isNodeOfType(
37+
AST_NODE_TYPES.ImportSpecifier
38+
);
39+
export const isJSXAttribute = ASTUtils.isNodeOfType(
40+
AST_NODE_TYPES.JSXAttribute
41+
);
42+
export const isLiteral = ASTUtils.isNodeOfType(AST_NODE_TYPES.Literal);
43+
export const isMemberExpression = ASTUtils.isNodeOfType(
44+
AST_NODE_TYPES.MemberExpression
45+
);
46+
export const isNewExpression = ASTUtils.isNodeOfType(
47+
AST_NODE_TYPES.NewExpression
48+
);
49+
export const isObjectExpression = ASTUtils.isNodeOfType(
50+
AST_NODE_TYPES.ObjectExpression
51+
);
52+
export const isObjectPattern = ASTUtils.isNodeOfType(
53+
AST_NODE_TYPES.ObjectPattern
54+
);
55+
export const isProperty = ASTUtils.isNodeOfType(AST_NODE_TYPES.Property);
56+
export const isReturnStatement = ASTUtils.isNodeOfType(
57+
AST_NODE_TYPES.ReturnStatement
58+
);
59+
export const isFunctionExpression = ASTUtils.isNodeOfType(
4760
AST_NODE_TYPES.FunctionExpression
4861
);

Diff for: package.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,16 @@
4242
"prepare": "is-ci || husky install"
4343
},
4444
"dependencies": {
45-
"@typescript-eslint/utils": "^5.10.2"
45+
"@typescript-eslint/utils": "^5.13.0"
4646
},
4747
"devDependencies": {
4848
"@babel/eslint-plugin": "^7.16.5",
4949
"@commitlint/cli": "^16.0.2",
5050
"@commitlint/config-conventional": "^16.0.0",
5151
"@types/jest": "^27.4.0",
5252
"@types/node": "^16.11.19",
53-
"@typescript-eslint/eslint-plugin": "^5.10.2",
54-
"@typescript-eslint/parser": "^5.10.2",
53+
"@typescript-eslint/eslint-plugin": "^5.13.0",
54+
"@typescript-eslint/parser": "^5.13.0",
5555
"cpy-cli": "^3.1.1",
5656
"eslint": "^8.6.0",
5757
"eslint-config-kentcdodds": "^20.0.1",

0 commit comments

Comments
 (0)