Include column numbers in GitLab output format. (#19708)

This commit is contained in:
cristian64 2025-08-03 14:37:01 +02:00 committed by GitHub
parent 6bd413df6c
commit bc6e105c18
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 100 additions and 54 deletions

View file

@ -22,11 +22,17 @@ exit_code: 1
"description": "`os` imported but unused", "description": "`os` imported but unused",
"fingerprint": "4dbad37161e65c72", "fingerprint": "4dbad37161e65c72",
"location": { "location": {
"lines": { "path": "input.py",
"begin": 1, "positions": {
"end": 1 "begin": {
}, "column": 8,
"path": "input.py" "line": 1
},
"end": {
"column": 10,
"line": 1
}
}
}, },
"severity": "major" "severity": "major"
}, },
@ -35,11 +41,17 @@ exit_code: 1
"description": "Undefined name `y`", "description": "Undefined name `y`",
"fingerprint": "7af59862a085230", "fingerprint": "7af59862a085230",
"location": { "location": {
"lines": { "path": "input.py",
"begin": 2, "positions": {
"end": 2 "begin": {
}, "column": 5,
"path": "input.py" "line": 2
},
"end": {
"column": 6,
"line": 2
}
}
}, },
"severity": "major" "severity": "major"
}, },
@ -48,11 +60,17 @@ exit_code: 1
"description": "Cannot use `match` statement on Python 3.9 (syntax was added in Python 3.10)", "description": "Cannot use `match` statement on Python 3.9 (syntax was added in Python 3.10)",
"fingerprint": "e558cec859bb66e8", "fingerprint": "e558cec859bb66e8",
"location": { "location": {
"lines": { "path": "input.py",
"begin": 3, "positions": {
"end": 3 "begin": {
}, "column": 1,
"path": "input.py" "line": 3
},
"end": {
"column": 6,
"line": 3
}
}
}, },
"severity": "major" "severity": "major"
} }

View file

@ -61,22 +61,17 @@ impl Serialize for SerializedMessages<'_> {
let mut fingerprints = HashSet::<u64>::with_capacity(self.diagnostics.len()); let mut fingerprints = HashSet::<u64>::with_capacity(self.diagnostics.len());
for diagnostic in self.diagnostics { for diagnostic in self.diagnostics {
let start_location = diagnostic.expect_ruff_start_location();
let end_location = diagnostic.expect_ruff_end_location();
let filename = diagnostic.expect_ruff_filename(); let filename = diagnostic.expect_ruff_filename();
let lines = if self.context.is_notebook(&filename) {
let (start_location, end_location) = if self.context.is_notebook(&filename) {
// We can't give a reasonable location for the structured formats, // We can't give a reasonable location for the structured formats,
// so we show one that's clearly a fallback // so we show one that's clearly a fallback
json!({ Default::default()
"begin": 1,
"end": 1
})
} else { } else {
json!({ (
"begin": start_location.line, diagnostic.expect_ruff_start_location(),
"end": end_location.line diagnostic.expect_ruff_end_location(),
}) )
}; };
let path = self.project_dir.as_ref().map_or_else( let path = self.project_dir.as_ref().map_or_else(
@ -111,8 +106,11 @@ impl Serialize for SerializedMessages<'_> {
"fingerprint": format!("{:x}", message_fingerprint), "fingerprint": format!("{:x}", message_fingerprint),
"location": { "location": {
"path": path, "path": path,
"lines": lines "positions": {
} "begin": start_location,
"end": end_location,
},
},
}); });
s.serialize_element(&value)?; s.serialize_element(&value)?;

View file

@ -8,11 +8,17 @@ expression: redact_fingerprint(&content)
"description": "`os` imported but unused", "description": "`os` imported but unused",
"fingerprint": "<redacted>", "fingerprint": "<redacted>",
"location": { "location": {
"lines": { "path": "fib.py",
"begin": 1, "positions": {
"end": 1 "begin": {
}, "column": 8,
"path": "fib.py" "line": 1
},
"end": {
"column": 10,
"line": 1
}
}
}, },
"severity": "major" "severity": "major"
}, },
@ -21,11 +27,17 @@ expression: redact_fingerprint(&content)
"description": "Local variable `x` is assigned to but never used", "description": "Local variable `x` is assigned to but never used",
"fingerprint": "<redacted>", "fingerprint": "<redacted>",
"location": { "location": {
"lines": { "path": "fib.py",
"begin": 6, "positions": {
"end": 6 "begin": {
}, "column": 5,
"path": "fib.py" "line": 6
},
"end": {
"column": 6,
"line": 6
}
}
}, },
"severity": "major" "severity": "major"
}, },
@ -34,11 +46,17 @@ expression: redact_fingerprint(&content)
"description": "Undefined name `a`", "description": "Undefined name `a`",
"fingerprint": "<redacted>", "fingerprint": "<redacted>",
"location": { "location": {
"lines": { "path": "undef.py",
"begin": 1, "positions": {
"end": 1 "begin": {
}, "column": 4,
"path": "undef.py" "line": 1
},
"end": {
"column": 5,
"line": 1
}
}
}, },
"severity": "major" "severity": "major"
} }

View file

@ -8,11 +8,17 @@ expression: redact_fingerprint(&content)
"description": "Expected one or more symbol names after import", "description": "Expected one or more symbol names after import",
"fingerprint": "<redacted>", "fingerprint": "<redacted>",
"location": { "location": {
"lines": { "path": "syntax_errors.py",
"begin": 1, "positions": {
"end": 2 "begin": {
}, "column": 15,
"path": "syntax_errors.py" "line": 1
},
"end": {
"column": 1,
"line": 2
}
}
}, },
"severity": "major" "severity": "major"
}, },
@ -21,11 +27,17 @@ expression: redact_fingerprint(&content)
"description": "Expected ')', found newline", "description": "Expected ')', found newline",
"fingerprint": "<redacted>", "fingerprint": "<redacted>",
"location": { "location": {
"lines": { "path": "syntax_errors.py",
"begin": 3, "positions": {
"end": 4 "begin": {
}, "column": 12,
"path": "syntax_errors.py" "line": 3
},
"end": {
"column": 1,
"line": 4
}
}
}, },
"severity": "major" "severity": "major"
} }