ota-meshi / eslint-plugin-jsonc

ESLint plugin for JSON(C|5)? files
https://ota-meshi.github.io/eslint-plugin-jsonc/
MIT License
181 stars 17 forks source link

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

Closed JoshuaKGoldberg closed 8 months ago

JoshuaKGoldberg commented 8 months ago

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

https://github.com/ota-meshi/eslint-plugin-jsonc/blob/247c013126fbbaa8eb169527c7b5cdf8e8987bab/lib/types.ts#L3-L5

https://github.com/ota-meshi/eslint-plugin-jsonc/blob/247c013126fbbaa8eb169527c7b5cdf8e8987bab/lib/rules/no-bigint-literals.ts#L25

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 commented 8 months ago

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.