Skip to content

Commit bc6e105

Browse files
authored
Include column numbers in GitLab output format. (#19708)
1 parent 6bd413d commit bc6e105

File tree

4 files changed

+100
-54
lines changed

4 files changed

+100
-54
lines changed

crates/ruff/tests/snapshots/lint__output_format_gitlab.snap

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,17 @@ exit_code: 1
2222
"description": "`os` imported but unused",
2323
"fingerprint": "4dbad37161e65c72",
2424
"location": {
25-
"lines": {
26-
"begin": 1,
27-
"end": 1
28-
},
29-
"path": "input.py"
25+
"path": "input.py",
26+
"positions": {
27+
"begin": {
28+
"column": 8,
29+
"line": 1
30+
},
31+
"end": {
32+
"column": 10,
33+
"line": 1
34+
}
35+
}
3036
},
3137
"severity": "major"
3238
},
@@ -35,11 +41,17 @@ exit_code: 1
3541
"description": "Undefined name `y`",
3642
"fingerprint": "7af59862a085230",
3743
"location": {
38-
"lines": {
39-
"begin": 2,
40-
"end": 2
41-
},
42-
"path": "input.py"
44+
"path": "input.py",
45+
"positions": {
46+
"begin": {
47+
"column": 5,
48+
"line": 2
49+
},
50+
"end": {
51+
"column": 6,
52+
"line": 2
53+
}
54+
}
4355
},
4456
"severity": "major"
4557
},
@@ -48,11 +60,17 @@ exit_code: 1
4860
"description": "Cannot use `match` statement on Python 3.9 (syntax was added in Python 3.10)",
4961
"fingerprint": "e558cec859bb66e8",
5062
"location": {
51-
"lines": {
52-
"begin": 3,
53-
"end": 3
54-
},
55-
"path": "input.py"
63+
"path": "input.py",
64+
"positions": {
65+
"begin": {
66+
"column": 1,
67+
"line": 3
68+
},
69+
"end": {
70+
"column": 6,
71+
"line": 3
72+
}
73+
}
5674
},
5775
"severity": "major"
5876
}

crates/ruff_linter/src/message/gitlab.rs

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -61,22 +61,17 @@ impl Serialize for SerializedMessages<'_> {
6161
let mut fingerprints = HashSet::<u64>::with_capacity(self.diagnostics.len());
6262

6363
for diagnostic in self.diagnostics {
64-
let start_location = diagnostic.expect_ruff_start_location();
65-
let end_location = diagnostic.expect_ruff_end_location();
66-
6764
let filename = diagnostic.expect_ruff_filename();
68-
let lines = if self.context.is_notebook(&filename) {
65+
66+
let (start_location, end_location) = if self.context.is_notebook(&filename) {
6967
// We can't give a reasonable location for the structured formats,
7068
// so we show one that's clearly a fallback
71-
json!({
72-
"begin": 1,
73-
"end": 1
74-
})
69+
Default::default()
7570
} else {
76-
json!({
77-
"begin": start_location.line,
78-
"end": end_location.line
79-
})
71+
(
72+
diagnostic.expect_ruff_start_location(),
73+
diagnostic.expect_ruff_end_location(),
74+
)
8075
};
8176

8277
let path = self.project_dir.as_ref().map_or_else(
@@ -111,8 +106,11 @@ impl Serialize for SerializedMessages<'_> {
111106
"fingerprint": format!("{:x}", message_fingerprint),
112107
"location": {
113108
"path": path,
114-
"lines": lines
115-
}
109+
"positions": {
110+
"begin": start_location,
111+
"end": end_location,
112+
},
113+
},
116114
});
117115

118116
s.serialize_element(&value)?;

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

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,17 @@ expression: redact_fingerprint(&content)
88
"description": "`os` imported but unused",
99
"fingerprint": "<redacted>",
1010
"location": {
11-
"lines": {
12-
"begin": 1,
13-
"end": 1
14-
},
15-
"path": "fib.py"
11+
"path": "fib.py",
12+
"positions": {
13+
"begin": {
14+
"column": 8,
15+
"line": 1
16+
},
17+
"end": {
18+
"column": 10,
19+
"line": 1
20+
}
21+
}
1622
},
1723
"severity": "major"
1824
},
@@ -21,11 +27,17 @@ expression: redact_fingerprint(&content)
2127
"description": "Local variable `x` is assigned to but never used",
2228
"fingerprint": "<redacted>",
2329
"location": {
24-
"lines": {
25-
"begin": 6,
26-
"end": 6
27-
},
28-
"path": "fib.py"
30+
"path": "fib.py",
31+
"positions": {
32+
"begin": {
33+
"column": 5,
34+
"line": 6
35+
},
36+
"end": {
37+
"column": 6,
38+
"line": 6
39+
}
40+
}
2941
},
3042
"severity": "major"
3143
},
@@ -34,11 +46,17 @@ expression: redact_fingerprint(&content)
3446
"description": "Undefined name `a`",
3547
"fingerprint": "<redacted>",
3648
"location": {
37-
"lines": {
38-
"begin": 1,
39-
"end": 1
40-
},
41-
"path": "undef.py"
49+
"path": "undef.py",
50+
"positions": {
51+
"begin": {
52+
"column": 4,
53+
"line": 1
54+
},
55+
"end": {
56+
"column": 5,
57+
"line": 1
58+
}
59+
}
4260
},
4361
"severity": "major"
4462
}

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

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,17 @@ expression: redact_fingerprint(&content)
88
"description": "Expected one or more symbol names after import",
99
"fingerprint": "<redacted>",
1010
"location": {
11-
"lines": {
12-
"begin": 1,
13-
"end": 2
14-
},
15-
"path": "syntax_errors.py"
11+
"path": "syntax_errors.py",
12+
"positions": {
13+
"begin": {
14+
"column": 15,
15+
"line": 1
16+
},
17+
"end": {
18+
"column": 1,
19+
"line": 2
20+
}
21+
}
1622
},
1723
"severity": "major"
1824
},
@@ -21,11 +27,17 @@ expression: redact_fingerprint(&content)
2127
"description": "Expected ')', found newline",
2228
"fingerprint": "<redacted>",
2329
"location": {
24-
"lines": {
25-
"begin": 3,
26-
"end": 4
27-
},
28-
"path": "syntax_errors.py"
30+
"path": "syntax_errors.py",
31+
"positions": {
32+
"begin": {
33+
"column": 12,
34+
"line": 3
35+
},
36+
"end": {
37+
"column": 1,
38+
"line": 4
39+
}
40+
}
2941
},
3042
"severity": "major"
3143
}

0 commit comments

Comments
 (0)