Skip to content

Internal code suggestion: add explicit call signatures for RuleListener node types? #268

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

Closed
JoshuaKGoldberg opened this issue Oct 17, 2023 · 1 comment · Fixed by #269
Closed

Comments

@JoshuaKGoldberg
Copy link
Contributor

Found when looking into ota-meshi/jsonc-eslint-parser#184: this package's rules seem to completely ignore estree types, and instead replace node types with their own AST.JSON* types.

export interface RuleListener {
[key: string]: ((node: never) => void) | undefined;
}

JSONLiteral(node: AST.JSONLiteral) {

Would you be open to a PR that adds a few explicit call signatures that have a type for the RuleListener's node? We use this strategy in typescript-eslint to remove the need for most node: ... type annotations in our rules.

export interface RuleListener {
  JSONBinaryExpression: ((node: AST.JSONBinaryExpression) => void) | undefined;
  JSONLiteral: ((node: AST.JSONLiteral) => void) | undefined;
  // ...
  [key: string]: ((node: never) => void) | undefined;
}

In theory this could be automated with TypeScript type magicks. I haven't looked into it.

@ota-meshi
Copy link
Owner

Would you be open to a PR that adds a few explicit call signatures that have a type for the RuleListener's node? We use this strategy in typescript-eslint to remove the need for most node: ... type annotations in our rules.

Thank you for posting the issue!
Yeah, I think it would be useful to have that type annotations. I think it would be useful if jsonc-eslint-parser provided type annotations so that each plugin would be easier to use.

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 a pull request may close this issue.

2 participants