Skip to content

fix(linter): apply CLI severity filters to JS plugin rules - #26668

Open
nathan-gage wants to merge 8 commits into
oxc-project:mainfrom
nathan-gage:fix/js-plugin-cli-severity-filters
Open

nathan-gage wants to merge 8 commits into
oxc-project:mainfrom
nathan-gage:fix/js-plugin-cli-severity-filters

Conversation

@nathan-gage

Copy link
Copy Markdown

Closes #22730

Cherry-picks the change from #23336 (withdrawn by its author), preserving its authorship, plus fixes for problems found while testing it.

Summary

-A/-W/-D <plugin>/<rule> now reach rules from jsPlugins, the same way they reach built-in rules:

  • -D custom/rule enables a plugin rule the config never mentioned.
  • -D/-W on a configured plugin rule changes its severity and keeps its options.
  • -A custom/rule removes a configured plugin rule.
  • Plugin names resolve like config keys: -D eslint-plugin-custom/rule, -D custom/rule, and -D @scope/custom/rule all work.
  • A filter only enables a JS rule in configs whose jsPlugins declare that plugin — the same bound config.plugins puts on built-in rules. With nested configs, -D custom/rule applies where custom is declared and nowhere else.
  • --print-config lists JS plugin rules, and its array-form rule values now round-trip.

These filters change base rule configuration; matching file overrides keep their existing precedence, as for built-in rules. Unqualified names (-D rule), categories, and all still only address built-in rules.

Root cause

ConfigStoreBuilder::with_filter only upserted into the built-in rule map. external_rules is filled by OxlintRules::override_rules from the config file, and the CLI path never touched it, so -D custom/rule was silently dropped.

Changes

  • with_filters / with_filter take &ExternalPluginStore and resolve plugin/rule filters against it, after the same normalization parse_rule_key applies to config keys (unalias_plugin_name). Callers (lint.rs, config_loader.rs, the category loop in from_oxlintrc) pass the store they already have. fix(linter): apply CLI severity filters to JS plugin rules #23336 added a parallel with_filters_and_external_rules; folded into the existing methods instead.
  • ExternalPluginStore is shared by every config in a run, so a bare lookup would also find plugins other configs loaded, and which configs picked up -D custom/rule depended on load order. The builder now records the plugin ids its base config declares (load_external_plugin returns the id; the store maps plugin path → id and rule → plugin) and filters only enable rules from those.
  • LintFilterKind::parse splits scoped plugin names at the last /, matching parse_rule_key. Fixes -D @scope/plugin/rule for JS plugins and, incidentally, -D @next/next/<rule> for the built-in nextjs plugin.
  • --print-config includes JS plugin rules (resolve_final_config_file takes the store; ExternalPluginStore::options added to read options back). Previously only built-in rules were serialized, so a CLI-enabled plugin rule looked like a no-op.
  • OxlintRules serialized array-form rules as [severity, [options]], which parse_rule_value reads back as one nested option, so --print-config output did not round-trip. Now [severity, ...options], as the JSON schema already describes. The ban_rules print-config snapshot changes accordingly.

with_filter(s), resolve_final_config_file, register_plugin, and is_plugin_registered (now registered_plugin_id) change signature; oxc_linter is publish = false and all in-repo callers are updated.

Tests

Unit: test_filter_external_rule (enable from CLI, prefixed plugin name, undeclared plugin ignored, severity change keeping options, allow, unknown name), test_print_config_includes_external_rules, test_serialize_roundtrip, scoped cases in LintFilterKind test_parse.

E2E fixtures: js_plugin_cli_filter (from #23336, now with an option the rule reports: warn → error, option kept), js_plugin_cli_filter_enable, js_plugin_cli_filter_allow, js_plugin_cli_filter_scoped, js_plugin_cli_filter_prefixed, js_plugin_cli_filter_nested (root + three sibling configs, one declaring the plugin), js_plugin_cli_filter_print_config.

Ran cargo test -p oxc_linter, cargo test -p oxlint, cargo lint on oxc_linter and its workspace dependents, just doc flags on both crates, typos, oxfmt --check, and pnpm --filter oxlint-app build-test && pnpm --filter oxlint-app test.

AI assistance

Prepared with AI assistance; reviewed and tested by me.

@camc314 camc314 added the A-linter Area - Linter (oxlint): rules, config, diagnostics, fixes. Add L-* labels for details label Sep 16, 2026
@github-actions github-actions Bot added A-cli Area - oxlint / oxfmt common CLI behavior: flags, ignore files, oxc_config L-js-plugins Linter > JS plugins (ESLint-compatible plugin API) labels Oct 14, 2026
@FLPPPPPP

FLPPPPPP commented Nov 7, 2026

Copy link
Copy Markdown

This PR's OxlintRules serializer change ([severity, ...options], with test_serialize_roundtrip) addresses #28972: on 1.92.0 the --print-config output fails to load with -c, and for some rules it loads but silently drops the options.

That part looks independent of the JS-plugin severity filters. Would you consider splitting it into its own PR, so it can be reviewed and land separately?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-cli Area - oxlint / oxfmt common CLI behavior: flags, ignore files, oxc_config A-linter Area - Linter (oxlint): rules, config, diagnostics, fixes. Add L-* labels for details L-js-plugins Linter > JS plugins (ESLint-compatible plugin API)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

linter: CLI -D does not override severity for jsPlugins rules

4 participants