diff options
| author | 魏曹先生 <1992414357@qq.com> | 2026-07-21 15:59:01 +0800 |
|---|---|---|
| committer | 魏曹先生 <1992414357@qq.com> | 2026-07-21 15:59:01 +0800 |
| commit | 05a06b59d2a27428d253308f067aa0e5a841eb5e (patch) | |
| tree | b1176b831e42a7dff4a8b0bcbb35fc7755164c77 /mingling_cli/tmpls | |
| parent | 770d738829076e0be2152452ab68933a47a483e2 (diff) | |
feat(lints): add quote dependency and improve variable name detection
Use `quote` token stream matching instead of debug formatting
to detect variable references in `unnecessary_render_result_creation`,
fixing false positives from string-based matching.
Diffstat (limited to 'mingling_cli/tmpls')
| -rw-r--r-- | mingling_cli/tmpls/lints.tmpl | 35 |
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()); }; } |
