Skip to content

Support back-references with wildcards #109

@brettz9

Description

@brettz9

We have come across a few use cases in eslint-plugin-jsdoc for allowing users to provide their own esquery contexts to indicate language features where comment blocks should apply.

For one example, there is a user who would like to require jsdoc blocks above a getter/setter pair, but not above each getter/setter. While they can define their allowable contexts like:

[
  'MethodDefinition:not([kind="get"],[kind="set"])',
  'MethodDefinition[kind="get"]:not(MethodDefinition[kind="set"] + MethodDefinition[kind="get"])',
  'MethodDefinition[kind="set"]:not(MethodDefinition[kind="get"] + MethodDefinition[kind="set"])'
],

...this doesn't perform checking to ensure that the getter preceded by a setter (or vice versa) that we are avoiding including is of the same name.

I would think that some kind of wildcard + backreference scheme such as:

'MethodDefinition[kind="set"]:not(MethodDefinition[kind="get"][key.name=(*)] + MethodDefinition[kind="set"][key.name="\\1"])'

...might help us solve these kinds of problems (the wildcard being necessary as the user doesn't know the method names in advance).

(Another use case we have currently is for only requiring docs on the top of a sequence of adjacent TSDeclareFunction's.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions