Skip to content

Commit 456df15

Browse files
committed
revise: lint rules are enabled via TagSet instead of "all" or "none"
1 parent c0a9ec8 commit 456df15

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

wdl-cli/src/analysis.rs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ mod source;
1818

1919
pub use results::AnalysisResults;
2020
pub use source::Source;
21+
use wdl_lint::TagSet;
2122

2223
/// The type of the initialization callback.
2324
type InitCb = Box<dyn Fn() + 'static>;
@@ -36,8 +37,8 @@ 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,
4142

4243
/// Basename for any ignorefiles which should be respected.
4344
ignore_filename: Option<String>,
@@ -74,12 +75,6 @@ impl Analysis {
7475
self
7576
}
7677

77-
/// Sets whether linting is enabled.
78-
pub fn lint(mut self, value: bool) -> Self {
79-
self.lint = value;
80-
self
81-
}
82-
8378
/// Sets the ignorefile basename.
8479
pub fn ignore_filename(mut self, filename: Option<String>) -> Self {
8580
self.ignore_filename = filename;
@@ -104,6 +99,12 @@ impl Analysis {
10499
self
105100
}
106101

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+
107108
/// Runs the analysis and returns all results (if any exist).
108109
pub async fn run(self) -> std::result::Result<AnalysisResults, NonEmpty<Arc<Error>>> {
109110
warn_unknown_rules(&self.exceptions);
@@ -116,8 +117,8 @@ impl Analysis {
116117
let validator = Box::new(move || {
117118
let mut validator = Validator::default();
118119

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);
121122
validator.add_visitor(visitor);
122123
}
123124

@@ -150,7 +151,7 @@ impl Default for Analysis {
150151
Self {
151152
sources: Default::default(),
152153
exceptions: Default::default(),
153-
lint: Default::default(),
154+
enabled_lint_tags: TagSet::new(&[]),
154155
ignore_filename: None,
155156
init: Box::new(|| {}),
156157
progress: Box::new(|_, _, _| Box::pin(async {})),
@@ -195,10 +196,11 @@ fn get_diagnostics_config(exceptions: &HashSet<String>) -> DiagnosticsConfig {
195196
}
196197

197198
/// 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 {
199200
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()))
203205
}))
204206
}

0 commit comments

Comments
 (0)