Repository navigation
fix(eslint-plugin-pnpm): support @eslint/json's json/json language for json rules - #39
Merged
antfu merged 1 commit intoAug 13, 2026
Conversation
…e for json rules The json-* rules assumed the sourceCode AST always came from jsonc-eslint-parser, indexing into it directly. When package.json is linted with @eslint/json's json/json language (as recommended when combining JSON linting with other json rules), the AST is produced by the Momoa parser instead, which has a different shape. This caused a crash: "Cannot read properties of undefined (reading 'expression')". Wrap rule create functions with eslint-json-compat-utils's toCompatCreate, which transparently adapts the jsonc-eslint-parser- shaped rules to also understand the json/json language's AST, so both setups work without crashing. Fixes made-in-common#38 This PR was created with the help of an agent.
3 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Linting
package.jsonwith@eslint/json'sjson/jsonlanguage alongsideeslint-plugin-pnpm'sjson-*rules (as recommended when you also want plain JSON linting) crashes:This happens because the
json-*rules assumedcontext.sourceCode.astalways has thejsonc-eslint-parsershape (Program -> body[0]: JSONExpressionStatement -> expression). When the file is linted through@eslint/json'sjson/jsonlanguage instead, the AST comes from the Momoa parser and has a completely different shape (Document -> body: Object -> members), so blindly indexing into it throws.Reproduced locally with the exact config from the issue (
@eslint/json+eslint-plugin-pnpmboth targetingpackage.json), confirming the reported stack trace.Fix
Wrap rule
createfunctions witheslint-json-compat-utils'stoCompatCreate. It detects whencontext.sourceCode.astis a Momoa/@eslint/jsonAST and transparently exposes ajsonc-eslint-parser-compatiblesourceCode/AST view (and converts fixes/reports back), so the existing rule implementations work unmodified. For files parsed the normal way (jsonc-eslint-parser, or non-JSON files), it's a no-op passthrough — confirmed no regressions in the existing test suite.Added a regression test (
json-language-compat.test.ts) that runs thejson-*rules through a realLinterconfigured with@eslint/json'sjson/jsonlanguage, verifying no crash, correct reporting/autofix, and that@eslint/json's own rules (e.g.json/no-duplicate-keys) keep working side by side.Fixes #38
This PR was created with the help of an agent.