diff --git a/README.md b/README.md index 18311967fb..54bac0199b 100644 --- a/README.md +++ b/README.md @@ -381,7 +381,7 @@ Options: --per-file-ignores List of mappings from file pattern to code to exclude --format - Output serialization format for violations [env: RUFF_FORMAT=] [possible values: text, json, junit, grouped, github, gitlab] + Output serialization format for violations [env: RUFF_FORMAT=] [possible values: text, json, junit, grouped, github, gitlab, pylint] --stdin-filename The name of the file when passing it through stdin --cache-dir @@ -2120,9 +2120,9 @@ force-exclude = true The style in which violation messages should be formatted: `"text"` (default), `"grouped"` (group messages by file), `"json"` -(machine-readable), `"junit"` (machine-readable XML), `"github"` -(GitHub Actions annotations) or `"gitlab"` -(GitLab CI code quality report). +(machine-readable), `"junit"` (machine-readable XML), `"github"` (GitHub +Actions annotations), `"gitlab"` (GitLab CI code quality report), or +`"pylint"` (Pylint text format). **Default value**: `"text"` diff --git a/ruff.schema.json b/ruff.schema.json index 607aa67f9f..ac1ace87d5 100644 --- a/ruff.schema.json +++ b/ruff.schema.json @@ -227,7 +227,7 @@ ] }, "format": { - "description": "The style in which violation messages should be formatted: `\"text\"` (default), `\"grouped\"` (group messages by file), `\"json\"` (machine-readable), `\"junit\"` (machine-readable XML), `\"github\"` (GitHub Actions annotations) or `\"gitlab\"` (GitLab CI code quality report).", + "description": "The style in which violation messages should be formatted: `\"text\"` (default), `\"grouped\"` (group messages by file), `\"json\"` (machine-readable), `\"junit\"` (machine-readable XML), `\"github\"` (GitHub Actions annotations), `\"gitlab\"` (GitLab CI code quality report), or `\"pylint\"` (Pylint text format).", "anyOf": [ { "$ref": "#/definitions/SerializationFormat" @@ -1804,7 +1804,8 @@ "junit", "grouped", "github", - "gitlab" + "gitlab", + "pylint" ] }, "Strictness": { diff --git a/ruff_cli/src/commands.rs b/ruff_cli/src/commands.rs index 2f9f003292..71b8a4219f 100644 --- a/ruff_cli/src/commands.rs +++ b/ruff_cli/src/commands.rs @@ -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(()) } diff --git a/ruff_cli/src/printer.rs b/ruff_cli/src/printer.rs index 632a0d8bbc..abfd789147 100644 --- a/ruff_cli/src/printer.rs +++ b/ruff_cli/src/printer.rs @@ -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()?; diff --git a/src/settings/options.rs b/src/settings/options.rs index cae0e58934..5c909003c1 100644 --- a/src/settings/options.rs +++ b/src/settings/options.rs @@ -208,9 +208,9 @@ pub struct Options { )] /// The style in which violation messages should be formatted: `"text"` /// (default), `"grouped"` (group messages by file), `"json"` - /// (machine-readable), `"junit"` (machine-readable XML), `"github"` - /// (GitHub Actions annotations) or `"gitlab"` - /// (GitLab CI code quality report). + /// (machine-readable), `"junit"` (machine-readable XML), `"github"` (GitHub + /// Actions annotations), `"gitlab"` (GitLab CI code quality report), or + /// `"pylint"` (Pylint text format). pub format: Option, #[option( default = r#"false"#, diff --git a/src/settings/types.rs b/src/settings/types.rs index 7a61dad928..92e3fa7e60 100644 --- a/src/settings/types.rs +++ b/src/settings/types.rs @@ -156,6 +156,7 @@ pub enum SerializationFormat { Grouped, Github, Gitlab, + Pylint, } impl Default for SerializationFormat {