Move rule code from `description` to `check_name` in GitLab output serializer (#16437)

This commit is contained in:
InSync 2025-02-28 21:27:01 +07:00 committed by GitHub
parent 0c7c001647
commit 980faff176
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 22 additions and 10 deletions

View File

@ -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),

View File

@ -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": "<redacted>",
"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": "<redacted>",
"location": {
"lines": {
@ -29,7 +30,8 @@ snapshot_kind: text
"severity": "major"
},
{
"description": "(F821) Undefined name `a`",
"check_name": "F821",
"description": "Undefined name `a`",
"fingerprint": "<redacted>",
"location": {
"lines": {

View File

@ -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": "<redacted>",
"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": "<redacted>",
"location": {
"lines": {