From b6a77873181bc75e46a9055bc2a20dd40fe6ed8c Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Thu, 16 Nov 2023 10:04:52 -0800 Subject: [PATCH] Remove `pyproject.toml` from fixtures directory (#8726) ## Summary This exists to power a test, but it ends up affecting the behavior of all files in the directory. Namely, it means that these files _aren't_ excluded when you format or lint them directly, since in that case, Ruff will fall back to looking at the `pyproject.toml` in `crates/ruff_linter/resources/test/fixtures`, which _doesn't_ exclude these files, unlike our top-level `pyproject.toml`. --- .../resources/test/fixtures/README.md | 3 -- .../resources/test/fixtures/pyproject.toml | 10 ------ crates/ruff_workspace/src/pyproject.rs | 34 +++++++++++++++---- 3 files changed, 28 insertions(+), 19 deletions(-) delete mode 100644 crates/ruff_linter/resources/test/fixtures/README.md delete mode 100644 crates/ruff_linter/resources/test/fixtures/pyproject.toml diff --git a/crates/ruff_linter/resources/test/fixtures/README.md b/crates/ruff_linter/resources/test/fixtures/README.md deleted file mode 100644 index 34ea3ac4d2..0000000000 --- a/crates/ruff_linter/resources/test/fixtures/README.md +++ /dev/null @@ -1,3 +0,0 @@ -# fixtures - -Fixture files used for snapshot testing. diff --git a/crates/ruff_linter/resources/test/fixtures/pyproject.toml b/crates/ruff_linter/resources/test/fixtures/pyproject.toml deleted file mode 100644 index 6a2564d488..0000000000 --- a/crates/ruff_linter/resources/test/fixtures/pyproject.toml +++ /dev/null @@ -1,10 +0,0 @@ -[tool.ruff] -line-length = 88 -extend-exclude = [ - "excluded_file.py", - "migrations", - "with_excluded_file/other_excluded_file.py", -] - -[tool.ruff.lint] -per-file-ignores = { "__init__.py" = ["F401"] } diff --git a/crates/ruff_workspace/src/pyproject.rs b/crates/ruff_workspace/src/pyproject.rs index 7080df65c9..5462fa6aec 100644 --- a/crates/ruff_workspace/src/pyproject.rs +++ b/crates/ruff_workspace/src/pyproject.rs @@ -152,10 +152,12 @@ pub fn load_options>(path: P) -> Result { #[cfg(test)] mod tests { + use std::fs; use std::str::FromStr; - use anyhow::Result; + use anyhow::{Context, Result}; use rustc_hash::FxHashMap; + use tempfile::TempDir; use ruff_linter::codes; use ruff_linter::line_width::LineLength; @@ -163,7 +165,6 @@ mod tests { use crate::options::{LintCommonOptions, LintOptions, Options}; use crate::pyproject::{find_settings_toml, parse_pyproject_toml, Pyproject, Tools}; - use crate::tests::test_resource_path; #[test] @@ -306,11 +307,32 @@ other-attribute = 1 #[test] fn find_and_parse_pyproject_toml() -> Result<()> { - let pyproject = find_settings_toml(test_resource_path("fixtures/__init__.py"))?.unwrap(); - assert_eq!(pyproject, test_resource_path("fixtures/pyproject.toml")); + let tempdir = TempDir::new()?; + let ruff_toml = tempdir.path().join("pyproject.toml"); + fs::write( + ruff_toml, + r#" +[tool.ruff] +line-length = 88 +extend-exclude = [ + "excluded_file.py", + "migrations", + "with_excluded_file/other_excluded_file.py", +] - let pyproject = parse_pyproject_toml(&pyproject)?; - let config = pyproject.tool.unwrap().ruff.unwrap(); +[tool.ruff.lint] +per-file-ignores = { "__init__.py" = ["F401"] } +"#, + )?; + + let pyproject = + find_settings_toml(tempdir.path())?.context("Failed to find pyproject.toml")?; + let pyproject = parse_pyproject_toml(pyproject)?; + let config = pyproject + .tool + .context("Expected to find [tool] field")? + .ruff + .context("Expected to find [tool.ruff] field")?; assert_eq!( config, Options {