File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -413,6 +413,46 @@ impl Rule for ForLoopCountReferences {
413
413
}
414
414
```
415
415
416
+ #### Multiple signals
417
+
418
+ Some rules require you to find all possible cases upfront in ` run ` function.
419
+ To achieve that you can change Signals type from ` Option<()> ` to ` Vec<()> ` .
420
+ This will call the diagnostic/action function for every item of the vec.
421
+
422
+ Taking previous example and modifying it a bit we can apply diagnostic for each item easily.
423
+ ``` rust
424
+ impl Rule for ForLoopCountReferences {
425
+ type Query = Semantic <JsForStatement >;
426
+ type State = TextRange ;
427
+ type Signals = Vec <Self :: State >; // Replaced Option with Vec
428
+ type Options = ();
429
+
430
+ fn run (ctx : & RuleContext <Self >) -> Self :: Signals {
431
+ let node = ctx . query ();
432
+
433
+ let model = ctx . model ();
434
+
435
+ ...
436
+
437
+ // Get all write references
438
+ let write_references = binding . all_writes (model );
439
+
440
+ // Find all places where variable is being written to and get node ranges
441
+ let write_ranges = write_references . into_iter (). map (| write | {
442
+ let syntax = write . syntax ();
443
+ let range = syntax . text_range ();
444
+
445
+ Some (range )
446
+ }). collect :: <Vec <_ >>();
447
+
448
+ write_ranges
449
+ }
450
+
451
+ fn diagnostic (_ : & RuleContext <Self >, range : & Self :: State ) -> Option <RuleDiagnostic > {
452
+ // This will be called for each vector item
453
+ }
454
+ }
455
+
416
456
#### Code action
417
457
418
458
A rule can implement a code action . A code action provides to the final user the option to fix or change their code .
You can’t perform that action at this time.
0 commit comments