From 1380bd94dad3bb1ad049365a6070fe01dd04e807 Mon Sep 17 00:00:00 2001 From: Jonathan Plasse <13716151+JonathanPlasse@users.noreply.github.com> Date: Fri, 12 May 2023 01:22:23 +0200 Subject: [PATCH] Expose more fields in rule explanation (#4367) --- crates/ruff_cli/src/commands/rule.rs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/crates/ruff_cli/src/commands/rule.rs b/crates/ruff_cli/src/commands/rule.rs index 22fab36073..b0fc26978b 100644 --- a/crates/ruff_cli/src/commands/rule.rs +++ b/crates/ruff_cli/src/commands/rule.rs @@ -10,9 +10,13 @@ use crate::args::HelpFormat; #[derive(Serialize)] struct Explanation<'a> { + name: &'a str, code: &'a str, linter: &'a str, summary: &'a str, + message_formats: &'a [&'a str], + autofix: &'a str, + explanation: Option<&'a str>, } /// Explain a `Rule` to the user. @@ -51,9 +55,13 @@ pub(crate) fn rule(rule: Rule, format: HelpFormat) -> Result<()> { } HelpFormat::Json => { output.push_str(&serde_json::to_string_pretty(&Explanation { + name: rule.as_ref(), code: &rule.noqa_code().to_string(), linter: linter.name(), summary: rule.message_formats()[0], + message_formats: rule.message_formats(), + autofix: &rule.autofixable().to_string(), + explanation: rule.explanation(), })?); } };