Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions crates/ruff/tests/snapshots/lint__output_format_gitlab.snap
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ exit_code: 1
[
{
"check_name": "F401",
"description": "`os` imported but unused",
"description": "F401: `os` imported but unused",
"fingerprint": "4dbad37161e65c72",
"location": {
"path": "input.py",
Expand All @@ -38,7 +38,7 @@ exit_code: 1
},
{
"check_name": "F821",
"description": "Undefined name `y`",
"description": "F821: Undefined name `y`",
"fingerprint": "7af59862a085230",
"location": {
"path": "input.py",
Expand All @@ -56,8 +56,8 @@ exit_code: 1
"severity": "major"
},
{
"check_name": "syntax-error",
"description": "Cannot use `match` statement on Python 3.9 (syntax was added in Python 3.10)",
"check_name": "invalid-syntax",
"description": "invalid-syntax: Cannot use `match` statement on Python 3.9 (syntax was added in Python 3.10)",
"fingerprint": "e558cec859bb66e8",
"location": {
"path": "input.py",
Expand Down
16 changes: 5 additions & 11 deletions crates/ruff_linter/src/message/gitlab.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,20 +88,14 @@ impl Serialize for SerializedMessages<'_> {
}
fingerprints.insert(message_fingerprint);

let (description, check_name) = if let Some(code) = diagnostic.secondary_code() {
(diagnostic.body().to_string(), code.as_str())
} else {
let description = diagnostic.body();
let description_without_prefix = description
.strip_prefix("SyntaxError: ")
.unwrap_or(description);

(description_without_prefix.to_string(), "syntax-error")
};
let description = diagnostic.body();
let check_name = diagnostic.secondary_code_or_id();

let value = json!({
"check_name": check_name,
"description": description,
// GitLab doesn't display the separate `check_name` field in a Code Quality report,
// so prepend it to the description too.
"description": format!("{check_name}: {description}"),
"severity": "major",
"fingerprint": format!("{:x}", message_fingerprint),
"location": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ expression: redact_fingerprint(&content)
[
{
"check_name": "F401",
"description": "`os` imported but unused",
"description": "F401: `os` imported but unused",
"fingerprint": "<redacted>",
"location": {
"path": "fib.py",
Expand All @@ -24,7 +24,7 @@ expression: redact_fingerprint(&content)
},
{
"check_name": "F841",
"description": "Local variable `x` is assigned to but never used",
"description": "F841: Local variable `x` is assigned to but never used",
"fingerprint": "<redacted>",
"location": {
"path": "fib.py",
Expand All @@ -43,7 +43,7 @@ expression: redact_fingerprint(&content)
},
{
"check_name": "F821",
"description": "Undefined name `a`",
"description": "F821: Undefined name `a`",
"fingerprint": "<redacted>",
"location": {
"path": "undef.py",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ expression: redact_fingerprint(&content)
---
[
{
"check_name": "syntax-error",
"description": "Expected one or more symbol names after import",
"check_name": "invalid-syntax",
"description": "invalid-syntax: Expected one or more symbol names after import",
"fingerprint": "<redacted>",
"location": {
"path": "syntax_errors.py",
Expand All @@ -23,8 +23,8 @@ expression: redact_fingerprint(&content)
"severity": "major"
},
{
"check_name": "syntax-error",
"description": "Expected ')', found newline",
"check_name": "invalid-syntax",
"description": "invalid-syntax: Expected ')', found newline",
"fingerprint": "<redacted>",
"location": {
"path": "syntax_errors.py",
Expand Down
Loading