Skip to content

Rule banning complex ESQuery selectors #339

Open
@JoshuaKGoldberg

Description

@JoshuaKGoldberg

Moving discussion from typescript-eslint/typescript-eslint#6444 (comment) here, and quoting @bradzacher:

now a days though I tend to feel that leaning too heavily into the custom DSL makes code less accessible and harder to understand / debug.
[specifiers.0] is one of those parts of the DSL that's super unclear as to what it's doing, IMO.

I think leveraging super clear parts of the DSL (prop existence, parents) are great and easy to understand, but for anything more complex it's better to write the clearer logic.

Is there any consensus/desire here to limit ESQuery node types?

Proposed "bad":

return {
  ImportDeclaration[importKind!="type"][specifiers.0](node) {
}

Proposed "good":

return {
  ImportDeclaration[importKind!="type"](node) {
    if (!node.specifiers.length) {
      return;
    }
}

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