From dda469eb2d6a9d2c18bd434a5204d3d7a1ce32af Mon Sep 17 00:00:00 2001 From: Jane Lewis Date: Thu, 1 Feb 2024 13:17:50 -0800 Subject: [PATCH 1/3] Fetch the correct preview settings for output formatting --- crates/ruff/src/lib.rs | 4 +++- crates/ruff/tests/integration_test.rs | 29 +++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/crates/ruff/src/lib.rs b/crates/ruff/src/lib.rs index 38fdcb8c4eea7..f3bc1ffd6ed0d 100644 --- a/crates/ruff/src/lib.rs +++ b/crates/ruff/src/lib.rs @@ -321,7 +321,9 @@ pub fn check(args: CheckCommand, log_level: LogLevel) -> Result { printer_flags, ); - let preview = overrides.preview.unwrap_or_default().is_enabled(); + // the settings should already be combined with the CLI overrides at this point + // TODO(jane): let's make this `PreviewMode` + let preview = pyproject_config.settings.linter.preview.is_enabled(); if cli.watch { if output_format != SerializationFormat::default(preview) { diff --git a/crates/ruff/tests/integration_test.rs b/crates/ruff/tests/integration_test.rs index b794495d1fd80..288a95de97c5e 100644 --- a/crates/ruff/tests/integration_test.rs +++ b/crates/ruff/tests/integration_test.rs @@ -755,6 +755,35 @@ fn full_output_preview() { "###); } +#[test] +fn full_output_preview_config() { + let tempdir = TempDir::new().unwrap(); + let pyproject_toml = tempdir.path().join("pyproject.toml"); + fs::write( + &pyproject_toml, + r#" +[tool.ruff] +preview = true +"#, + ) + .unwrap(); + let mut cmd = RuffCheck::default().config(&pyproject_toml).build(); + assert_cmd_snapshot!(cmd.pass_stdin("l = 1"), @r###" + success: false + exit_code: 1 + ----- stdout ----- + -:1:1: E741 Ambiguous variable name: `l` + | + 1 | l = 1 + | ^ E741 + | + + Found 1 error. + + ----- stderr ----- + "###); +} + #[test] fn full_output_format() { let mut cmd = RuffCheck::default().output_format("full").build(); From ef346027676f2ab2bc8b862dcf122e098f405fb3 Mon Sep 17 00:00:00 2001 From: Jane Lewis Date: Thu, 1 Feb 2024 13:30:31 -0800 Subject: [PATCH 2/3] Add additional TODO to reference the global preview mode after #8232 gets solved --- crates/ruff/src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/crates/ruff/src/lib.rs b/crates/ruff/src/lib.rs index f3bc1ffd6ed0d..303703ad6b3b6 100644 --- a/crates/ruff/src/lib.rs +++ b/crates/ruff/src/lib.rs @@ -323,6 +323,8 @@ pub fn check(args: CheckCommand, log_level: LogLevel) -> Result { // the settings should already be combined with the CLI overrides at this point // TODO(jane): let's make this `PreviewMode` + // TODO: this should reference the global preview mode once https://github.com/astral-sh/ruff/issues/8232 + // is resolved. let preview = pyproject_config.settings.linter.preview.is_enabled(); if cli.watch { From 1c12457ed0480612073bf462cedad8986582c7f1 Mon Sep 17 00:00:00 2001 From: Jane Lewis Date: Thu, 1 Feb 2024 13:34:48 -0800 Subject: [PATCH 3/3] Use ? over .unwrap() in integration test --- crates/ruff/tests/integration_test.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/crates/ruff/tests/integration_test.rs b/crates/ruff/tests/integration_test.rs index 288a95de97c5e..f9e9c221acdd5 100644 --- a/crates/ruff/tests/integration_test.rs +++ b/crates/ruff/tests/integration_test.rs @@ -756,8 +756,8 @@ fn full_output_preview() { } #[test] -fn full_output_preview_config() { - let tempdir = TempDir::new().unwrap(); +fn full_output_preview_config() -> Result<()> { + let tempdir = TempDir::new()?; let pyproject_toml = tempdir.path().join("pyproject.toml"); fs::write( &pyproject_toml, @@ -765,8 +765,7 @@ fn full_output_preview_config() { [tool.ruff] preview = true "#, - ) - .unwrap(); + )?; let mut cmd = RuffCheck::default().config(&pyproject_toml).build(); assert_cmd_snapshot!(cmd.pass_stdin("l = 1"), @r###" success: false @@ -782,6 +781,7 @@ preview = true ----- stderr ----- "###); + Ok(()) } #[test]