Derive explanation method on Rule struct via rustdoc (#2642)

```console
❯ cargo run rule B017
    Finished dev [unoptimized + debuginfo] target(s) in 0.13s
     Running `target/debug/ruff rule B017`
no-assert-raises-exception

Code: B017 (flake8-bugbear)

### What it does
Checks for `self.assertRaises(Exception)`.

## Why is this bad?
`assertRaises(Exception)` can lead to your test passing even if the
code being tested is never executed due to a typo.

Either assert for a more specific exception (builtin or custom), use
`assertRaisesRegex` or the context manager form of `assertRaises`.
```
This commit is contained in:
Charlie Marsh 2023-02-07 17:23:29 -05:00 committed by GitHub
parent 8fd29b3b60
commit f1cdd108e6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
262 changed files with 400 additions and 537 deletions

View file

@ -1,10 +1,10 @@
//! This crate implements internal macros for the `ruff` library.
use proc_macro::TokenStream;
use syn::{parse_macro_input, DeriveInput, ItemFn};
mod config;
mod define_rule_mapping;
mod define_violation;
mod derive_message_formats;
mod rule_code_prefix;
mod rule_namespace;
@ -24,6 +24,13 @@ pub fn define_rule_mapping(item: proc_macro::TokenStream) -> proc_macro::TokenSt
define_rule_mapping::define_rule_mapping(&mapping).into()
}
#[proc_macro]
pub fn define_violation(item: proc_macro::TokenStream) -> proc_macro::TokenStream {
let cloned = item.clone();
let meta = parse_macro_input!(cloned as define_violation::LintMeta);
define_violation::define_violation(&item.into(), meta).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);
@ -34,7 +41,10 @@ pub fn derive_rule_namespace(input: proc_macro::TokenStream) -> proc_macro::Toke
}
#[proc_macro_attribute]
pub fn derive_message_formats(_attr: TokenStream, item: TokenStream) -> TokenStream {
pub fn derive_message_formats(
_attr: proc_macro::TokenStream,
item: proc_macro::TokenStream,
) -> proc_macro::TokenStream {
let func = parse_macro_input!(item as ItemFn);
derive_message_formats::derive_message_formats(&func).into()
}