Skip to content

Commit 980faff

Browse files
Move rule code from description to check_name in GitLab output serializer (#16437)
1 parent 0c7c001 commit 980faff

File tree

3 files changed

+22
-10
lines changed

3 files changed

+22
-10
lines changed

crates/ruff_linter/src/message/gitlab.rs

+12-3
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,22 @@ impl Serialize for SerializedMessages<'_> {
9090
}
9191
fingerprints.insert(message_fingerprint);
9292

93-
let description = if let Some(rule) = message.rule() {
94-
format!("({}) {}", rule.noqa_code(), message.body())
93+
let (description, check_name) = if let Some(rule) = message.rule() {
94+
(message.body().to_string(), rule.noqa_code().to_string())
9595
} else {
96-
message.body().to_string()
96+
let description = message.body();
97+
let description_without_prefix = description
98+
.strip_prefix("SyntaxError: ")
99+
.unwrap_or(description);
100+
101+
(
102+
description_without_prefix.to_string(),
103+
"syntax-error".to_string(),
104+
)
97105
};
98106

99107
let value = json!({
108+
"check_name": check_name,
100109
"description": description,
101110
"severity": "major",
102111
"fingerprint": format!("{:x}", message_fingerprint),

crates/ruff_linter/src/message/snapshots/ruff_linter__message__gitlab__tests__output.snap

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
---
22
source: crates/ruff_linter/src/message/gitlab.rs
33
expression: redact_fingerprint(&content)
4-
snapshot_kind: text
54
---
65
[
76
{
8-
"description": "(F401) `os` imported but unused",
7+
"check_name": "F401",
8+
"description": "`os` imported but unused",
99
"fingerprint": "<redacted>",
1010
"location": {
1111
"lines": {
@@ -17,7 +17,8 @@ snapshot_kind: text
1717
"severity": "major"
1818
},
1919
{
20-
"description": "(F841) Local variable `x` is assigned to but never used",
20+
"check_name": "F841",
21+
"description": "Local variable `x` is assigned to but never used",
2122
"fingerprint": "<redacted>",
2223
"location": {
2324
"lines": {
@@ -29,7 +30,8 @@ snapshot_kind: text
2930
"severity": "major"
3031
},
3132
{
32-
"description": "(F821) Undefined name `a`",
33+
"check_name": "F821",
34+
"description": "Undefined name `a`",
3335
"fingerprint": "<redacted>",
3436
"location": {
3537
"lines": {

crates/ruff_linter/src/message/snapshots/ruff_linter__message__gitlab__tests__syntax_errors.snap

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
---
22
source: crates/ruff_linter/src/message/gitlab.rs
33
expression: redact_fingerprint(&content)
4-
snapshot_kind: text
54
---
65
[
76
{
8-
"description": "SyntaxError: Expected one or more symbol names after import",
7+
"check_name": "syntax-error",
8+
"description": "Expected one or more symbol names after import",
99
"fingerprint": "<redacted>",
1010
"location": {
1111
"lines": {
@@ -17,7 +17,8 @@ snapshot_kind: text
1717
"severity": "major"
1818
},
1919
{
20-
"description": "SyntaxError: Expected ')', found newline",
20+
"check_name": "syntax-error",
21+
"description": "Expected ')', found newline",
2122
"fingerprint": "<redacted>",
2223
"location": {
2324
"lines": {

0 commit comments

Comments
 (0)