Skip to content

[utils] Use template literal types to parse esquery selectors to automatically type complex selectors #4065

Open
@bradzacher

Description

@bradzacher

Template literal types (https://www.typescriptlang.org/docs/handbook/2/template-literal-types.html) were released in TS 4.1. since their announcement people have done all sorts of crazy and wonderful things with them - from simple cases like auto prefixing keys to ridiculous things like SQL query parsers.

We should be able to leverage them as part of our ESLint types to automatically type the node argument of an ESLint rule selector.

We don't need to handle every crazy case (selectors can get pretty complicated!) but at least handling things like property existence checks, sibling checks, and the :exit special selector would be great.

For reference here are the docs on, and implementation of esquery selectors
https://github.com/estools/esquery

It's worth mentioning that if we find that template literal types are too slow or complex, an alternative might be to consider using codegen to generate a number of common cases statically. But I'd love to achieve this using template literal types if possible!

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issueenhancementNew feature or requestpackage: utilsIssues related to the @typescript-eslint/utils package

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy