mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-30 22:01:47 +00:00
Warn on invalid noqa even when there are no diagnostics (#16178)
On `main` we warn the user if there is an invalid noqa comment[^1] and at least one of the following holds: - There is at least one diagnostic - A lint rule related to `noqa`s is enabled (e.g. `RUF100`) This is probably strange behavior from the point of view of the user, so we now show invalid `noqa`s even when there are no diagnostics. Closes #12831 [^1]: For the current definition of "invalid noqa comment", which may be expanded in #12811 . This PR is independent of loc. cit. in the sense that the CLI warnings should be consistent, regardless of which `noqa` comments are considered invalid.
This commit is contained in:
parent
3a0d45c85b
commit
f29c7b03ec
3 changed files with 39 additions and 1 deletions
|
@ -1021,6 +1021,22 @@ include = ["*.ipy"]
|
|||
Ok(())
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn warn_invalid_noqa_with_no_diagnostics() {
|
||||
assert_cmd_snapshot!(Command::new(get_cargo_bin(BIN_NAME))
|
||||
.args(STDIN_BASE_OPTIONS)
|
||||
.args(["--isolated"])
|
||||
.arg("--select")
|
||||
.arg("F401")
|
||||
.arg("-")
|
||||
.pass_stdin(
|
||||
r#"
|
||||
# ruff: noqa: AAA101
|
||||
print("Hello world!")
|
||||
"#
|
||||
));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn file_noqa_external() -> Result<()> {
|
||||
let tempdir = TempDir::new()?;
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
---
|
||||
source: crates/ruff/tests/lint.rs
|
||||
info:
|
||||
program: ruff
|
||||
args:
|
||||
- check
|
||||
- "--no-cache"
|
||||
- "--output-format"
|
||||
- concise
|
||||
- "--isolated"
|
||||
- "--select"
|
||||
- F401
|
||||
- "-"
|
||||
stdin: "\n# ruff: noqa: AAA101\nprint(\"Hello world!\")\n"
|
||||
---
|
||||
success: true
|
||||
exit_code: 0
|
||||
----- stdout -----
|
||||
All checks passed!
|
||||
|
||||
----- stderr -----
|
||||
warning: Invalid rule code provided to `# ruff: noqa` at -:2: AAA101
|
|
@ -267,7 +267,7 @@ pub fn check_path(
|
|||
}
|
||||
|
||||
// Enforce `noqa` directives.
|
||||
if (noqa.is_enabled() && !diagnostics.is_empty())
|
||||
if noqa.is_enabled()
|
||||
|| settings
|
||||
.rules
|
||||
.iter_enabled()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue