Allow hiding the diagnostic severity in ruff_db (#19644)

## Summary

This PR is a spin-off from https://github.com/astral-sh/ruff/pull/19415.
It enables replacing the severity and lint name in a ty-style
diagnostic:

```
error[unused-import]: `os` imported but unused
```

with the noqa code and optional fix availability icon for a Ruff
diagnostic:

```
F401 [*] `os` imported but unused
F821 Undefined name `a`
```

or nothing at all for a Ruff syntax error:

```
SyntaxError: Expected one or more symbol names after import
```

Ruff adds the `SyntaxError` prefix to these messages manually.

Initially (d912458), I just passed a `hide_severity` flag through a
bunch of calls to get it into `annotate-snippets`, but after looking at
it again today, I think reusing the `None` severity/level gave a nicer
result. As I note in a lengthy code comment, I think all of this code
should be temporary and reverted when Ruff gets real severities, so
hopefully it's okay if it feels a little hacky.

I think the main visible downside of this approach is that we can't
style the asterisk in the fix availabilty icon in cyan, as in Ruff's
current output. It's part of the message in this PR and any styling gets
overwritten in `annotate-snippets`.

<img width="400" height="342" alt="image"
src="https://github.com/user-attachments/assets/57542ec9-a81c-4a01-91c7-bd6d7ec99f99"
/>

Hmm, I guess reusing `Level::None` also means the `F401` isn't red
anymore. Maybe my initial approach was better after all. In any case,
the rest of the PR should be basically the same, it just depends how we
want to toggle the severity.

## Test Plan

New `ruff_db` tests. These snapshots should be compared to the two tests
just above them (`hide_severity_output` vs `output` and
`hide_severity_syntax_errors` against `syntax_errors`).
This commit is contained in:
Brent Westbrook 2025-08-05 09:56:18 -04:00 committed by GitHub
parent 94947cbf65
commit 78e5fe0a51
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
77 changed files with 448 additions and 223 deletions

View file

@ -33,10 +33,8 @@ impl Emitter for GithubEmitter {
write!(
writer,
"::error title=Ruff{code},file={file},line={row},col={column},endLine={end_row},endColumn={end_column}::",
code = diagnostic
.secondary_code()
.map_or_else(String::new, |code| format!(" ({code})")),
"::error title=Ruff ({code}),file={file},line={row},col={column},endLine={end_row},endColumn={end_column}::",
code = diagnostic.secondary_code_or_id(),
file = filename,
row = source_location.line,
column = source_location.column,
@ -54,6 +52,8 @@ impl Emitter for GithubEmitter {
if let Some(code) = diagnostic.secondary_code() {
write!(writer, " {code}")?;
} else {
write!(writer, " {id}:", id = diagnostic.id())?;
}
writeln!(writer, " {}", diagnostic.body())?;

View file

@ -33,8 +33,7 @@ mod text;
/// Creates a `Diagnostic` from a syntax error, with the format expected by Ruff.
///
/// This is almost identical to `ruff_db::diagnostic::create_syntax_error_diagnostic`, except the
/// `message` is stored as the primary diagnostic message instead of on the primary annotation, and
/// `SyntaxError: ` is prepended to the message.
/// `message` is stored as the primary diagnostic message instead of on the primary annotation.
///
/// TODO(brent) These should be unified at some point, but we keep them separate for now to avoid a
/// ton of snapshot changes while combining ruff's diagnostic type with `Diagnostic`.
@ -43,11 +42,7 @@ pub fn create_syntax_error_diagnostic(
message: impl std::fmt::Display,
range: impl Ranged,
) -> Diagnostic {
let mut diag = Diagnostic::new(
DiagnosticId::InvalidSyntax,
Severity::Error,
format_args!("SyntaxError: {message}"),
);
let mut diag = Diagnostic::new(DiagnosticId::InvalidSyntax, Severity::Error, message);
let span = span.into().with_range(range.range());
diag.annotate(Annotation::primary(span));
diag

View file

@ -27,7 +27,10 @@ impl Emitter for SarifEmitter {
.map(SarifResult::from_message)
.collect::<Result<Vec<_>>>()?;
let unique_rules: HashSet<_> = results.iter().filter_map(|result| result.code).collect();
let unique_rules: HashSet<_> = results
.iter()
.filter_map(|result| result.code.as_secondary_code())
.collect();
let mut rules: Vec<SarifRule> = unique_rules.into_iter().map(SarifRule::from).collect();
rules.sort_by(|a, b| a.code.cmp(b.code));
@ -109,9 +112,40 @@ impl Serialize for SarifRule<'_> {
}
}
#[derive(Debug)]
enum RuleCode<'a> {
SecondaryCode(&'a SecondaryCode),
LintId(&'a str),
}
impl RuleCode<'_> {
fn as_secondary_code(&self) -> Option<&SecondaryCode> {
match self {
RuleCode::SecondaryCode(code) => Some(code),
RuleCode::LintId(_) => None,
}
}
fn as_str(&self) -> &str {
match self {
RuleCode::SecondaryCode(code) => code.as_str(),
RuleCode::LintId(id) => id,
}
}
}
impl<'a> From<&'a Diagnostic> for RuleCode<'a> {
fn from(code: &'a Diagnostic) -> Self {
match code.secondary_code() {
Some(diagnostic) => Self::SecondaryCode(diagnostic),
None => Self::LintId(code.id().as_str()),
}
}
}
#[derive(Debug)]
struct SarifResult<'a> {
code: Option<&'a SecondaryCode>,
code: RuleCode<'a>,
level: String,
message: String,
uri: String,
@ -128,7 +162,7 @@ impl<'a> SarifResult<'a> {
let end_location = message.expect_ruff_end_location();
let path = normalize_path(&*message.expect_ruff_filename());
Ok(Self {
code: message.secondary_code(),
code: RuleCode::from(message),
level: "error".to_string(),
message: message.body().to_string(),
uri: url::Url::from_file_path(&path)
@ -148,7 +182,7 @@ impl<'a> SarifResult<'a> {
let end_location = message.expect_ruff_end_location();
let path = normalize_path(&*message.expect_ruff_filename());
Ok(Self {
code: message.secondary_code(),
code: RuleCode::from(message),
level: "error".to_string(),
message: message.body().to_string(),
uri: path.display().to_string(),
@ -183,7 +217,7 @@ impl Serialize for SarifResult<'_> {
}
}
}],
"ruleId": self.code,
"ruleId": self.code.as_str(),
})
.serialize(serializer)
}

View file

@ -1,7 +1,6 @@
---
source: crates/ruff_linter/src/message/github.rs
expression: content
snapshot_kind: text
---
::error title=Ruff,file=syntax_errors.py,line=1,col=15,endLine=2,endColumn=1::syntax_errors.py:1:15: SyntaxError: Expected one or more symbol names after import
::error title=Ruff,file=syntax_errors.py,line=3,col=12,endLine=4,endColumn=1::syntax_errors.py:3:12: SyntaxError: Expected ')', found newline
::error title=Ruff (invalid-syntax),file=syntax_errors.py,line=1,col=15,endLine=2,endColumn=1::syntax_errors.py:1:15: invalid-syntax: Expected one or more symbol names after import
::error title=Ruff (invalid-syntax),file=syntax_errors.py,line=3,col=12,endLine=4,endColumn=1::syntax_errors.py:3:12: invalid-syntax: Expected ')', found newline

View file

@ -1,8 +1,7 @@
---
source: crates/ruff_linter/src/message/grouped.rs
expression: content
snapshot_kind: text
---
syntax_errors.py:
1:15 SyntaxError: Expected one or more symbol names after import
3:12 SyntaxError: Expected ')', found newline
1:15 invalid-syntax: Expected one or more symbol names after import
3:12 invalid-syntax: Expected ')', found newline

View file

@ -2,7 +2,7 @@
source: crates/ruff_linter/src/message/text.rs
expression: content
---
syntax_errors.py:1:15: SyntaxError: Expected one or more symbol names after import
syntax_errors.py:1:15: invalid-syntax: Expected one or more symbol names after import
|
1 | from os import
| ^
@ -11,7 +11,7 @@ syntax_errors.py:1:15: SyntaxError: Expected one or more symbol names after impo
4 | def bar():
|
syntax_errors.py:3:12: SyntaxError: Expected ')', found newline
syntax_errors.py:3:12: invalid-syntax: Expected ')', found newline
|
1 | from os import
2 |

View file

@ -154,7 +154,12 @@ impl Display for RuleCodeAndBody<'_> {
body = self.message.body(),
)
} else {
f.write_str(self.message.body())
write!(
f,
"{code}: {body}",
code = self.message.id().as_str().red().bold(),
body = self.message.body(),
)
}
}
}

View file

@ -1,7 +1,7 @@
---
source: crates/ruff_linter/src/rules/flake8_commas/mod.rs
---
COM81_syntax_error.py:3:5: SyntaxError: Starred expression cannot be used here
COM81_syntax_error.py:3:5: invalid-syntax: Starred expression cannot be used here
|
1 | # Check for `flake8-commas` violation for a file containing syntax errors.
2 | (
@ -10,7 +10,7 @@ COM81_syntax_error.py:3:5: SyntaxError: Starred expression cannot be used here
4 | )
|
COM81_syntax_error.py:6:9: SyntaxError: Type parameter list cannot be empty
COM81_syntax_error.py:6:9: invalid-syntax: Type parameter list cannot be empty
|
4 | )
5 |

View file

@ -1,7 +1,7 @@
---
source: crates/ruff_linter/src/rules/flake8_commas/mod.rs
---
COM81_syntax_error.py:3:5: SyntaxError: Starred expression cannot be used here
COM81_syntax_error.py:3:5: invalid-syntax: Starred expression cannot be used here
|
1 | # Check for `flake8-commas` violation for a file containing syntax errors.
2 | (
@ -10,7 +10,7 @@ COM81_syntax_error.py:3:5: SyntaxError: Starred expression cannot be used here
4 | )
|
COM81_syntax_error.py:6:9: SyntaxError: Type parameter list cannot be empty
COM81_syntax_error.py:6:9: invalid-syntax: Type parameter list cannot be empty
|
4 | )
5 |

View file

@ -1,7 +1,7 @@
---
source: crates/ruff_linter/src/rules/flake8_implicit_str_concat/mod.rs
---
ISC_syntax_error.py:2:5: SyntaxError: missing closing quote in string literal
ISC_syntax_error.py:2:5: invalid-syntax: missing closing quote in string literal
|
1 | # The lexer doesn't emit a string token if it's unterminated
2 | "a" "b
@ -10,7 +10,7 @@ ISC_syntax_error.py:2:5: SyntaxError: missing closing quote in string literal
4 | "a" """b
|
ISC_syntax_error.py:2:7: SyntaxError: Expected a statement
ISC_syntax_error.py:2:7: invalid-syntax: Expected a statement
|
1 | # The lexer doesn't emit a string token if it's unterminated
2 | "a" "b
@ -31,7 +31,7 @@ ISC_syntax_error.py:3:1: ISC001 Implicitly concatenated string literals on one l
|
= help: Combine string literals
ISC_syntax_error.py:3:9: SyntaxError: missing closing quote in string literal
ISC_syntax_error.py:3:9: invalid-syntax: missing closing quote in string literal
|
1 | # The lexer doesn't emit a string token if it's unterminated
2 | "a" "b
@ -41,7 +41,7 @@ ISC_syntax_error.py:3:9: SyntaxError: missing closing quote in string literal
5 | c""" "d
|
ISC_syntax_error.py:3:11: SyntaxError: Expected a statement
ISC_syntax_error.py:3:11: invalid-syntax: Expected a statement
|
1 | # The lexer doesn't emit a string token if it's unterminated
2 | "a" "b
@ -63,7 +63,7 @@ ISC_syntax_error.py:4:1: ISC001 Implicitly concatenated string literals on one l
|
= help: Combine string literals
ISC_syntax_error.py:5:6: SyntaxError: missing closing quote in string literal
ISC_syntax_error.py:5:6: invalid-syntax: missing closing quote in string literal
|
3 | "a" "b" "c
4 | "a" """b
@ -73,7 +73,7 @@ ISC_syntax_error.py:5:6: SyntaxError: missing closing quote in string literal
7 | # For f-strings, the `FStringRanges` won't contain the range for
|
ISC_syntax_error.py:5:8: SyntaxError: Expected a statement
ISC_syntax_error.py:5:8: invalid-syntax: Expected a statement
|
3 | "a" "b" "c
4 | "a" """b
@ -84,7 +84,7 @@ ISC_syntax_error.py:5:8: SyntaxError: Expected a statement
8 | # unterminated f-strings.
|
ISC_syntax_error.py:9:8: SyntaxError: f-string: unterminated string
ISC_syntax_error.py:9:8: invalid-syntax: f-string: unterminated string
|
7 | # For f-strings, the `FStringRanges` won't contain the range for
8 | # unterminated f-strings.
@ -94,7 +94,7 @@ ISC_syntax_error.py:9:8: SyntaxError: f-string: unterminated string
11 | f"a" f"""b
|
ISC_syntax_error.py:9:9: SyntaxError: Expected FStringEnd, found newline
ISC_syntax_error.py:9:9: invalid-syntax: Expected FStringEnd, found newline
|
7 | # For f-strings, the `FStringRanges` won't contain the range for
8 | # unterminated f-strings.
@ -116,7 +116,7 @@ ISC_syntax_error.py:10:1: ISC001 Implicitly concatenated string literals on one
|
= help: Combine string literals
ISC_syntax_error.py:10:13: SyntaxError: f-string: unterminated string
ISC_syntax_error.py:10:13: invalid-syntax: f-string: unterminated string
|
8 | # unterminated f-strings.
9 | f"a" f"b
@ -126,7 +126,7 @@ ISC_syntax_error.py:10:13: SyntaxError: f-string: unterminated string
12 | c""" f"d {e
|
ISC_syntax_error.py:10:14: SyntaxError: Expected FStringEnd, found newline
ISC_syntax_error.py:10:14: invalid-syntax: Expected FStringEnd, found newline
|
8 | # unterminated f-strings.
9 | f"a" f"b
@ -148,7 +148,7 @@ ISC_syntax_error.py:11:1: ISC001 Implicitly concatenated string literals on one
|
= help: Combine string literals
ISC_syntax_error.py:16:5: SyntaxError: missing closing quote in string literal
ISC_syntax_error.py:16:5: invalid-syntax: missing closing quote in string literal
|
14 | (
15 | "a"
@ -158,7 +158,7 @@ ISC_syntax_error.py:16:5: SyntaxError: missing closing quote in string literal
18 | "d"
|
ISC_syntax_error.py:26:9: SyntaxError: f-string: unterminated triple-quoted string
ISC_syntax_error.py:26:9: invalid-syntax: f-string: unterminated triple-quoted string
|
24 | (
25 | """abc"""
@ -170,14 +170,14 @@ ISC_syntax_error.py:26:9: SyntaxError: f-string: unterminated triple-quoted stri
| |__^
|
ISC_syntax_error.py:30:1: SyntaxError: unexpected EOF while parsing
ISC_syntax_error.py:30:1: invalid-syntax: unexpected EOF while parsing
|
28 | "i" "j"
29 | )
| ^
|
ISC_syntax_error.py:30:1: SyntaxError: f-string: unterminated string
ISC_syntax_error.py:30:1: invalid-syntax: f-string: unterminated string
|
28 | "i" "j"
29 | )

View file

@ -1,7 +1,7 @@
---
source: crates/ruff_linter/src/rules/flake8_implicit_str_concat/mod.rs
---
ISC_syntax_error.py:2:5: SyntaxError: missing closing quote in string literal
ISC_syntax_error.py:2:5: invalid-syntax: missing closing quote in string literal
|
1 | # The lexer doesn't emit a string token if it's unterminated
2 | "a" "b
@ -10,7 +10,7 @@ ISC_syntax_error.py:2:5: SyntaxError: missing closing quote in string literal
4 | "a" """b
|
ISC_syntax_error.py:2:7: SyntaxError: Expected a statement
ISC_syntax_error.py:2:7: invalid-syntax: Expected a statement
|
1 | # The lexer doesn't emit a string token if it's unterminated
2 | "a" "b
@ -20,7 +20,7 @@ ISC_syntax_error.py:2:7: SyntaxError: Expected a statement
5 | c""" "d
|
ISC_syntax_error.py:3:9: SyntaxError: missing closing quote in string literal
ISC_syntax_error.py:3:9: invalid-syntax: missing closing quote in string literal
|
1 | # The lexer doesn't emit a string token if it's unterminated
2 | "a" "b
@ -30,7 +30,7 @@ ISC_syntax_error.py:3:9: SyntaxError: missing closing quote in string literal
5 | c""" "d
|
ISC_syntax_error.py:3:11: SyntaxError: Expected a statement
ISC_syntax_error.py:3:11: invalid-syntax: Expected a statement
|
1 | # The lexer doesn't emit a string token if it's unterminated
2 | "a" "b
@ -40,7 +40,7 @@ ISC_syntax_error.py:3:11: SyntaxError: Expected a statement
5 | c""" "d
|
ISC_syntax_error.py:5:6: SyntaxError: missing closing quote in string literal
ISC_syntax_error.py:5:6: invalid-syntax: missing closing quote in string literal
|
3 | "a" "b" "c
4 | "a" """b
@ -50,7 +50,7 @@ ISC_syntax_error.py:5:6: SyntaxError: missing closing quote in string literal
7 | # For f-strings, the `FStringRanges` won't contain the range for
|
ISC_syntax_error.py:5:8: SyntaxError: Expected a statement
ISC_syntax_error.py:5:8: invalid-syntax: Expected a statement
|
3 | "a" "b" "c
4 | "a" """b
@ -61,7 +61,7 @@ ISC_syntax_error.py:5:8: SyntaxError: Expected a statement
8 | # unterminated f-strings.
|
ISC_syntax_error.py:9:8: SyntaxError: f-string: unterminated string
ISC_syntax_error.py:9:8: invalid-syntax: f-string: unterminated string
|
7 | # For f-strings, the `FStringRanges` won't contain the range for
8 | # unterminated f-strings.
@ -71,7 +71,7 @@ ISC_syntax_error.py:9:8: SyntaxError: f-string: unterminated string
11 | f"a" f"""b
|
ISC_syntax_error.py:9:9: SyntaxError: Expected FStringEnd, found newline
ISC_syntax_error.py:9:9: invalid-syntax: Expected FStringEnd, found newline
|
7 | # For f-strings, the `FStringRanges` won't contain the range for
8 | # unterminated f-strings.
@ -82,7 +82,7 @@ ISC_syntax_error.py:9:9: SyntaxError: Expected FStringEnd, found newline
12 | c""" f"d {e
|
ISC_syntax_error.py:10:13: SyntaxError: f-string: unterminated string
ISC_syntax_error.py:10:13: invalid-syntax: f-string: unterminated string
|
8 | # unterminated f-strings.
9 | f"a" f"b
@ -92,7 +92,7 @@ ISC_syntax_error.py:10:13: SyntaxError: f-string: unterminated string
12 | c""" f"d {e
|
ISC_syntax_error.py:10:14: SyntaxError: Expected FStringEnd, found newline
ISC_syntax_error.py:10:14: invalid-syntax: Expected FStringEnd, found newline
|
8 | # unterminated f-strings.
9 | f"a" f"b
@ -102,7 +102,7 @@ ISC_syntax_error.py:10:14: SyntaxError: Expected FStringEnd, found newline
12 | c""" f"d {e
|
ISC_syntax_error.py:16:5: SyntaxError: missing closing quote in string literal
ISC_syntax_error.py:16:5: invalid-syntax: missing closing quote in string literal
|
14 | (
15 | "a"
@ -112,7 +112,7 @@ ISC_syntax_error.py:16:5: SyntaxError: missing closing quote in string literal
18 | "d"
|
ISC_syntax_error.py:26:9: SyntaxError: f-string: unterminated triple-quoted string
ISC_syntax_error.py:26:9: invalid-syntax: f-string: unterminated triple-quoted string
|
24 | (
25 | """abc"""
@ -124,14 +124,14 @@ ISC_syntax_error.py:26:9: SyntaxError: f-string: unterminated triple-quoted stri
| |__^
|
ISC_syntax_error.py:30:1: SyntaxError: unexpected EOF while parsing
ISC_syntax_error.py:30:1: invalid-syntax: unexpected EOF while parsing
|
28 | "i" "j"
29 | )
| ^
|
ISC_syntax_error.py:30:1: SyntaxError: f-string: unterminated string
ISC_syntax_error.py:30:1: invalid-syntax: f-string: unterminated string
|
28 | "i" "j"
29 | )

View file

@ -21,7 +21,7 @@ E11.py:6:1: E111 Indentation is not a multiple of 4
8 | if False:
|
E11.py:9:1: SyntaxError: Expected an indented block after `if` statement
E11.py:9:1: invalid-syntax: Expected an indented block after `if` statement
|
7 | #: E112
8 | if False:
@ -31,7 +31,7 @@ E11.py:9:1: SyntaxError: Expected an indented block after `if` statement
11 | print()
|
E11.py:12:1: SyntaxError: Unexpected indentation
E11.py:12:1: invalid-syntax: Unexpected indentation
|
10 | #: E113
11 | print()
@ -41,7 +41,7 @@ E11.py:12:1: SyntaxError: Unexpected indentation
14 | mimetype = 'application/x-directory'
|
E11.py:14:1: SyntaxError: Expected a statement
E11.py:14:1: invalid-syntax: Expected a statement
|
12 | print()
13 | #: E114 E116
@ -51,7 +51,7 @@ E11.py:14:1: SyntaxError: Expected a statement
16 | create_date = False
|
E11.py:45:1: SyntaxError: Expected an indented block after `if` statement
E11.py:45:1: invalid-syntax: Expected an indented block after `if` statement
|
43 | #: E112
44 | if False: #

View file

@ -11,7 +11,7 @@ E11.py:9:1: E112 Expected an indented block
11 | print()
|
E11.py:9:1: SyntaxError: Expected an indented block after `if` statement
E11.py:9:1: invalid-syntax: Expected an indented block after `if` statement
|
7 | #: E112
8 | if False:
@ -21,7 +21,7 @@ E11.py:9:1: SyntaxError: Expected an indented block after `if` statement
11 | print()
|
E11.py:12:1: SyntaxError: Unexpected indentation
E11.py:12:1: invalid-syntax: Unexpected indentation
|
10 | #: E113
11 | print()
@ -31,7 +31,7 @@ E11.py:12:1: SyntaxError: Unexpected indentation
14 | mimetype = 'application/x-directory'
|
E11.py:14:1: SyntaxError: Expected a statement
E11.py:14:1: invalid-syntax: Expected a statement
|
12 | print()
13 | #: E114 E116
@ -51,7 +51,7 @@ E11.py:45:1: E112 Expected an indented block
47 | if False:
|
E11.py:45:1: SyntaxError: Expected an indented block after `if` statement
E11.py:45:1: invalid-syntax: Expected an indented block after `if` statement
|
43 | #: E112
44 | if False: #

View file

@ -1,7 +1,7 @@
---
source: crates/ruff_linter/src/rules/pycodestyle/mod.rs
---
E11.py:9:1: SyntaxError: Expected an indented block after `if` statement
E11.py:9:1: invalid-syntax: Expected an indented block after `if` statement
|
7 | #: E112
8 | if False:
@ -21,7 +21,7 @@ E11.py:12:1: E113 Unexpected indentation
14 | mimetype = 'application/x-directory'
|
E11.py:12:1: SyntaxError: Unexpected indentation
E11.py:12:1: invalid-syntax: Unexpected indentation
|
10 | #: E113
11 | print()
@ -31,7 +31,7 @@ E11.py:12:1: SyntaxError: Unexpected indentation
14 | mimetype = 'application/x-directory'
|
E11.py:14:1: SyntaxError: Expected a statement
E11.py:14:1: invalid-syntax: Expected a statement
|
12 | print()
13 | #: E114 E116
@ -41,7 +41,7 @@ E11.py:14:1: SyntaxError: Expected a statement
16 | create_date = False
|
E11.py:45:1: SyntaxError: Expected an indented block after `if` statement
E11.py:45:1: invalid-syntax: Expected an indented block after `if` statement
|
43 | #: E112
44 | if False: #

View file

@ -1,7 +1,7 @@
---
source: crates/ruff_linter/src/rules/pycodestyle/mod.rs
---
E11.py:9:1: SyntaxError: Expected an indented block after `if` statement
E11.py:9:1: invalid-syntax: Expected an indented block after `if` statement
|
7 | #: E112
8 | if False:
@ -11,7 +11,7 @@ E11.py:9:1: SyntaxError: Expected an indented block after `if` statement
11 | print()
|
E11.py:12:1: SyntaxError: Unexpected indentation
E11.py:12:1: invalid-syntax: Unexpected indentation
|
10 | #: E113
11 | print()
@ -21,7 +21,7 @@ E11.py:12:1: SyntaxError: Unexpected indentation
14 | mimetype = 'application/x-directory'
|
E11.py:14:1: SyntaxError: Expected a statement
E11.py:14:1: invalid-syntax: Expected a statement
|
12 | print()
13 | #: E114 E116
@ -41,7 +41,7 @@ E11.py:15:1: E114 Indentation is not a multiple of 4 (comment)
17 | #: E116 E116 E116
|
E11.py:45:1: SyntaxError: Expected an indented block after `if` statement
E11.py:45:1: invalid-syntax: Expected an indented block after `if` statement
|
43 | #: E112
44 | if False: #

View file

@ -1,7 +1,7 @@
---
source: crates/ruff_linter/src/rules/pycodestyle/mod.rs
---
E11.py:9:1: SyntaxError: Expected an indented block after `if` statement
E11.py:9:1: invalid-syntax: Expected an indented block after `if` statement
|
7 | #: E112
8 | if False:
@ -11,7 +11,7 @@ E11.py:9:1: SyntaxError: Expected an indented block after `if` statement
11 | print()
|
E11.py:12:1: SyntaxError: Unexpected indentation
E11.py:12:1: invalid-syntax: Unexpected indentation
|
10 | #: E113
11 | print()
@ -21,7 +21,7 @@ E11.py:12:1: SyntaxError: Unexpected indentation
14 | mimetype = 'application/x-directory'
|
E11.py:14:1: SyntaxError: Expected a statement
E11.py:14:1: invalid-syntax: Expected a statement
|
12 | print()
13 | #: E114 E116
@ -91,7 +91,7 @@ E11.py:35:1: E115 Expected an indented block (comment)
37 | #: E117
|
E11.py:45:1: SyntaxError: Expected an indented block after `if` statement
E11.py:45:1: invalid-syntax: Expected an indented block after `if` statement
|
43 | #: E112
44 | if False: #

View file

@ -1,7 +1,7 @@
---
source: crates/ruff_linter/src/rules/pycodestyle/mod.rs
---
E11.py:9:1: SyntaxError: Expected an indented block after `if` statement
E11.py:9:1: invalid-syntax: Expected an indented block after `if` statement
|
7 | #: E112
8 | if False:
@ -11,7 +11,7 @@ E11.py:9:1: SyntaxError: Expected an indented block after `if` statement
11 | print()
|
E11.py:12:1: SyntaxError: Unexpected indentation
E11.py:12:1: invalid-syntax: Unexpected indentation
|
10 | #: E113
11 | print()
@ -21,7 +21,7 @@ E11.py:12:1: SyntaxError: Unexpected indentation
14 | mimetype = 'application/x-directory'
|
E11.py:14:1: SyntaxError: Expected a statement
E11.py:14:1: invalid-syntax: Expected a statement
|
12 | print()
13 | #: E114 E116
@ -71,7 +71,7 @@ E11.py:26:1: E116 Unexpected indentation (comment)
28 | def start(self):
|
E11.py:45:1: SyntaxError: Expected an indented block after `if` statement
E11.py:45:1: invalid-syntax: Expected an indented block after `if` statement
|
43 | #: E112
44 | if False: #

View file

@ -11,7 +11,7 @@ E11.py:6:1: E117 Over-indented
8 | if False:
|
E11.py:9:1: SyntaxError: Expected an indented block after `if` statement
E11.py:9:1: invalid-syntax: Expected an indented block after `if` statement
|
7 | #: E112
8 | if False:
@ -21,7 +21,7 @@ E11.py:9:1: SyntaxError: Expected an indented block after `if` statement
11 | print()
|
E11.py:12:1: SyntaxError: Unexpected indentation
E11.py:12:1: invalid-syntax: Unexpected indentation
|
10 | #: E113
11 | print()
@ -31,7 +31,7 @@ E11.py:12:1: SyntaxError: Unexpected indentation
14 | mimetype = 'application/x-directory'
|
E11.py:14:1: SyntaxError: Expected a statement
E11.py:14:1: invalid-syntax: Expected a statement
|
12 | print()
13 | #: E114 E116
@ -61,7 +61,7 @@ E11.py:42:1: E117 Over-indented
44 | if False: #
|
E11.py:45:1: SyntaxError: Expected an indented block after `if` statement
E11.py:45:1: invalid-syntax: Expected an indented block after `if` statement
|
43 | #: E112
44 | if False: #

View file

@ -1,7 +1,7 @@
---
source: crates/ruff_linter/src/rules/pycodestyle/mod.rs
---
E30_syntax_error.py:4:15: SyntaxError: Expected ']', found '('
E30_syntax_error.py:4:15: invalid-syntax: Expected ']', found '('
|
2 | # parenthesis.
3 |
@ -10,7 +10,7 @@ E30_syntax_error.py:4:15: SyntaxError: Expected ']', found '('
5 | pass
|
E30_syntax_error.py:13:18: SyntaxError: Expected ')', found newline
E30_syntax_error.py:13:18: invalid-syntax: Expected ')', found newline
|
12 | class Foo:
13 | def __init__(
@ -30,7 +30,7 @@ E30_syntax_error.py:15:5: E301 Expected 1 blank line, found 0
|
= help: Add missing blank line
E30_syntax_error.py:18:11: SyntaxError: Expected ')', found newline
E30_syntax_error.py:18:11: invalid-syntax: Expected ')', found newline
|
16 | pass
17 |
@ -41,7 +41,7 @@ E30_syntax_error.py:18:11: SyntaxError: Expected ')', found newline
21 | def top(
|
E30_syntax_error.py:21:9: SyntaxError: Expected ')', found newline
E30_syntax_error.py:21:9: invalid-syntax: Expected ')', found newline
|
21 | def top(
| ^

View file

@ -1,7 +1,7 @@
---
source: crates/ruff_linter/src/rules/pycodestyle/mod.rs
---
E30_syntax_error.py:4:15: SyntaxError: Expected ']', found '('
E30_syntax_error.py:4:15: invalid-syntax: Expected ']', found '('
|
2 | # parenthesis.
3 |
@ -20,7 +20,7 @@ E30_syntax_error.py:7:1: E302 Expected 2 blank lines, found 1
|
= help: Add missing blank line(s)
E30_syntax_error.py:13:18: SyntaxError: Expected ')', found newline
E30_syntax_error.py:13:18: invalid-syntax: Expected ')', found newline
|
12 | class Foo:
13 | def __init__(
@ -30,7 +30,7 @@ E30_syntax_error.py:13:18: SyntaxError: Expected ')', found newline
16 | pass
|
E30_syntax_error.py:18:11: SyntaxError: Expected ')', found newline
E30_syntax_error.py:18:11: invalid-syntax: Expected ')', found newline
|
16 | pass
17 |
@ -41,7 +41,7 @@ E30_syntax_error.py:18:11: SyntaxError: Expected ')', found newline
21 | def top(
|
E30_syntax_error.py:21:9: SyntaxError: Expected ')', found newline
E30_syntax_error.py:21:9: invalid-syntax: Expected ')', found newline
|
21 | def top(
| ^

View file

@ -1,7 +1,7 @@
---
source: crates/ruff_linter/src/rules/pycodestyle/mod.rs
---
E30_syntax_error.py:4:15: SyntaxError: Expected ']', found '('
E30_syntax_error.py:4:15: invalid-syntax: Expected ']', found '('
|
2 | # parenthesis.
3 |
@ -19,7 +19,7 @@ E30_syntax_error.py:12:1: E303 Too many blank lines (3)
|
= help: Remove extraneous blank line(s)
E30_syntax_error.py:13:18: SyntaxError: Expected ')', found newline
E30_syntax_error.py:13:18: invalid-syntax: Expected ')', found newline
|
12 | class Foo:
13 | def __init__(
@ -29,7 +29,7 @@ E30_syntax_error.py:13:18: SyntaxError: Expected ')', found newline
16 | pass
|
E30_syntax_error.py:18:11: SyntaxError: Expected ')', found newline
E30_syntax_error.py:18:11: invalid-syntax: Expected ')', found newline
|
16 | pass
17 |
@ -40,7 +40,7 @@ E30_syntax_error.py:18:11: SyntaxError: Expected ')', found newline
21 | def top(
|
E30_syntax_error.py:21:9: SyntaxError: Expected ')', found newline
E30_syntax_error.py:21:9: invalid-syntax: Expected ')', found newline
|
21 | def top(
| ^

View file

@ -1,7 +1,7 @@
---
source: crates/ruff_linter/src/rules/pycodestyle/mod.rs
---
E30_syntax_error.py:4:15: SyntaxError: Expected ']', found '('
E30_syntax_error.py:4:15: invalid-syntax: Expected ']', found '('
|
2 | # parenthesis.
3 |
@ -10,7 +10,7 @@ E30_syntax_error.py:4:15: SyntaxError: Expected ']', found '('
5 | pass
|
E30_syntax_error.py:13:18: SyntaxError: Expected ')', found newline
E30_syntax_error.py:13:18: invalid-syntax: Expected ')', found newline
|
12 | class Foo:
13 | def __init__(
@ -29,7 +29,7 @@ E30_syntax_error.py:18:1: E305 Expected 2 blank lines after class or function de
|
= help: Add missing blank line(s)
E30_syntax_error.py:18:11: SyntaxError: Expected ')', found newline
E30_syntax_error.py:18:11: invalid-syntax: Expected ')', found newline
|
16 | pass
17 |
@ -40,7 +40,7 @@ E30_syntax_error.py:18:11: SyntaxError: Expected ')', found newline
21 | def top(
|
E30_syntax_error.py:21:9: SyntaxError: Expected ')', found newline
E30_syntax_error.py:21:9: invalid-syntax: Expected ')', found newline
|
21 | def top(
| ^

View file

@ -1,7 +1,7 @@
---
source: crates/ruff_linter/src/rules/pycodestyle/mod.rs
---
E30_syntax_error.py:4:15: SyntaxError: Expected ']', found '('
E30_syntax_error.py:4:15: invalid-syntax: Expected ']', found '('
|
2 | # parenthesis.
3 |
@ -10,7 +10,7 @@ E30_syntax_error.py:4:15: SyntaxError: Expected ']', found '('
5 | pass
|
E30_syntax_error.py:13:18: SyntaxError: Expected ')', found newline
E30_syntax_error.py:13:18: invalid-syntax: Expected ')', found newline
|
12 | class Foo:
13 | def __init__(
@ -20,7 +20,7 @@ E30_syntax_error.py:13:18: SyntaxError: Expected ')', found newline
16 | pass
|
E30_syntax_error.py:18:11: SyntaxError: Expected ')', found newline
E30_syntax_error.py:18:11: invalid-syntax: Expected ')', found newline
|
16 | pass
17 |
@ -31,7 +31,7 @@ E30_syntax_error.py:18:11: SyntaxError: Expected ')', found newline
21 | def top(
|
E30_syntax_error.py:21:9: SyntaxError: Expected ')', found newline
E30_syntax_error.py:21:9: invalid-syntax: Expected ')', found newline
|
21 | def top(
| ^

View file

@ -8,14 +8,14 @@ W19.py:1:1: W191 Indentation contains tabs
2 | multiline string with tab in it'''
|
W19.py:1:1: SyntaxError: Unexpected indentation
W19.py:1:1: invalid-syntax: Unexpected indentation
|
1 | '''File starts with a tab
| ^^^^
2 | multiline string with tab in it'''
|
W19.py:5:1: SyntaxError: Expected a statement
W19.py:5:1: invalid-syntax: Expected a statement
|
4 | #: W191
5 | if False:

View file

@ -1,8 +1,7 @@
---
source: crates/ruff_linter/src/rules/pycodestyle/mod.rs
snapshot_kind: text
---
E2_syntax_error.py:1:10: SyntaxError: Expected an expression
E2_syntax_error.py:1:10: invalid-syntax: Expected an expression
|
1 | a = (1 or)
| ^

View file

@ -11,7 +11,7 @@ invalid_characters_syntax_error.py:5:6: PLE2510 Invalid unescaped character back
|
= help: Replace with escape sequence
invalid_characters_syntax_error.py:7:5: SyntaxError: missing closing quote in string literal
invalid_characters_syntax_error.py:7:5: invalid-syntax: missing closing quote in string literal
|
5 | b = '␈'
6 | # Unterminated string
@ -21,7 +21,7 @@ invalid_characters_syntax_error.py:7:5: SyntaxError: missing closing quote in st
9 | # Unterminated f-string
|
invalid_characters_syntax_error.py:7:7: SyntaxError: Expected a statement
invalid_characters_syntax_error.py:7:7: invalid-syntax: Expected a statement
|
5 | b = '␈'
6 | # Unterminated string
@ -43,7 +43,7 @@ invalid_characters_syntax_error.py:8:6: PLE2510 Invalid unescaped character back
|
= help: Replace with escape sequence
invalid_characters_syntax_error.py:10:7: SyntaxError: f-string: unterminated string
invalid_characters_syntax_error.py:10:7: invalid-syntax: f-string: unterminated string
|
8 | b = '␈'
9 | # Unterminated f-string
@ -53,7 +53,7 @@ invalid_characters_syntax_error.py:10:7: SyntaxError: f-string: unterminated str
12 | # Implicitly concatenated
|
invalid_characters_syntax_error.py:10:8: SyntaxError: Expected FStringEnd, found newline
invalid_characters_syntax_error.py:10:8: invalid-syntax: Expected FStringEnd, found newline
|
8 | b = '␈'
9 | # Unterminated f-string
@ -93,7 +93,7 @@ invalid_characters_syntax_error.py:13:11: PLE2510 Invalid unescaped character ba
|
= help: Replace with escape sequence
invalid_characters_syntax_error.py:13:14: SyntaxError: missing closing quote in string literal
invalid_characters_syntax_error.py:13:14: invalid-syntax: missing closing quote in string literal
|
11 | b = f'␈'
12 | # Implicitly concatenated
@ -101,7 +101,7 @@ invalid_characters_syntax_error.py:13:14: SyntaxError: missing closing quote in
| ^^
|
invalid_characters_syntax_error.py:13:16: SyntaxError: Expected a statement
invalid_characters_syntax_error.py:13:16: invalid-syntax: Expected a statement
|
11 | b = f'␈'
12 | # Implicitly concatenated

View file

@ -1,7 +1,7 @@
---
source: crates/ruff_linter/src/linter.rs
---
resources/test/fixtures/syntax_errors/async_comprehension.ipynb:3:5: SyntaxError: cannot use an asynchronous comprehension inside of a synchronous comprehension on Python 3.10 (syntax was added in 3.11)
resources/test/fixtures/syntax_errors/async_comprehension.ipynb:3:5: invalid-syntax: cannot use an asynchronous comprehension inside of a synchronous comprehension on Python 3.10 (syntax was added in 3.11)
|
1 | async def elements(n): yield n
2 | [x async for x in elements(5)] # okay, async at top level

View file

@ -1,7 +1,7 @@
---
source: crates/ruff_linter/src/linter.rs
---
<filename>:1:27: SyntaxError: cannot use an asynchronous comprehension inside of a synchronous comprehension on Python 3.10 (syntax was added in 3.11)
<filename>:1:27: invalid-syntax: cannot use an asynchronous comprehension inside of a synchronous comprehension on Python 3.10 (syntax was added in 3.11)
|
1 | async def f(): return [[x async for x in foo(n)] for n in range(3)]
| ^^^^^^^^^^^^^^^^^^^^^

View file

@ -1,7 +1,7 @@
---
source: crates/ruff_linter/src/linter.rs
---
<filename>:3:21: SyntaxError: attribute name `x` repeated in class pattern
<filename>:3:21: invalid-syntax: attribute name `x` repeated in class pattern
|
2 | match x:
3 | case Point(x=1, x=2):

View file

@ -1,7 +1,7 @@
---
source: crates/ruff_linter/src/linter.rs
---
<filename>:3:21: SyntaxError: mapping pattern checks duplicate key `'key'`
<filename>:3:21: invalid-syntax: mapping pattern checks duplicate key `'key'`
|
2 | match x:
3 | case {'key': 1, 'key': 2}:

View file

@ -1,7 +1,7 @@
---
source: crates/ruff_linter/src/linter.rs
---
<filename>:1:12: SyntaxError: duplicate type parameter
<filename>:1:12: invalid-syntax: duplicate type parameter
|
1 | class C[T, T]: pass
| ^

View file

@ -1,7 +1,7 @@
---
source: crates/ruff_linter/src/linter.rs
---
<filename>:2:22: SyntaxError: named expression cannot be used within a generic definition
<filename>:2:22: invalid-syntax: named expression cannot be used within a generic definition
|
2 | def f[T](x: int) -> (y := 3): return x
| ^^^^^^

View file

@ -1,7 +1,7 @@
---
source: crates/ruff_linter/src/linter.rs
---
<filename>:2:13: SyntaxError: yield expression cannot be used within a generic definition
<filename>:2:13: invalid-syntax: yield expression cannot be used within a generic definition
|
2 | class C[T]((yield from [object])):
| ^^^^^^^^^^^^^^^^^^^

View file

@ -1,7 +1,7 @@
---
source: crates/ruff_linter/src/linter.rs
---
<filename>:2:11: SyntaxError: yield expression cannot be used within a type alias
<filename>:2:11: invalid-syntax: yield expression cannot be used within a type alias
|
2 | type Y = (yield 1)
| ^^^^^^^

View file

@ -1,7 +1,7 @@
---
source: crates/ruff_linter/src/linter.rs
---
<filename>:2:12: SyntaxError: yield expression cannot be used within a TypeVar bound
<filename>:2:12: invalid-syntax: yield expression cannot be used within a TypeVar bound
|
2 | type X[T: (yield 1)] = int
| ^^^^^^^

View file

@ -1,7 +1,7 @@
---
source: crates/ruff_linter/src/linter.rs
---
<filename>:3:12: SyntaxError: Starred expression cannot be used here
<filename>:3:12: invalid-syntax: Starred expression cannot be used here
|
2 | def func():
3 | return *x

View file

@ -1,7 +1,7 @@
---
source: crates/ruff_linter/src/linter.rs
---
<filename>:2:5: SyntaxError: Starred expression cannot be used here
<filename>:2:5: invalid-syntax: Starred expression cannot be used here
|
2 | for *x in range(10):
| ^^

View file

@ -1,7 +1,7 @@
---
source: crates/ruff_linter/src/linter.rs
---
<filename>:3:11: SyntaxError: Starred expression cannot be used here
<filename>:3:11: invalid-syntax: Starred expression cannot be used here
|
2 | def func():
3 | yield *x

View file

@ -1,7 +1,7 @@
---
source: crates/ruff_linter/src/linter.rs
---
<filename>:3:10: SyntaxError: name capture `irrefutable` makes remaining patterns unreachable
<filename>:3:10: invalid-syntax: name capture `irrefutable` makes remaining patterns unreachable
|
2 | match value:
3 | case irrefutable:

View file

@ -1,7 +1,7 @@
---
source: crates/ruff_linter/src/linter.rs
---
<filename>:3:10: SyntaxError: wildcard makes remaining patterns unreachable
<filename>:3:10: invalid-syntax: wildcard makes remaining patterns unreachable
|
2 | match value:
3 | case _:

View file

@ -1,7 +1,7 @@
---
source: crates/ruff_linter/src/linter.rs
---
<filename>:3:14: SyntaxError: multiple assignments to name `a` in pattern
<filename>:3:14: invalid-syntax: multiple assignments to name `a` in pattern
|
2 | match x:
3 | case [a, a]:

View file

@ -1,7 +1,7 @@
---
source: crates/ruff_linter/src/linter.rs
---
<filename>:1:2: SyntaxError: assignment expression cannot rebind comprehension variable
<filename>:1:2: invalid-syntax: assignment expression cannot rebind comprehension variable
|
1 | [x:= 2 for x in range(2)]
| ^

View file

@ -1,7 +1,7 @@
---
source: crates/ruff_linter/src/linter.rs
---
<filename>:1:1: SyntaxError: starred assignment target must be in a list or tuple
<filename>:1:1: invalid-syntax: starred assignment target must be in a list or tuple
|
1 | *a = [1, 2, 3, 4]
| ^^

View file

@ -1,7 +1,7 @@
---
source: crates/ruff_linter/src/linter.rs
---
<filename>:2:1: SyntaxError: cannot assign to `__debug__`
<filename>:2:1: invalid-syntax: cannot assign to `__debug__`
|
2 | __debug__ = False
| ^^^^^^^^^

View file

@ -1,7 +1,7 @@
---
source: crates/ruff_linter/src/linter.rs
---
<filename>:2:15: SyntaxError: cannot assign to `__debug__`
<filename>:2:15: invalid-syntax: cannot assign to `__debug__`
|
2 | class Generic[__debug__]:
| ^^^^^^^^^

View file

@ -1,7 +1,7 @@
---
source: crates/ruff_linter/src/linter.rs
---
<filename>:2:13: SyntaxError: cannot assign to `__debug__`
<filename>:2:13: invalid-syntax: cannot assign to `__debug__`
|
2 | def process(__debug__):
| ^^^^^^^^^