fix: replace package.json JSON-parser check with native rule to avoid config merge issues - #145
Open
saberzero1 wants to merge 3 commits into
Open
fix: replace package.json JSON-parser check with native rule to avoid config merge issues#145saberzero1 wants to merge 3 commits into
saberzero1 wants to merge 3 commits into
Conversation
saberzero1
marked this pull request as ready for review
May 8, 2026 06:44
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.
Summary
Replaces the
{ files: ['package.json'], language: 'json/json' }config block with a nativeobsidianmd/no-banned-dependenciesrule that readspackage.jsonfrom disk. This eliminates the class of config-merge issues where consumers' global typed-linting configs leak onto package.json and crash typescript-eslint rules.Problem
The
recommendedconfig included a config block targetingpackage.jsonvia@eslint/jsonandeslint-plugin-depend. ESLint's flat config merging is by design — config objects withoutfilesare "universal" and apply to every matched file (eslint/eslint#20352, eslint/eslint#20354). When consumers write:ESLint merges the typed-linting setup onto
package.json, andtypescript-eslintrules crash because the JSON language processor doesn't provide TypeScript services. ThedisableTypeCheckedguard only disables the plugin's own type-aware rules — it cannot prevent the consumer's config from leaking.ESLint has explicitly rejected fixing this upstream (both issues closed as "works as intended").
Approach
The new
obsidianmd/no-banned-dependenciesrule:package.jsonfrom disk viafs.readFileSynconce per ESLint run (cached by resolved path)dependencies,devDependencies,peerDependencies, andoptionalDependenciesagainst the module-replacements banned lists (the same data sourceeslint-plugin-dependuses)native,microutilities,preferred) and adds an allowed option for whitelistingThis pattern is established in the ecosystem —
eslint-plugin-import/no-extraneous-dependenciesdoes exactly this.What changes for consumers
Nothing.
...obsidianmd.configs.recommendedcontinues to work as a one-liner. The banned-dependency check is now part ofrecommendedPluginRulesConfigand fires automatically. No config migration needed.Trade-off
Errors now report on the source file being linted rather than on the
package.jsonline itself. The message includes the dependency name and section (e.g.,"is-number" in dependencies should not be used. Use X instead.), so it's clear what to fix.Changes
obsidianmd/no-banned-dependencies(lib/rules/noBannedDependencies.ts)files: ['package.json']config block fromflatRecommendedConfig@eslint/jsonandeslint-plugin-dependas dependencies/peerDependenciesmodule-replacementsas a direct dependencytests/dependRules.test.ts(replaced by the new test file)