@@ -18,6 +18,7 @@ mod source;
18
18
19
19
pub use results:: AnalysisResults ;
20
20
pub use source:: Source ;
21
+ use wdl_lint:: TagSet ;
21
22
22
23
/// The type of the initialization callback.
23
24
type InitCb = Box < dyn Fn ( ) + ' static > ;
@@ -36,8 +37,8 @@ pub struct Analysis {
36
37
/// A list of rules to except.
37
38
exceptions : HashSet < String > ,
38
39
39
- /// Whether or not to enable linting .
40
- lint : bool ,
40
+ /// Which lint rules to enable, as specified via a [`TagSet`] .
41
+ enabled_lint_tags : TagSet ,
41
42
42
43
/// Basename for any ignorefiles which should be respected.
43
44
ignore_filename : Option < String > ,
@@ -74,12 +75,6 @@ impl Analysis {
74
75
self
75
76
}
76
77
77
- /// Sets whether linting is enabled.
78
- pub fn lint ( mut self , value : bool ) -> Self {
79
- self . lint = value;
80
- self
81
- }
82
-
83
78
/// Sets the ignorefile basename.
84
79
pub fn ignore_filename ( mut self , filename : Option < String > ) -> Self {
85
80
self . ignore_filename = filename;
@@ -104,6 +99,12 @@ impl Analysis {
104
99
self
105
100
}
106
101
102
+ /// Sets the enabled lint tags.
103
+ pub fn enabled_lint_tags ( mut self , tags : TagSet ) -> Self {
104
+ self . enabled_lint_tags = tags;
105
+ self
106
+ }
107
+
107
108
/// Runs the analysis and returns all results (if any exist).
108
109
pub async fn run ( self ) -> std:: result:: Result < AnalysisResults , NonEmpty < Arc < Error > > > {
109
110
warn_unknown_rules ( & self . exceptions ) ;
@@ -116,8 +117,8 @@ impl Analysis {
116
117
let validator = Box :: new ( move || {
117
118
let mut validator = Validator :: default ( ) ;
118
119
119
- if self . lint {
120
- let visitor = get_lint_visitor ( & self . exceptions ) ;
120
+ if self . enabled_lint_tags . count ( ) > 0 {
121
+ let visitor = get_lint_visitor ( & self . enabled_lint_tags , & self . exceptions ) ;
121
122
validator. add_visitor ( visitor) ;
122
123
}
123
124
@@ -150,7 +151,7 @@ impl Default for Analysis {
150
151
Self {
151
152
sources : Default :: default ( ) ,
152
153
exceptions : Default :: default ( ) ,
153
- lint : Default :: default ( ) ,
154
+ enabled_lint_tags : TagSet :: new ( & [ ] ) ,
154
155
ignore_filename : None ,
155
156
init : Box :: new ( || { } ) ,
156
157
progress : Box :: new ( |_, _, _| Box :: pin ( async { } ) ) ,
@@ -195,10 +196,11 @@ fn get_diagnostics_config(exceptions: &HashSet<String>) -> DiagnosticsConfig {
195
196
}
196
197
197
198
/// Gets a lint visitor with the excepted rules removed.
198
- fn get_lint_visitor ( exceptions : & HashSet < String > ) -> Linter {
199
+ fn get_lint_visitor ( enabled_lint_tags : & TagSet , exceptions : & HashSet < String > ) -> Linter {
199
200
Linter :: new ( wdl_lint:: rules ( ) . into_iter ( ) . filter ( |rule| {
200
- !exceptions
201
- . iter ( )
202
- . any ( |exception| exception. eq_ignore_ascii_case ( rule. id ( ) ) )
201
+ enabled_lint_tags. union ( rule. tags ( ) ) . count ( ) > 0
202
+ && !exceptions
203
+ . iter ( )
204
+ . any ( |exception| exception. eq_ignore_ascii_case ( rule. id ( ) ) )
203
205
} ) )
204
206
}
0 commit comments