aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/src/lib.rs12
-rw-r--r--macros/src/lib.rs16
2 files changed, 21 insertions, 7 deletions
diff --git a/lib/src/lib.rs b/lib/src/lib.rs
index 4065345..4374ac7 100644
--- a/lib/src/lib.rs
+++ b/lib/src/lib.rs
@@ -112,7 +112,7 @@ pub trait Metadata {
112 where 112 where
113 Self: Sized; 113 Self: Sized;
114 fn match_with(&self, with: &SyntaxKind) -> bool; 114 fn match_with(&self, with: &SyntaxKind) -> bool;
115 fn match_kind(&self) -> SyntaxKind; 115 fn match_kind(&self) -> Vec<SyntaxKind>;
116} 116}
117 117
118/// Combines Rule and Metadata, do not implement manually, this is derived by 118/// Combines Rule and Metadata, do not implement manually, this is derived by
@@ -140,10 +140,12 @@ macro_rules! lint_map {
140 $( 140 $(
141 { 141 {
142 let temp_lint = &*$s::LINT; 142 let temp_lint = &*$s::LINT;
143 let temp_match = temp_lint.match_kind(); 143 let temp_matches = temp_lint.match_kind();
144 map.entry(temp_match) 144 for temp_match in temp_matches {
145 .and_modify(|v: &mut Vec<_>| v.push(temp_lint)) 145 map.entry(temp_match)
146 .or_insert_with(|| vec![temp_lint]); 146 .and_modify(|v: &mut Vec<_>| v.push(temp_lint))
147 .or_insert_with(|| vec![temp_lint]);
148 }
147 } 149 }
148 )* 150 )*
149 map 151 map
diff --git a/macros/src/lib.rs b/macros/src/lib.rs
index c33fcba..127b4cb 100644
--- a/macros/src/lib.rs
+++ b/macros/src/lib.rs
@@ -139,6 +139,12 @@ fn generate_match_with_fn(meta: &LintMeta) -> TokenStream2 {
139 #match_path == *with 139 #match_path == *with
140 } 140 }
141 } 141 }
142 } else if let syn::Expr::Array(array_expr) = match_with_lit {
143 quote! {
144 fn match_with(&self, with: &SyntaxKind) -> bool {
145 #array_expr.contains(with)
146 }
147 }
142 } else { 148 } else {
143 panic!("`match_with` has non-path value") 149 panic!("`match_with` has non-path value")
144 } 150 }
@@ -151,8 +157,14 @@ fn generate_match_kind(meta: &LintMeta) -> TokenStream2 {
151 .unwrap_or_else(|| panic!("`match_with` not present")); 157 .unwrap_or_else(|| panic!("`match_with` not present"));
152 if let syn::Expr::Path(match_path) = match_with_lit { 158 if let syn::Expr::Path(match_path) = match_with_lit {
153 quote! { 159 quote! {
154 fn match_kind(&self) -> SyntaxKind { 160 fn match_kind(&self) -> Vec<SyntaxKind> {
155 #match_path 161 vec![#match_path]
162 }
163 }
164 } else if let syn::Expr::Array(array_expr) = match_with_lit {
165 quote! {
166 fn match_kind(&self) -> Vec<SyntaxKind> {
167 #array_expr.to_vec()
156 } 168 }
157 } 169 }
158 } else { 170 } else {