Skip to content

fix: enforce plugins gate for JS/TS config rule resolution#545

Merged
fansenze merged 1 commit intomainfrom
fix/plugins-gate-jsconfig-20260318
Mar 19, 2026
Merged

fix: enforce plugins gate for JS/TS config rule resolution#545
fansenze merged 1 commit intomainfrom
fix/plugins-gate-jsconfig-20260318

Conversation

@fansenze
Copy link
Copy Markdown
Contributor

@fansenze fansenze commented Mar 18, 2026

Summary

  • In JS/TS flat configs, plugin rules (e.g. @typescript-eslint/no-explicit-any) now require their corresponding plugin to be declared in plugins before they take effect. This aligns with ESLint's behavior where plugins must be registered before their rules can be used.
  • Core rules (no plugin prefix like no-debugger) are always active regardless of plugins declarations.
  • JSON config behavior is unchanged (no plugin enforcement). Fixed a bug where plugins: ["eslint-plugin-import"] in JSON config failed to inject import/ rules due to missing name normalization.
  • The TypeScript recommended preset (ts.configs.recommended) now includes plugins: ['@typescript-eslint'] so existing users are not affected.

Key changes:

Plugin registry (config.go)

  • Introduce KnownPlugins registry as single source of truth for all supported plugins, with RulePrefix, DeclNames (supports multiple aliases), and getAllRules
  • NormalizePluginName is now a lookup-table based function instead of string manipulation
  • Remove GetAllRulesForPlugin (no callers) and getAllTypeScriptEslintPluginRules (returned all rules, not just TS rules)

Plugin enforcement (rule_registry.go)

  • GetEnabledRules accepts enforcePlugins param (true for JS/TS configs, false for JSON)
  • MergedConfig tracks merged Plugins set from matching config entries
  • RulePluginPrefix extracts plugin prefix from rule names

Bug fix (loader.go)

  • normalizeJSONConfig now normalizes plugin names before calling GetPluginRules, fixing plugins: ["eslint-plugin-import"] failing to inject import/ rules

LSP (service.go)

  • getConfigForURI returns isJSConfig bool to thread plugin enforcement correctly

Preset (typescript.ts)

  • Add plugins: ['@typescript-eslint'] to the TS recommended preset

Test restructuring

  • Split Go tests into 4 files: config_merge_test.go, config_plugin_test.go, loader_normalize_test.go, rule_registry_test.go
  • Split E2E tests into js-config/ folder: helpers.ts, normalize-config.test.ts, load-config.test.ts, cli-integration.test.ts, plugin-enforcement.test.ts, presets.test.ts

Related Links

Fixes the issue where plugins: ["@typescript-eslint"] in JS/TS config had no effect — rules would work even without the plugin declaration, causing confusion.

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

@gemini-code-assist
Copy link
Copy Markdown

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@fansenze fansenze force-pushed the fix/plugins-gate-jsconfig-20260318 branch 9 times, most recently from 2c6bc6e to f706e46 Compare March 18, 2026 08:36
@fansenze fansenze requested a review from hardfist March 18, 2026 08:50
In JS/TS flat configs, plugin rules (e.g. `@typescript-eslint/no-explicit-any`)
now require their corresponding plugin to be declared in `plugins` before they
take effect. This aligns with ESLint's behavior where plugins must be registered
before their rules can be used.

Core changes:
- Add `Plugins` field to `MergedConfig` and merge plugins from matching entries
- Add `enforcePlugins` parameter to `GetEnabledRules` (true for JS/TS, false for JSON)
- Add `NormalizePluginName` and `RulePluginPrefix` helpers
- Add `plugins: ['@typescript-eslint']` to the TS recommended preset
- JSON config behavior is unchanged (no plugin enforcement)

Test restructuring:
- Split Go tests: config_merge_test.go, config_plugin_test.go,
  loader_normalize_test.go, rule_registry_test.go
- Split E2E tests: js-config/ folder with helpers, normalize-config,
  load-config, cli-integration, plugin-enforcement, presets
@fansenze fansenze force-pushed the fix/plugins-gate-jsconfig-20260318 branch from f706e46 to 1973746 Compare March 19, 2026 02:14
@fansenze fansenze merged commit 04ae489 into main Mar 19, 2026
14 checks passed
@fansenze fansenze deleted the fix/plugins-gate-jsconfig-20260318 branch March 19, 2026 03:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants