Skip to content

Types: Allow passing JsonAST nodes directly to ESLint context APIsΒ #198

@JoshuaKGoldberg

Description

@JoshuaKGoldberg

Description

Following #184 -> #186: I'm still finding that I need to do some massaging of TypeScript types. Also filed in JoshuaKGoldberg/eslint-plugin-package-json#125.

The current state of types for AST nodes in eslint-plugin-package-json 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:

context.report({ 
  messageId: "mismatched", 
  node: node 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.

Is this something we can solve at the parser level in jsonc-eslint-parser? Slash, maybe we should modify @types/eslint in some way to make the context generic (per JoshuaKGoldberg/eslint-plugin-package-json#125 additional info)?

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions