Skip to content

fix(linter): print [severity, ...options] in --print-config - #28994

Closed
FLPPPPPP wants to merge 1 commit into
oxc-project:mainfrom
FLPPPPPP:fix/print-config-rule-options-roundtrip
Closed

FLPPPPPP wants to merge 1 commit into
oxc-project:mainfrom
FLPPPPPP:fix/print-config-rule-options-roundtrip

Conversation

@FLPPPPPP

@FLPPPPPP FLPPPPPP commented Nov 7, 2026

Copy link
Copy Markdown

Closes #28972.

OxlintRules serialized array-form rule values as a 2-tuple of the severity and the whole options list, so --print-config printed ["deny", [options...]] instead of ["deny", ...options]. parse_rule_value reads everything after the severity as the options, so the printed value came back as one nested option. Most rules with options then refused the printed config (invalid type: ...), and some loaded it and silently dropped their options (max-statements, no-restricted-globals, no-inner-declarations, no-magic-numbers).

This serializes the flat [severity, ...options] form, the shape the config schema describes, and adds a round-trip test. The ban_rules print-config snapshot changes from ["deny", ["always"]] to ["deny", "always"]. Only --print-config output changes, since it is the only place OxlintRules is serialized.

The serializer change and the test are taken from #26668 by @nathan-gage (credited as co-author), where they are bundled with the JS-plugin CLI severity filters. I asked in #26668 whether this part could be split out; this PR carries only the fix so it can be reviewed on its own. Happy to close it if you would rather land it through #26668. Note that #26143 has tests and fixtures that expect the nested shape, so whichever of the two lands second needs to update them.

Not covered here, and already wrong before this change (in what resolve_final_config_file prints, not how): options of rules that come from extends, options of TypeScript-adapted ESLint rules configured with the typescript/ or @typescript-eslint/ prefix (looked up under the plain rule name, so they print as a bare severity), settings outside the typed built-in blocks (#22117), and CLI filters such as -A/-D.

Tested on Windows 11:

  • cargo test -p oxc_linter --all-features passes. The new test_serialize_roundtrip fails without the serializer change.
  • cargo clippy -p oxc_linter --all-targets --all-features with warnings denied, and cargo fmt --check, pass.
  • cargo test -p oxlint -- print_config passes with the updated snapshot. The rest of cargo test -p oxlint gives the same results with and without this change on this machine: failures in tests that need oxlint-tsgolint, symlinks or a JS runtime, plus one lint::suppression test that aborts the test process on Windows either way.
  • With the built oxlint binary, --print-config followed by -c <printed file> gives the same diagnostics and exit code as the original config for max-params, max-statements, no-console, eqeqeq (one and two options), no-restricted-globals, no-inner-declarations, no-magic-numbers, no-empty and max-params inside overrides, and, with oxlint-tsgolint 7.0.2006 running, for type-aware typescript/restrict-template-expressions and typescript/no-floating-promises with options.

AI disclosure: I used an AI coding assistant to prepare this change and this description. The tests and checks above were run locally.

`OxlintRules` serialized array-form rule values as a 2-tuple of the
severity and the whole options list, so `--print-config` printed
`["deny", [options...]]` instead of `["deny", ...options]`.
`parse_rule_value` reads everything after the severity as the options,
so the printed value came back as one nested option. Most rules with
options then refused the printed config, and some (max-statements,
no-restricted-globals, no-inner-declarations, no-magic-numbers) loaded
it and silently dropped their options.

Serialize the flat `[severity, ...options]` form instead, which is the
shape the config schema describes, and add a round-trip test. The
ban_rules print-config snapshot changes from `["deny", ["always"]]` to
`["deny", "always"]`.

The serializer change and the test come from oxc-project#26668.

Closes oxc-project#28972

Co-authored-by: Nathan Gage <54559789+nathan-gage@users.noreply.github.com>
@FLPPPPPP
FLPPPPPP requested a review from camc314 as a code owner November 7, 2026 17:54
@FLPPPPPP

Copy link
Copy Markdown
Author

Closing this one: #29531 landed the same serializer change (--print-config now writes [severity, ...options]) and closed #28972. Thanks for fixing it.

@FLPPPPPP FLPPPPPP closed this Nov 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

linter: --print-config wraps rule options in an extra array; the output fails to load with -c or silently drops options

1 participant