diff --git a/crates/ruff/tests/snapshots/lint__output_format_gitlab.snap b/crates/ruff/tests/snapshots/lint__output_format_gitlab.snap index 304d2a748f..7596f0d086 100644 --- a/crates/ruff/tests/snapshots/lint__output_format_gitlab.snap +++ b/crates/ruff/tests/snapshots/lint__output_format_gitlab.snap @@ -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", @@ -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", @@ -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", diff --git a/crates/ruff_linter/src/message/gitlab.rs b/crates/ruff_linter/src/message/gitlab.rs index 9dc5423734..fbf5643697 100644 --- a/crates/ruff_linter/src/message/gitlab.rs +++ b/crates/ruff_linter/src/message/gitlab.rs @@ -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": { diff --git a/crates/ruff_linter/src/message/snapshots/ruff_linter__message__gitlab__tests__output.snap b/crates/ruff_linter/src/message/snapshots/ruff_linter__message__gitlab__tests__output.snap index 28565a1553..c106eb70ba 100644 --- a/crates/ruff_linter/src/message/snapshots/ruff_linter__message__gitlab__tests__output.snap +++ b/crates/ruff_linter/src/message/snapshots/ruff_linter__message__gitlab__tests__output.snap @@ -5,7 +5,7 @@ expression: redact_fingerprint(&content) [ { "check_name": "F401", - "description": "`os` imported but unused", + "description": "F401: `os` imported but unused", "fingerprint": "", "location": { "path": "fib.py", @@ -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": "", "location": { "path": "fib.py", @@ -43,7 +43,7 @@ expression: redact_fingerprint(&content) }, { "check_name": "F821", - "description": "Undefined name `a`", + "description": "F821: Undefined name `a`", "fingerprint": "", "location": { "path": "undef.py", diff --git a/crates/ruff_linter/src/message/snapshots/ruff_linter__message__gitlab__tests__syntax_errors.snap b/crates/ruff_linter/src/message/snapshots/ruff_linter__message__gitlab__tests__syntax_errors.snap index b8440fae2c..7979aa977a 100644 --- a/crates/ruff_linter/src/message/snapshots/ruff_linter__message__gitlab__tests__syntax_errors.snap +++ b/crates/ruff_linter/src/message/snapshots/ruff_linter__message__gitlab__tests__syntax_errors.snap @@ -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": "", "location": { "path": "syntax_errors.py", @@ -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": "", "location": { "path": "syntax_errors.py",