Skip to content

Repo: Add a util for determining whether a node is a specific identifier #8327

Closed as not planned
@StyleShit

Description

@StyleShit

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:

if (
node.typeName.type === AST_NODE_TYPES.Identifier &&
node.typeName.name === 'Array'
) {

return (
node.typeName.type === AST_NODE_TYPES.Identifier &&
node.typeName.name === 'const'
);

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:

function isIdentifier(
init: TSESTree.Expression,
...names: string[]
): boolean {
return (
init.type === AST_NODE_TYPES.Identifier && names.includes(init.name)
);
}

It might be a nice good first issue PR 😄

Metadata

Metadata

Assignees

No one assigned

    Labels

    locked due to agePlease open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.repo maintenancethings to do with maintenance of the repo, and not with code/docswontfixThis will not be worked on

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions