mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-02 06:42:02 +00:00
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:
parent
8fd29b3b60
commit
f1cdd108e6
262 changed files with 400 additions and 537 deletions
|
@ -10,6 +10,7 @@ pub fn define_rule_mapping(mapping: &Mapping) -> proc_macro2::TokenStream {
|
|||
let mut diagnostic_kind_variants = quote!();
|
||||
let mut rule_message_formats_match_arms = quote!();
|
||||
let mut rule_autofixable_match_arms = quote!();
|
||||
let mut rule_explanation_match_arms = quote!();
|
||||
let mut rule_code_match_arms = quote!();
|
||||
let mut rule_from_code_match_arms = quote!();
|
||||
let mut diagnostic_kind_code_match_arms = quote!();
|
||||
|
@ -32,6 +33,7 @@ pub fn define_rule_mapping(mapping: &Mapping) -> proc_macro2::TokenStream {
|
|||
.extend(quote! {#(#attr)* Self::#name => <#path as Violation>::message_formats(),});
|
||||
rule_autofixable_match_arms
|
||||
.extend(quote! {#(#attr)* Self::#name => <#path as Violation>::AUTOFIX,});
|
||||
rule_explanation_match_arms.extend(quote! {#(#attr)* Self::#name => #path::explanation(),});
|
||||
rule_code_match_arms.extend(quote! {#(#attr)* Self::#name => #code_str,});
|
||||
rule_from_code_match_arms.extend(quote! {#(#attr)* #code_str => Ok(Rule::#name), });
|
||||
diagnostic_kind_code_match_arms
|
||||
|
@ -97,6 +99,10 @@ pub fn define_rule_mapping(mapping: &Mapping) -> proc_macro2::TokenStream {
|
|||
match self { #rule_message_formats_match_arms }
|
||||
}
|
||||
|
||||
pub fn explanation(&self) -> Option<&'static str> {
|
||||
match self { #rule_explanation_match_arms }
|
||||
}
|
||||
|
||||
pub fn autofixable(&self) -> Option<crate::violation::AutofixKind> {
|
||||
match self { #rule_autofixable_match_arms }
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue