Skip to content
This repository was archived by the owner on Sep 24, 2025. It is now read-only.

Commit 1f776d6

Browse files
committed
revise: lint rules can be enabled/disabled via TagSet
1 parent c0a9ec8 commit 1f776d6

File tree

11 files changed

+99
-31
lines changed

11 files changed

+99
-31
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ serde_json = "1.0.140"
8080
serde_with = "3.14.0"
8181
serde_yaml_ng = "0.10.0"
8282
shellexpand = "3.1.1"
83+
strum = { version = "0.27", features = ["derive"] }
8384
strsim = "0.11.1"
8485
sysinfo = "0.37.0"
8586
tempfile = "3.21.0"

wdl-cli/src/analysis.rs

Lines changed: 36 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,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
}

wdl-grammar/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ logos = { workspace = true }
1919
rowan = { workspace = true }
2020
serde = { workspace = true }
2121
serde_with = { workspace = true }
22-
strum = { version = "0.27", features = ["derive"] }
22+
strum = { workspace = true }
2323

2424
[dev-dependencies]
2525
anyhow = { workspace = true }

wdl-lint/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ rand = { workspace = true }
2323
rowan = { workspace = true }
2424
serde = { workspace = true }
2525
serde_json = { workspace = true }
26+
strum = { workspace = true }
2627
strsim = { workspace = true }
2728
tracing = { workspace = true }
2829
url = { workspace = true }

wdl-lint/src/rules/comment_whitespace.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ impl Rule for CommentWhitespaceRule {
8787
}
8888

8989
fn tags(&self) -> TagSet {
90-
TagSet::new(&[Tag::Spacing])
90+
TagSet::new(&[Tag::Spacing, Tag::Style])
9191
}
9292

9393
fn exceptable_nodes(&self) -> Option<&'static [SyntaxKind]> {

wdl-lint/src/rules/element_spacing.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ impl Rule for ElementSpacingRule {
9999
}
100100

101101
fn tags(&self) -> TagSet {
102-
TagSet::new(&[Tag::Spacing])
102+
TagSet::new(&[Tag::Spacing, Tag::Style])
103103
}
104104

105105
fn exceptable_nodes(&self) -> Option<&'static [SyntaxKind]> {

wdl-lint/src/rules/ending_newline.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl Rule for EndingNewlineRule {
5959
}
6060

6161
fn tags(&self) -> TagSet {
62-
TagSet::new(&[Tag::Spacing, Tag::Style])
62+
TagSet::new(&[Tag::Spacing, Tag::Portability])
6363
}
6464

6565
fn exceptable_nodes(&self) -> Option<&'static [SyntaxKind]> {

wdl-lint/src/rules/expression_spacing.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ impl Rule for ExpressionSpacingRule {
194194
}
195195

196196
fn tags(&self) -> TagSet {
197-
TagSet::new(&[Tag::Spacing])
197+
TagSet::new(&[Tag::Spacing, Tag::Style])
198198
}
199199

200200
fn exceptable_nodes(&self) -> Option<&'static [SyntaxKind]> {

wdl-lint/src/rules/input_name.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ impl Rule for InputNameRule {
7070
}
7171

7272
fn tags(&self) -> TagSet {
73-
TagSet::new(&[Tag::Naming])
73+
TagSet::new(&[Tag::Naming, Tag::Style])
7474
}
7575

7676
fn exceptable_nodes(&self) -> Option<&'static [wdl_ast::SyntaxKind]> {

wdl-lint/src/rules/output_name.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ impl Rule for OutputNameRule {
7070
}
7171

7272
fn tags(&self) -> TagSet {
73-
TagSet::new(&[Tag::Naming])
73+
TagSet::new(&[Tag::Naming, Tag::Style])
7474
}
7575

7676
fn exceptable_nodes(&self) -> Option<&'static [wdl_ast::SyntaxKind]> {

0 commit comments

Comments
 (0)