Expose more fields in rule explanation (#4367)

This commit is contained in:
Jonathan Plasse 2023-05-12 01:22:23 +02:00 committed by GitHub
parent c10a4535b9
commit 1380bd94da
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 0 deletions

View File

@ -10,9 +10,13 @@ use crate::args::HelpFormat;
#[derive(Serialize)] #[derive(Serialize)]
struct Explanation<'a> { struct Explanation<'a> {
name: &'a str,
code: &'a str, code: &'a str,
linter: &'a str, linter: &'a str,
summary: &'a str, summary: &'a str,
message_formats: &'a [&'a str],
autofix: &'a str,
explanation: Option<&'a str>,
} }
/// Explain a `Rule` to the user. /// Explain a `Rule` to the user.
@ -51,9 +55,13 @@ pub(crate) fn rule(rule: Rule, format: HelpFormat) -> Result<()> {
} }
HelpFormat::Json => { HelpFormat::Json => {
output.push_str(&serde_json::to_string_pretty(&Explanation { output.push_str(&serde_json::to_string_pretty(&Explanation {
name: rule.as_ref(),
code: &rule.noqa_code().to_string(), code: &rule.noqa_code().to_string(),
linter: linter.name(), linter: linter.name(),
summary: rule.message_formats()[0], summary: rule.message_formats()[0],
message_formats: rule.message_formats(),
autofix: &rule.autofixable().to_string(),
explanation: rule.explanation(),
})?); })?);
} }
}; };