-
-
Notifications
You must be signed in to change notification settings - Fork 4
Description
Before You File a Bug Report Please Confirm You Have Done The Following...
- I'm using eslint-plugin-jsonc. (
*.json
file linting does not work with the parser alone. You should also use eslint-plugin-jsonc with it.) - I'm sure the problem is a parser problem. (If you are not sure, search for the issue in eslint-plugin-jsonc repo and open the issue in eslint-plugin-jsonc repo if there is no solution.
- I have tried restarting my IDE and the issue persists.
- I have updated to the latest version of the packages.
What version of ESLint are you using?
9.34.0
What version of eslint-plugin-jsonc
and jsonc-eslint-parser
are you using?
- jsonc-eslint-parser@2.4.0
What did you do?
Coming from JoshuaKGoldberg/eslint-plugin-package-json#1242 (comment), we're using the types from jsonc-eslint-parser
as part of the types for our eslint-plugin-package-json
(which uses the parser in its configs), and users have reported that when shifting from TSEslint's config
function to ESLint's built-in defineConfig
function for creating a config, the type of our plugin is incompatible. I've traced it down to an incompatibility with the RuleListener
exported from this package, and the NodeListener
/ RuleVisitor
that ESLint
expects as the return type for a create
function.
Tangentially, I think you'll have a similar issue with the eslint-plugin-jsonc
package, as it's setting the types up in a similar way: https://github.com/ota-meshi/eslint-plugin-jsonc/blob/master/lib/types.ts#L34
What did you expect to happen?
I found that if we swap in eslint's NodeListener
, in place of RuleListener
, it resolved the type issue on our side, but we lost some of the type inference that this package's type provided. So, we were thinking it might be more appropriate to address the issue here, rather than working around it downstream.
What actually happened?
This is an example of the type error
Type '{ configs: { "legacy-recommended": { plugins: string[]; rules: { "package-json/valid-package-definition": ["error", { ignoreProperties: string[]; }]; }; }; recommended: { files: string[]; languageOptions: { ...; }; name: string; plugins: { ...; }; rules: { ...; }; }; }; meta: { ...; }; rules: Record<...>; }' is not assignable to type 'Plugin'.
Types of property 'rules' are incompatible.
Type 'Record<string, PackageJsonRuleModule<unknown[]>>' is not assignable to type 'Record<string, RuleDefinition<RuleDefinitionTypeOptions>>'.
'string' index signatures are incompatible.
Type 'PackageJsonRuleModule<unknown[]>' is not assignable to type 'RuleDefinition<RuleDefinitionTypeOptions>'.
The types returned by 'create(...)' are incompatible between these types.
Type 'RuleListener' is not assignable to type 'RuleVisitor'.
'string' index signatures are incompatible.
Type 'RuleFunction<never> | undefined' is not assignable to type '((...args: any[]) => void) | undefined'.
Type 'RuleFunction<never>' is not assignable to type '(...args: any[]) => void'.
Types of parameters 'node' and 'args' are incompatible.
Type 'any' is not assignable to type 'never'.ts(2322)
Link to GitHub Repo with Minimal Reproducible Example
https://github.com/JoshuaKGoldberg/eslint-plugin-package-json
Additional comments
No response