-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update
ruff check
and ruff format
to default to the current direc…
…tory (#8791) Closes #7347 Closes #3970 via use of `include` We could update examples in our documentation, but I worry since we do not have versioned documentation users on older versions would be confused. Instead, I'll open an issue to track updating use of `ruff check .` in the documentation sometime in the future.
- Loading branch information
Showing
16 changed files
with
286 additions
and
22 deletions.
There are no files selected for viewing
Empty file.
Empty file.
Empty file.
2 changes: 2 additions & 0 deletions
2
crates/ruff_cli/resources/test/fixtures/include-test/nested-project/pyproject.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[tool.ruff] | ||
select = [] |
2 changes: 2 additions & 0 deletions
2
crates/ruff_cli/resources/test/fixtures/include-test/pyproject.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[tool.ruff] | ||
include = ["a.py", "subdirectory/c.py"] |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
#![cfg(not(target_family = "wasm"))] | ||
|
||
use std::path::Path; | ||
use std::process::Command; | ||
use std::str; | ||
|
||
use insta_cmd::{assert_cmd_snapshot, get_cargo_bin}; | ||
const BIN_NAME: &str = "ruff"; | ||
|
||
#[cfg(not(target_os = "windows"))] | ||
const TEST_FILTERS: &[(&str, &str)] = &[(".*/resources/test/fixtures/", "[BASEPATH]/")]; | ||
#[cfg(target_os = "windows")] | ||
const TEST_FILTERS: &[(&str, &str)] = &[ | ||
(r".*\\resources\\test\\fixtures\\", "[BASEPATH]\\"), | ||
(r"\\", "/"), | ||
]; | ||
|
||
#[test] | ||
fn check_project_include_defaults() { | ||
// Defaults to checking the current working directory | ||
// | ||
// The test directory includes: | ||
// - A pyproject.toml which specifies an include | ||
// - A nested pyproject.toml which has a Ruff section | ||
// | ||
// The nested project should all be checked instead of respecting the parent includes | ||
|
||
insta::with_settings!({ | ||
filters => TEST_FILTERS.to_vec() | ||
}, { | ||
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) | ||
.args(["check", "--show-files"]).current_dir(Path::new("./resources/test/fixtures/include-test")), @r###" | ||
success: true | ||
exit_code: 0 | ||
----- stdout ----- | ||
[BASEPATH]/include-test/a.py | ||
[BASEPATH]/include-test/nested-project/e.py | ||
[BASEPATH]/include-test/nested-project/pyproject.toml | ||
[BASEPATH]/include-test/subdirectory/c.py | ||
----- stderr ----- | ||
"###); | ||
}); | ||
} | ||
|
||
#[test] | ||
fn check_project_respects_direct_paths() { | ||
// Given a direct path not included in the project `includes`, it should be checked | ||
|
||
insta::with_settings!({ | ||
filters => TEST_FILTERS.to_vec() | ||
}, { | ||
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) | ||
.args(["check", "--show-files", "b.py"]).current_dir(Path::new("./resources/test/fixtures/include-test")), @r###" | ||
success: true | ||
exit_code: 0 | ||
----- stdout ----- | ||
[BASEPATH]/include-test/b.py | ||
----- stderr ----- | ||
"###); | ||
}); | ||
} | ||
|
||
#[test] | ||
fn check_project_respects_subdirectory_includes() { | ||
// Given a direct path to a subdirectory, the include should be respected | ||
|
||
insta::with_settings!({ | ||
filters => TEST_FILTERS.to_vec() | ||
}, { | ||
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) | ||
.args(["check", "--show-files", "subdirectory"]).current_dir(Path::new("./resources/test/fixtures/include-test")), @r###" | ||
success: true | ||
exit_code: 0 | ||
----- stdout ----- | ||
[BASEPATH]/include-test/subdirectory/c.py | ||
----- stderr ----- | ||
"###); | ||
}); | ||
} | ||
|
||
#[test] | ||
fn check_project_from_project_subdirectory_respects_includes() { | ||
// Run from a project subdirectory, the include specified in the parent directory should be respected | ||
|
||
insta::with_settings!({ | ||
filters => TEST_FILTERS.to_vec() | ||
}, { | ||
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME)) | ||
.args(["check", "--show-files"]).current_dir(Path::new("./resources/test/fixtures/include-test/subdirectory")), @r###" | ||
success: true | ||
exit_code: 0 | ||
----- stdout ----- | ||
[BASEPATH]/include-test/subdirectory/c.py | ||
----- stderr ----- | ||
"###); | ||
}); | ||
} |
Oops, something went wrong.