@@ -56,7 +56,7 @@ impl LintResult {
56
56
}
57
57
}
58
58
59
- pub fn to_linting_error ( & self , rule : ErasedRule , fixes : Vec < LintFix > ) -> Option < SQLLintError > {
59
+ pub fn to_linting_error ( & self , rule : & ErasedRule ) -> Option < SQLLintError > {
60
60
let anchor = self . anchor . clone ( ) ?;
61
61
62
62
let description = self
@@ -66,7 +66,7 @@ impl LintResult {
66
66
67
67
let is_fixable = rule. is_fix_compatible ( ) ;
68
68
69
- SQLLintError :: new ( description. as_str ( ) , anchor, is_fixable, fixes)
69
+ SQLLintError :: new ( description. as_str ( ) , anchor, is_fixable, self . fixes . clone ( ) )
70
70
. config ( |this| {
71
71
this. rule = Some ( ErrorStructRule {
72
72
name : rule. name ( ) ,
@@ -107,23 +107,13 @@ impl Debug for LintResult {
107
107
}
108
108
}
109
109
110
- pub trait CloneRule {
111
- fn erased ( & self ) -> ErasedRule ;
112
- }
113
-
114
- impl < T : Rule > CloneRule for T {
115
- fn erased ( & self ) -> ErasedRule {
116
- dyn_clone:: clone ( self ) . erased ( )
117
- }
118
- }
119
-
120
110
#[ derive( Debug , Clone , PartialEq ) ]
121
111
pub enum LintPhase {
122
112
Main ,
123
113
Post ,
124
114
}
125
115
126
- pub trait Rule : CloneRule + dyn_clone :: DynClone + Debug + ' static + Send + Sync {
116
+ pub trait Rule : Debug + ' static + Send + Sync {
127
117
fn load_from_config ( & self , _config : & AHashMap < String , Value > ) -> Result < ErasedRule , String > ;
128
118
129
119
fn lint_phase ( & self ) -> LintPhase {
@@ -171,74 +161,72 @@ pub trait Rule: CloneRule + dyn_clone::DynClone + Debug + 'static + Send + Sync
171
161
}
172
162
173
163
fn crawl_behaviour ( & self ) -> Crawler ;
164
+ }
174
165
175
- fn crawl (
176
- & self ,
177
- tables : & Tables ,
178
- dialect : & Dialect ,
179
- templated_file : & TemplatedFile ,
180
- tree : ErasedSegment ,
181
- config : & FluffConfig ,
182
- ) -> Vec < SQLLintError > {
183
- let mut root_context = RuleContext :: new ( tables, dialect, config, tree. clone ( ) ) ;
184
- let mut vs = Vec :: new ( ) ;
185
-
186
- // TODO Will to return a note that rules were skipped
187
- if self . dialect_skip ( ) . contains ( & dialect. name ) && !self . force_enable ( ) {
188
- return Vec :: new ( ) ;
189
- }
166
+ pub fn crawl (
167
+ rule : & ErasedRule ,
168
+ tables : & Tables ,
169
+ dialect : & Dialect ,
170
+ templated_file : & TemplatedFile ,
171
+ tree : ErasedSegment ,
172
+ config : & FluffConfig ,
173
+ ) -> Vec < SQLLintError > {
174
+ let mut root_context = RuleContext :: new ( tables, dialect, config, tree. clone ( ) ) ;
175
+ let mut vs = Vec :: new ( ) ;
176
+
177
+ // TODO Will to return a note that rules were skipped
178
+ if rule . dialect_skip ( ) . contains ( & dialect. name ) && !rule . force_enable ( ) {
179
+ return Vec :: new ( ) ;
180
+ }
190
181
191
- self . crawl_behaviour ( ) . crawl ( & mut root_context, & mut |context| {
192
- let resp =
193
- std:: panic:: catch_unwind ( std:: panic:: AssertUnwindSafe ( || self . eval ( context) ) ) ;
182
+ rule . crawl_behaviour ( ) . crawl ( & mut root_context, & mut |context| {
183
+ let resp =
184
+ std:: panic:: catch_unwind ( std:: panic:: AssertUnwindSafe ( || rule . eval ( context) ) ) ;
194
185
195
- let resp = match resp {
196
- Ok ( t) => t,
197
- Err ( _) => {
198
- vs. push ( SQLLintError :: new ( "Unexpected exception. Could you open an issue at https://github.com/quarylabs/sqruff" , tree. clone ( ) , false , vec ! [ ] ) ) ;
199
- Vec :: new ( )
200
- }
201
- } ;
186
+ let resp = match resp {
187
+ Ok ( t) => t,
188
+ Err ( _) => {
189
+ vs. push ( SQLLintError :: new ( "Unexpected exception. Could you open an issue at https://github.com/quarylabs/sqruff" , tree. clone ( ) , false , vec ! [ ] ) ) ;
190
+ Vec :: new ( )
191
+ }
192
+ } ;
202
193
203
- let mut new_lerrs = Vec :: new ( ) ;
194
+ let mut new_lerrs = Vec :: new ( ) ;
204
195
205
- if resp. is_empty ( ) {
206
- // Assume this means no problems (also means no memory)
207
- } else {
208
- for elem in resp {
209
- self . process_lint_result ( elem, templated_file, & mut new_lerrs) ;
210
- }
196
+ if resp. is_empty ( ) {
197
+ // Assume this means no problems (also means no memory)
198
+ } else {
199
+ for elem in resp {
200
+ process_lint_result ( rule, elem, templated_file, & mut new_lerrs) ;
211
201
}
202
+ }
212
203
213
- // Consume the new results
214
- vs. extend ( new_lerrs) ;
215
- } ) ;
204
+ // Consume the new results
205
+ vs. extend ( new_lerrs) ;
206
+ } ) ;
216
207
217
- vs
218
- }
208
+ vs
209
+ }
219
210
220
- fn process_lint_result (
221
- & self ,
222
- res : LintResult ,
223
- templated_file : & TemplatedFile ,
224
- new_lerrs : & mut Vec < SQLLintError > ,
225
- ) {
226
- if res
227
- . fixes
228
- . iter ( )
229
- . any ( |it| it. has_template_conflicts ( templated_file) )
230
- {
231
- return ;
232
- }
211
+ fn process_lint_result (
212
+ rule : & ErasedRule ,
213
+ res : LintResult ,
214
+ templated_file : & TemplatedFile ,
215
+ new_lerrs : & mut Vec < SQLLintError > ,
216
+ ) {
217
+ if res
218
+ . fixes
219
+ . iter ( )
220
+ . any ( |it| it. has_template_conflicts ( templated_file) )
221
+ {
222
+ return ;
223
+ }
233
224
234
- if let Some ( lerr) = res. to_linting_error ( self . erased ( ) , res. fixes . clone ( ) ) {
235
- new_lerrs. push ( lerr) ;
236
- }
225
+ if let Some ( lerr) = res. to_linting_error ( rule) {
226
+ new_lerrs. push ( lerr) ;
237
227
}
238
228
}
239
229
240
- dyn_clone:: clone_trait_object!( Rule ) ;
241
-
242
230
#[ derive( Debug , Clone ) ]
243
231
pub struct ErasedRule {
244
232
erased : Arc < dyn Rule > ,
0 commit comments