Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(unstable): add lint plugin ast types #27977

Merged
merged 4 commits into from
Feb 6, 2025
Merged

Conversation

marvinhagemeister
Copy link
Contributor

@marvinhagemeister marvinhagemeister commented Feb 5, 2025

  • Add type definition for all TSEstree AST nodes in the JS lint plugin system
    - Fix deviations from TSEStree

Decided to split this PR up into two ones so that this one only has the type changes. The TSEStree fixes are here #27996

@marvinhagemeister marvinhagemeister added this to the 2.2.0 milestone Feb 5, 2025
export interface YieldExpression extends AstBase {
type: "YieldExpression";
delegate: boolean;
argument: Expression | null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems sometimes we use | undefined and other times | null. Should we consolidate on one or is this for a certain reason?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In TSEStree they use null as an empty value for all non-type nodes and undefined as an empty value for type nodes. It's a little weird.

Copy link
Member

@dsherret dsherret left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@marvinhagemeister marvinhagemeister merged commit 89b1969 into main Feb 6, 2025
18 checks passed
@marvinhagemeister marvinhagemeister deleted the lint-plugin-types2 branch February 6, 2025 20:45
marvinhagemeister added a commit that referenced this pull request Feb 6, 2025
This PR fixes deviations in our AST format compared to TSEStree. They
are mostly a leftover for when I first started working on it and based
it off of babel instead.

One of the key changes why the changeset is a bit bigger is that
TSEStree uses `undefined` instead of `null` as the empty value for type
nodes. This is likely influenced by `tsc` which use `undefined`
everywhere. The rest of the nodes use `null` though. It's a little
weird, but for now it might be better to align.

(extracted from #27977)
marvinhagemeister added a commit that referenced this pull request Feb 7, 2025
This PR strongly types the JS plugin visitor.

```ts
export default {
  name: "foo",
  rules: {
    bar: {
      create(ctx) {
        return {
          // Plain ast node visitor
          Identifier(node) {},

          // Exit visitor
          "Identifier:exit"(node) {},

          // Custom selectors, `node` needs to be typed manually
          "FunctionDeclaration > Identifier"(node: Deno.lint.Identifier) {}
        }
      }
    }
  }
}

```

Follow up to #27977
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants