mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-30 22:01:47 +00:00
Respect per-file-ignores for RUF100 with no other diagnostics (#11058)
## Summary The existing test didn't cover the case in which there are _no_ other diagnostics in the file. Closes https://github.com/astral-sh/ruff/issues/10906.
This commit is contained in:
parent
c80b9a4a90
commit
d544199272
3 changed files with 29 additions and 1 deletions
|
@ -265,7 +265,13 @@ pub fn check_path(
|
|||
}
|
||||
|
||||
// Ignore diagnostics based on per-file-ignores.
|
||||
let per_file_ignores = if !diagnostics.is_empty() && !settings.per_file_ignores.is_empty() {
|
||||
let per_file_ignores = if (!diagnostics.is_empty()
|
||||
|| settings
|
||||
.rules
|
||||
.iter_enabled()
|
||||
.any(|rule_code| rule_code.lint_source().is_noqa()))
|
||||
&& !settings.per_file_ignores.is_empty()
|
||||
{
|
||||
fs::ignores_from_path(path, &settings.per_file_ignores)
|
||||
} else {
|
||||
RuleSet::empty()
|
||||
|
|
|
@ -252,6 +252,24 @@ mod tests {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ruff_per_file_ignores_empty() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
Path::new("ruff/ruff_per_file_ignores.py"),
|
||||
&settings::LinterSettings {
|
||||
per_file_ignores: CompiledPerFileIgnoreList::resolve(vec![PerFileIgnore::new(
|
||||
"ruff_per_file_ignores.py".to_string(),
|
||||
&["RUF100".parse().unwrap()],
|
||||
None,
|
||||
)])
|
||||
.unwrap(),
|
||||
..settings::LinterSettings::for_rules(vec![Rule::UnusedNOQA])
|
||||
},
|
||||
)?;
|
||||
assert_messages!(diagnostics);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn flake8_noqa() -> Result<()> {
|
||||
let diagnostics = test_path(
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
---
|
||||
source: crates/ruff_linter/src/rules/ruff/mod.rs
|
||||
---
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue