feat: support --rule CLI flag for runtime rule overrides#603
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces the --rule CLI flag, allowing users to override or add linting rules directly from the command line using an ESLint-compatible format. The implementation includes a new repeatedFlag type in the Go command-line interface to handle multiple occurrences of the flag, a parsing utility for rule configurations (supporting both simple severity strings and complex JSON arrays), and logic to merge these overrides into the existing configuration. Additionally, the JavaScript argument parser was updated to ensure flags are reordered before positional arguments, preventing them from being ignored by Go's flag parser. Comprehensive unit, integration, and CLI tests have been added to verify the new functionality. I have no feedback to provide as the implementation is robust and well-tested.
Deploying rslint with
|
| Latest commit: |
57f7e4c
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://f648e106.rslint.pages.dev |
| Branch Preview URL: | https://feat-cli-rule-flag-20260407.rslint.pages.dev |
a618314 to
1c0e0ee
Compare
Add ESLint-compatible --rule flag that allows overriding rule severity and options from the command line without modifying config files. Syntax: --rule 'ruleName: severity' or --rule 'ruleName: [severity, options]' Multiple --rule flags supported, later overrides earlier for same rule. Implementation injects a synthetic ConfigEntry (no files = matches all) at the end of the config array, leveraging existing merge semantics for highest precedence with zero changes to core config/linter logic. JS side registers rule as a known string flag and reorders flags before positional args to work around Go's flag.Parse stopping at the first positional argument. Option-terminator (--) position is preserved.
d5ec8f2 to
57f7e4c
Compare
Summary
Add ESLint-compatible
--ruleCLI flag that allows overriding rule severity and options from the command line without modifying config files.Syntax:
Implementation:
internal/config/cli_rules.go—ParseCLIRuleFlagparses--rulevalues (severity or JSON array with options),BuildCLIRuleEntrybuilds a syntheticConfigEntrywith nofilesfield (matches all files)cmd/rslint/cmd.go—repeatedFlagtype for multiple--rule, synthetic entry appended to config array end (both single and multi-config/monorepo)packages/rslint/src/utils/args.ts— registersruleas known string flag (multiple: true), reorders flags before positional args (Go'sflag.Parsestops at first positional), preserves--option-terminator positionwebsite/docs/en/guide/cli.md— CLI reference updated with--ruleflag and "Rule Overrides" sectionZero changes to core config merging (
GetConfigForFile) or linter logic (GetEnabledRules).Tests:
internal/config/cli_rules_test.go— 30 Go unit tests (parsing, whitespace, nested JSON options, construction, integration with config merge)packages/rslint/tests/args.test.ts— 17 JS unit tests (rest ordering,--rulereordering,--terminator handling)packages/rslint-test-tools/tests/cli/rule-flag.test.ts— 36 e2e tests using JS config (basic usage, severity/options override, ordering matrix, multi-rule × flag cross, whitespace variations, error handling,--terminator, plugin rules, per-file override)Related Links
Design aligned with ESLint v10's
--ruleflag behavior.Checklist