mirror of
https://github.com/astral-sh/ruff
synced 2026-01-20 21:10:48 -05:00
Added pylint formatter (#1995)
Fixes: #1953 @charliermarsh thank you for the tips in the issue. I'm not very familiar with Rust, so please excuse if my string formatting syntax is messy. In terms of testing, I compared output of `flake8 --format=pylint ` and `cargo run --format=pylint` on the same code and the output syntax seems to check out.
This commit is contained in:
@@ -319,6 +319,9 @@ pub fn explain(rule: &Rule, format: SerializationFormat) -> Result<()> {
|
||||
SerializationFormat::Gitlab => {
|
||||
bail!("`--explain` does not support GitLab format")
|
||||
}
|
||||
SerializationFormat::Pylint => {
|
||||
bail!("`--explain` does not support pylint format")
|
||||
}
|
||||
};
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@@ -285,7 +285,7 @@ impl<'a> Printer<'a> {
|
||||
}
|
||||
}
|
||||
SerializationFormat::Gitlab => {
|
||||
// Generate JSON with errors in GitLab CI format
|
||||
// Generate JSON with violations in GitLab CI format
|
||||
// https://docs.gitlab.com/ee/ci/testing/code_quality.html#implementing-a-custom-tool
|
||||
writeln!(stdout,
|
||||
"{}",
|
||||
@@ -312,6 +312,20 @@ impl<'a> Printer<'a> {
|
||||
)?
|
||||
)?;
|
||||
}
|
||||
SerializationFormat::Pylint => {
|
||||
// Generate violations in Pylint format.
|
||||
// See: https://flake8.pycqa.org/en/latest/internal/formatters.html#pylint-formatter
|
||||
for message in &diagnostics.messages {
|
||||
let label = format!(
|
||||
"{}:{}: [{}] {}",
|
||||
relativize_path(Path::new(&message.filename)),
|
||||
message.location.row(),
|
||||
message.kind.rule().code(),
|
||||
message.kind.body(),
|
||||
);
|
||||
writeln!(stdout, "{label}")?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
stdout.flush()?;
|
||||
|
||||
Reference in New Issue
Block a user