aboutsummaryrefslogtreecommitdiff
path: root/mingling_cli/tmpls/lints.tmpl
diff options
context:
space:
mode:
Diffstat (limited to 'mingling_cli/tmpls/lints.tmpl')
-rw-r--r--mingling_cli/tmpls/lints.tmpl35
1 files changed, 13 insertions, 22 deletions
diff --git a/mingling_cli/tmpls/lints.tmpl b/mingling_cli/tmpls/lints.tmpl
index fae1126..3b20ed4 100644
--- a/mingling_cli/tmpls/lints.tmpl
+++ b/mingling_cli/tmpls/lints.tmpl
@@ -12,11 +12,9 @@ pub fn run_all_lints(file: &syn::File, source: &str) -> Vec<MlintReport> {
>>>>>>>>>> calls;
@@@ >>> calls
- // Check item-level #[mlint(allow/warn/deny(<<<name>>>))]
let skip = get_mlint_override(&f.attrs, "<<<name>>>") == Some(MlintLevelOverride::Allow);
if !skip {
let mut rs = <<<name>>>::linter(f.clone(), source);
- // Apply deny override at item level
if get_mlint_override(&f.attrs, "<<<name>>>") == Some(MlintLevelOverride::Deny) {
for r in &mut rs { r.level = MlintLevel::Error; }
}
@@ -25,46 +23,39 @@ pub fn run_all_lints(file: &syn::File, source: &str) -> Vec<MlintReport> {
@@@ <<<
}
}
- // Apply file-level #![mlint(allow/warn/deny(...))] overrides
for r in &mut reports {
let name = &r.lint_code;
if let Some(override_level) = get_mlint_override(&file.attrs, name) {
match override_level {
- MlintLevelOverride::Allow => {
- // remove by marking; filtered below
- r.level = MlintLevel::Help; // sentinel: filtered out
- }
- MlintLevelOverride::Deny => {
- r.level = MlintLevel::Error;
- }
+ MlintLevelOverride::Allow => r.level = MlintLevel::Help,
+ MlintLevelOverride::Deny => r.level = MlintLevel::Error,
MlintLevelOverride::Warn => {
- if r.level != MlintLevel::Error {
- r.level = MlintLevel::Warning;
- }
+ if r.level != MlintLevel::Error { r.level = MlintLevel::Warning; }
}
}
}
}
- // Remove allowed reports (sentinel = Help)
reports.retain(|r| r.level != MlintLevel::Help);
reports
}
#[macro_export]
macro_rules! assert_detected {
- ($linter:expr, $ast_type:ty => $code:tt) => {
- // Parse the string into a syn::ItemFn
- let ast: $ast_type = syn::parse_str(&stringify!($code)).unwrap();
- assert!(!$linter(ast, &stringify!($code).to_string()).is_empty());
+ ($linter:expr, $ast_type:ty => { $($code:tt)* }) => {
+ // $($code:tt)* captures tokens INSIDE the braces, not including the braces
+ // e.g. `fn foo() { ... }` — exactly what syn::ItemFn expects
+ let source = stringify!($($code)*);
+ let ast: $ast_type = syn::parse_str(&source).unwrap();
+ assert!(!$linter(ast, &source).is_empty());
};
}
#[macro_export]
macro_rules! assert_not_detected {
- ($linter:expr, $ast_type:ty => $code:tt) => {
- // Parse the string into a syn::ItemFn
- let ast: $ast_type = syn::parse_str(&stringify!($code)).unwrap();
- assert!($linter(ast, &stringify!($code).to_string()).is_empty());
+ ($linter:expr, $ast_type:ty => { $($code:tt)* }) => {
+ let source = stringify!($($code)*);
+ let ast: $ast_type = syn::parse_str(&source).unwrap();
+ assert!($linter(ast, &source).is_empty());
};
}