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/src/lints | |
| 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/src/lints')
| -rw-r--r-- | mingling_cli/src/lints/unnecessary_render_result_creation.rs | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/mingling_cli/src/lints/unnecessary_render_result_creation.rs b/mingling_cli/src/lints/unnecessary_render_result_creation.rs index 06c47d9..03f81d2 100644 --- a/mingling_cli/src/lints/unnecessary_render_result_creation.rs +++ b/mingling_cli/src/lints/unnecessary_render_result_creation.rs @@ -15,6 +15,7 @@ //! Default: `warn` use crate::linter::mlint_report::{MlintLevel, MlintReport}; +use quote::ToTokens; pub fn linter(ast: syn::ItemFn, source: &str) -> Vec<MlintReport> { if !has_renderer_attr(&ast) { @@ -169,8 +170,19 @@ fn check_stmt_usage(stmt: &syn::Stmt, r_name: &str, print_count: &mut usize) -> } } - let s = format!("{stmt:#?}"); - !s.contains(&format!("\"{r_name}\"")) + // Any other reference to r → not allowed + // Check the token stream for the variable name + let ts_string = stmt.to_token_stream().to_string(); + if ts_string.contains(&format!("({r_name})")) + || ts_string.contains(&format!(" {r_name})")) + || ts_string.contains(&format!("(&mut {r_name})")) + || ts_string.contains(&format!("&{r_name}")) + || ts_string.contains(&format!("move {r_name}")) + || ts_string.contains(&format!(",{r_name},")) + { + return false; + } + true } #[cfg(test)] |
