@@ -18,6 +18,7 @@ mod source;
1818
1919pub use results:: AnalysisResults ;
2020pub use source:: Source ;
21+ use wdl_lint:: TagSet ;
2122
2223/// The type of the initialization callback.
2324type InitCb = Box < dyn Fn ( ) + ' static > ;
@@ -36,8 +37,11 @@ pub struct Analysis {
3637 /// A list of rules to except.
3738 exceptions : HashSet < String > ,
3839
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 ,
42+
43+ /// Which lint rules to disable, as specified via a [`TagSet`].
44+ disabled_lint_tags : TagSet ,
4145
4246 /// Basename for any ignorefiles which should be respected.
4347 ignore_filename : Option < String > ,
@@ -74,12 +78,6 @@ impl Analysis {
7478 self
7579 }
7680
77- /// Sets whether linting is enabled.
78- pub fn lint ( mut self , value : bool ) -> Self {
79- self . lint = value;
80- self
81- }
82-
8381 /// Sets the ignorefile basename.
8482 pub fn ignore_filename ( mut self , filename : Option < String > ) -> Self {
8583 self . ignore_filename = filename;
@@ -104,6 +102,18 @@ impl Analysis {
104102 self
105103 }
106104
105+ /// Sets the enabled lint tags.
106+ pub fn enabled_lint_tags ( mut self , tags : TagSet ) -> Self {
107+ self . enabled_lint_tags = tags;
108+ self
109+ }
110+
111+ /// Sets the disabled lint tags.
112+ pub fn disabled_lint_tags ( mut self , tags : TagSet ) -> Self {
113+ self . disabled_lint_tags = tags;
114+ self
115+ }
116+
107117 /// Runs the analysis and returns all results (if any exist).
108118 pub async fn run ( self ) -> std:: result:: Result < AnalysisResults , NonEmpty < Arc < Error > > > {
109119 warn_unknown_rules ( & self . exceptions ) ;
@@ -116,8 +126,12 @@ impl Analysis {
116126 let validator = Box :: new ( move || {
117127 let mut validator = Validator :: default ( ) ;
118128
119- if self . lint {
120- let visitor = get_lint_visitor ( & self . exceptions ) ;
129+ if self . enabled_lint_tags . count ( ) > 0 {
130+ let visitor = get_lint_visitor (
131+ & self . enabled_lint_tags ,
132+ & self . disabled_lint_tags ,
133+ & self . exceptions ,
134+ ) ;
121135 validator. add_visitor ( visitor) ;
122136 }
123137
@@ -150,7 +164,8 @@ impl Default for Analysis {
150164 Self {
151165 sources : Default :: default ( ) ,
152166 exceptions : Default :: default ( ) ,
153- lint : Default :: default ( ) ,
167+ enabled_lint_tags : TagSet :: new ( & [ ] ) ,
168+ disabled_lint_tags : TagSet :: new ( & [ ] ) ,
154169 ignore_filename : None ,
155170 init : Box :: new ( || { } ) ,
156171 progress : Box :: new ( |_, _, _| Box :: pin ( async { } ) ) ,
@@ -195,10 +210,16 @@ fn get_diagnostics_config(exceptions: &HashSet<String>) -> DiagnosticsConfig {
195210}
196211
197212/// Gets a lint visitor with the excepted rules removed.
198- fn get_lint_visitor ( exceptions : & HashSet < String > ) -> Linter {
213+ fn get_lint_visitor (
214+ enabled_lint_tags : & TagSet ,
215+ disabled_lint_tags : & TagSet ,
216+ exceptions : & HashSet < String > ,
217+ ) -> Linter {
199218 Linter :: new ( wdl_lint:: rules ( ) . into_iter ( ) . filter ( |rule| {
200- !exceptions
201- . iter ( )
202- . any ( |exception| exception. eq_ignore_ascii_case ( rule. id ( ) ) )
219+ enabled_lint_tags. intersect ( rule. tags ( ) ) . count ( ) > 0
220+ && disabled_lint_tags. intersect ( rule. tags ( ) ) . count ( ) == 0
221+ && !exceptions
222+ . iter ( )
223+ . any ( |exception| exception. eq_ignore_ascii_case ( rule. id ( ) ) )
203224 } ) )
204225}
0 commit comments