From 980faff176c9ee17d87f593ad5d04636e55b88bd Mon Sep 17 00:00:00 2001 From: InSync Date: Fri, 28 Feb 2025 21:27:01 +0700 Subject: [PATCH] Move rule code from `description` to `check_name` in GitLab output serializer (#16437) --- crates/ruff_linter/src/message/gitlab.rs | 15 ++++++++++++--- ...ff_linter__message__gitlab__tests__output.snap | 10 ++++++---- ...er__message__gitlab__tests__syntax_errors.snap | 7 ++++--- 3 files changed, 22 insertions(+), 10 deletions(-) diff --git a/crates/ruff_linter/src/message/gitlab.rs b/crates/ruff_linter/src/message/gitlab.rs index 15e72832a2..6433184ac5 100644 --- a/crates/ruff_linter/src/message/gitlab.rs +++ b/crates/ruff_linter/src/message/gitlab.rs @@ -90,13 +90,22 @@ impl Serialize for SerializedMessages<'_> { } fingerprints.insert(message_fingerprint); - let description = if let Some(rule) = message.rule() { - format!("({}) {}", rule.noqa_code(), message.body()) + let (description, check_name) = if let Some(rule) = message.rule() { + (message.body().to_string(), rule.noqa_code().to_string()) } else { - message.body().to_string() + let description = message.body(); + let description_without_prefix = description + .strip_prefix("SyntaxError: ") + .unwrap_or(description); + + ( + description_without_prefix.to_string(), + "syntax-error".to_string(), + ) }; let value = json!({ + "check_name": check_name, "description": description, "severity": "major", "fingerprint": format!("{:x}", message_fingerprint), 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 4acd3f235d..438a434b6a 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 @@ -1,11 +1,11 @@ --- source: crates/ruff_linter/src/message/gitlab.rs expression: redact_fingerprint(&content) -snapshot_kind: text --- [ { - "description": "(F401) `os` imported but unused", + "check_name": "F401", + "description": "`os` imported but unused", "fingerprint": "", "location": { "lines": { @@ -17,7 +17,8 @@ snapshot_kind: text "severity": "major" }, { - "description": "(F841) Local variable `x` is assigned to but never used", + "check_name": "F841", + "description": "Local variable `x` is assigned to but never used", "fingerprint": "", "location": { "lines": { @@ -29,7 +30,8 @@ snapshot_kind: text "severity": "major" }, { - "description": "(F821) Undefined name `a`", + "check_name": "F821", + "description": "Undefined name `a`", "fingerprint": "", "location": { "lines": { 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 646289f50e..a9ff0a9311 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 @@ -1,11 +1,11 @@ --- source: crates/ruff_linter/src/message/gitlab.rs expression: redact_fingerprint(&content) -snapshot_kind: text --- [ { - "description": "SyntaxError: Expected one or more symbol names after import", + "check_name": "syntax-error", + "description": "Expected one or more symbol names after import", "fingerprint": "", "location": { "lines": { @@ -17,7 +17,8 @@ snapshot_kind: text "severity": "major" }, { - "description": "SyntaxError: Expected ')', found newline", + "check_name": "syntax-error", + "description": "Expected ')', found newline", "fingerprint": "", "location": { "lines": {