mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-27 04:19:43 +00:00
Deprecate define violation (#3358)
* Add `#[violation]` proc macro as a replacement for `define_violation!` * Switch all rules to #[violation]
This commit is contained in:
parent
22e6778e17
commit
348a38d261
305 changed files with 4680 additions and 4635 deletions
|
@ -2,7 +2,7 @@
|
|||
|
||||
use crate::cache_key::derive_cache_key;
|
||||
use proc_macro::TokenStream;
|
||||
use syn::{parse_macro_input, DeriveInput, ItemFn};
|
||||
use syn::{parse_macro_input, DeriveInput, ItemFn, ItemStruct};
|
||||
|
||||
mod cache_key;
|
||||
mod config;
|
||||
|
@ -45,6 +45,16 @@ pub fn define_violation(item: proc_macro::TokenStream) -> proc_macro::TokenStrea
|
|||
define_violation::define_violation(&item.into(), meta).into()
|
||||
}
|
||||
|
||||
/// Adds an `explanation()` method from the doc comment and
|
||||
/// `#[derive(Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]`
|
||||
#[proc_macro_attribute]
|
||||
pub fn violation(_attr: TokenStream, item: TokenStream) -> TokenStream {
|
||||
let violation = parse_macro_input!(item as ItemStruct);
|
||||
define_violation::violation(&violation)
|
||||
.unwrap_or_else(syn::Error::into_compile_error)
|
||||
.into()
|
||||
}
|
||||
|
||||
#[proc_macro_derive(RuleNamespace, attributes(prefix))]
|
||||
pub fn derive_rule_namespace(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
|
||||
let input = parse_macro_input!(input as DeriveInput);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue