Decouple Diagnostic from "all violations" enumeration (#3352)

This commit is contained in:
Charlie Marsh 2023-03-08 12:51:37 -05:00 committed by GitHub
parent bc869d4f52
commit ffad0bcdaa
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
804 changed files with 14764 additions and 6792 deletions

View file

@ -46,6 +46,19 @@ pub fn violation(violation: &ItemStruct) -> Result<TokenStream> {
quote! {
#[derive(Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
#violation
impl From<#ident> for crate::registry::DiagnosticKind {
fn from(value: #ident) -> Self {
use crate::violation::Violation;
Self {
body: Violation::message(&value),
fixable: value.autofix_title_formatter().is_some(),
commit: value.autofix_title_formatter().map(|f| f(&value)),
name: stringify!(#ident).to_string(),
}
}
}
}
} else {
quote! {
@ -57,6 +70,19 @@ pub fn violation(violation: &ItemStruct) -> Result<TokenStream> {
Some(#explanation)
}
}
impl From<#ident> for crate::registry::DiagnosticKind {
fn from(value: #ident) -> Self {
use crate::violation::Violation;
Self {
body: Violation::message(&value),
fixable: value.autofix_title_formatter().is_some(),
commit: value.autofix_title_formatter().map(|f| f(&value)),
name: stringify!(#ident).to_string(),
}
}
}
}
};
Ok(violation)