Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
Closed as not planned
Description
Suggestion
Splits from#8295 (comment)
The proposal is to go over all of the places where we check if a node is a specific identifier and use a util for that. Here are a couple of examples of places we do this:
typescript-eslint/packages/eslint-plugin/src/rules/array-type.ts
Lines 31 to 34 in82cb9dd
if( | |
node.typeName.type===AST_NODE_TYPES.Identifier&& | |
node.typeName.name==='Array' | |
){ |
typescript-eslint/packages/eslint-plugin/src/rules/consistent-type-assertions.ts
Lines 102 to 105 ina54a60b
return( | |
node.typeName.type===AST_NODE_TYPES.Identifier&& | |
node.typeName.name==='const' | |
); |
typescript-eslint/packages/eslint-plugin/src/rules/no-explicit-any.ts
Lines 110 to 114 ine77616b
return( | |
node.type===AST_NODE_TYPES.TSTypeReference&& | |
node.typeName.type===AST_NODE_TYPES.Identifier&& | |
['Array','ReadonlyArray'].includes(node.typeName.name) | |
); |
I think we can take inspiration from this existing function and extract it to a util:
functionisIdentifier( | |
init:TSESTree.Expression, | |
...names:string[] | |
):boolean{ | |
return( | |
init.type===AST_NODE_TYPES.Identifier&&names.includes(init.name) | |
); | |
} |
It might be a nicegood first issue
PR 😄