Skip to content

Commit 148b64e

Browse files
authored
Fix issue where output format mode would not change to full if preview mode was set in configuration file (#9763)
## Summary This was causing build failures for #9599. We were referencing the command line overrides instead of the merged configuration data, hence the issue. ## Test Plan A snapshot test was added.
1 parent 99eddbd commit 148b64e

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

crates/ruff/src/lib.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,11 @@ pub fn check(args: CheckCommand, log_level: LogLevel) -> Result<ExitStatus> {
321321
printer_flags,
322322
);
323323

324-
let preview = overrides.preview.unwrap_or_default().is_enabled();
324+
// the settings should already be combined with the CLI overrides at this point
325+
// TODO(jane): let's make this `PreviewMode`
326+
// TODO: this should reference the global preview mode once https://github.com/astral-sh/ruff/issues/8232
327+
// is resolved.
328+
let preview = pyproject_config.settings.linter.preview.is_enabled();
325329

326330
if cli.watch {
327331
if output_format != SerializationFormat::default(preview) {

crates/ruff/tests/integration_test.rs

+29
Original file line numberDiff line numberDiff line change
@@ -755,6 +755,35 @@ fn full_output_preview() {
755755
"###);
756756
}
757757

758+
#[test]
759+
fn full_output_preview_config() -> Result<()> {
760+
let tempdir = TempDir::new()?;
761+
let pyproject_toml = tempdir.path().join("pyproject.toml");
762+
fs::write(
763+
&pyproject_toml,
764+
r#"
765+
[tool.ruff]
766+
preview = true
767+
"#,
768+
)?;
769+
let mut cmd = RuffCheck::default().config(&pyproject_toml).build();
770+
assert_cmd_snapshot!(cmd.pass_stdin("l = 1"), @r###"
771+
success: false
772+
exit_code: 1
773+
----- stdout -----
774+
-:1:1: E741 Ambiguous variable name: `l`
775+
|
776+
1 | l = 1
777+
| ^ E741
778+
|
779+
780+
Found 1 error.
781+
782+
----- stderr -----
783+
"###);
784+
Ok(())
785+
}
786+
758787
#[test]
759788
fn full_output_format() {
760789
let mut cmd = RuffCheck::default().output_format("full").build();

0 commit comments

Comments
 (0)