Skip to content

Rule enforcing using AST_NODE_TYPES and AST_TOKEN_TYPES from @typescript-eslint/utils #572

@G-Rath

Description

@G-Rath

When using @typescript-eslint/utils you can compare node and token types against the AST_NODE_TYPES and AST_TOKEN_TYPES enums.

Using these can help avoid typos and maybe improve discoverability, though I think the main reason to do so is just consistency since it'd be a breaking change for a type value to actually change.

Regardless, it would be great if there was a linting rule to enforce using these instead of native strings, which I think would be make sense to live in this plugin even though it only applies when you're using @typescript-eslint/utils because:

  1. a handful of plugins do (eslint-plugin-jest, eslint-plugin-vitest, eslint-plugin-testing-library)
  2. this is the plugin for eslint plugins
  3. the implementation should be pretty lightweight

I'm happy to handle implementing the rule itself if folks are happy to have it here - my plan would be to have it import the enums from @typescript-eslint/utils within its create function and report any string literals whose value matches one of the enum values

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions