Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix docs and add overlap test for negated per-file-ignores #10863

Merged
merged 4 commits into from Apr 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 36 additions & 0 deletions crates/ruff/tests/lint.rs
Expand Up @@ -1248,3 +1248,39 @@ fn negated_per_file_ignores_absolute() -> Result<()> {
});
Ok(())
}

/// patterns are additive, can't use negative patterns to "un-ignore"
carljm marked this conversation as resolved.
Show resolved Hide resolved
#[test]
fn negated_per_file_ignores_overlap() -> Result<()> {
let tempdir = TempDir::new()?;
let ruff_toml = tempdir.path().join("ruff.toml");
fs::write(
&ruff_toml,
r#"
[lint.per-file-ignores]
"*.py" = ["RUF"]
"!foo.py" = ["RUF"]
"#,
)?;
let foo_file = tempdir.path().join("foo.py");
fs::write(foo_file, "")?;
let bar_file = tempdir.path().join("bar.py");
fs::write(bar_file, "")?;

assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
.args(STDIN_BASE_OPTIONS)
.arg("--config")
.arg(&ruff_toml)
.arg("--select")
.arg("RUF901")
.current_dir(&tempdir)
, @r###"
success: true
exit_code: 0
----- stdout -----
All checks passed!

----- stderr -----
"###);
Ok(())
}
2 changes: 1 addition & 1 deletion crates/ruff_workspace/src/options.rs
Expand Up @@ -916,7 +916,7 @@ pub struct LintCommonOptions {
"__init__.py" = ["E402"]
"path/to/file.py" = ["E402"]
# Ignore `D` rules everywhere except for the `src/` directory.
"!src/**.py" = ["F401"]
"!src/**.py" = ["D"]
"#
)]
pub per_file_ignores: Option<FxHashMap<String, Vec<RuleSelector>>>,
Expand Down