-
Notifications
You must be signed in to change notification settings - Fork 38
Description
Bug Report Checklist
- I have tried restarting my IDE and the issue persists.
- I have pulled the latest
mainbranch of the repository. - I have searched for related issues and found none that matched my issue.
Overview
Following #40 & #59 & ota-meshi/jsonc-eslint-parser#184: the current state of types for AST nodes in this plugin is that we've completely swapped out the built-in ESLint ones. Nodes are instead typed using import type { AST as JsonAST } from "jsonc-eslint-parser"; -> node: JsonAST.JSONProperty and the like.
Unfortunately, ESLint's APIs still expect ESTree nodes. So we end up with assertions any time we need to pass the nodes to ESLint's APIs:
eslint-plugin-package-json/src/rules/valid-repository-directory.ts
Lines 32 to 34 in 84035c3
| context.report({ | |
| messageId: "mismatched", | |
| node: directoryProperty.value as unknown as ESTree.Node, |
This isn't ideal. One workaround done by eslint-plugin-jsonc is to instead pass loc: node.loc. But I'd ideally like to be able to just pass the node directly.
Additional Info
I don't know a straightforward way to make this better. context.report is typed in @types/eslint as:
report(descriptor: ReportDescriptor): void;...with:
type ReportDescriptor = ReportDescriptorMessage & ReportDescriptorLocation & ReportDescriptorOptions;
type ReportDescriptorMessage = { message: string } | { messageId: string };
type ReportDescriptorLocation =
| { node: ESTree.Node }
| { loc: AST.SourceLocation | { line: number; column: number } };I suppose @types/eslint could mark the context with a type parameter like <Node = ESTree.Node> π¬... Eww.
Filed ota-meshi/jsonc-eslint-parser#198. Marking as blocked pending discussion there.