Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ serde_with = "3.14.0"
serde_yaml_ng = "0.10.0"
shellexpand = "3.1.1"
strsim = "0.11.1"
strum = { version = "0.27", features = ["derive"] }
sysinfo = "0.37.0"
tempfile = "3.21.0"
thiserror = "2.0.12"
Expand Down
4 changes: 4 additions & 0 deletions wdl-cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

#### Changed

* `Analysis` had its `lint()` method replaced with `enabled_lint_tags()` and `disabled_lint_tags()` ([#592](https://github.com/stjude-rust-labs/wdl/pull/592)).

## 0.5.0 - 08-13-2025

#### Added
Expand Down
90 changes: 75 additions & 15 deletions wdl-cli/src/analysis.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use std::sync::Arc;
use anyhow::Error;
use futures::future::BoxFuture;
use nonempty::NonEmpty;
use tracing::info;
use tracing::warn;
use wdl_analysis::Analyzer;
use wdl_analysis::DiagnosticsConfig;
Expand All @@ -18,6 +19,8 @@ mod source;

pub use results::AnalysisResults;
pub use source::Source;
use wdl_lint::Rule;
use wdl_lint::TagSet;

/// The type of the initialization callback.
type InitCb = Box<dyn Fn() + 'static>;
Expand All @@ -36,8 +39,11 @@ pub struct Analysis {
/// A list of rules to except.
exceptions: HashSet<String>,

/// Whether or not to enable linting.
lint: bool,
/// Which lint rules to enable, as specified via a [`TagSet`].
enabled_lint_tags: TagSet,

/// Which lint rules to disable, as specified via a [`TagSet`].
disabled_lint_tags: TagSet,

/// Basename for any ignorefiles which should be respected.
ignore_filename: Option<String>,
Expand Down Expand Up @@ -74,12 +80,6 @@ impl Analysis {
self
}

/// Sets whether linting is enabled.
pub fn lint(mut self, value: bool) -> Self {
self.lint = value;
self
}

/// Sets the ignorefile basename.
pub fn ignore_filename(mut self, filename: Option<String>) -> Self {
self.ignore_filename = filename;
Expand All @@ -104,9 +104,39 @@ impl Analysis {
self
}

/// Sets the enabled lint tags.
pub fn enabled_lint_tags(mut self, tags: TagSet) -> Self {
self.enabled_lint_tags = tags;
self
}

/// Sets the disabled lint tags.
pub fn disabled_lint_tags(mut self, tags: TagSet) -> Self {
self.disabled_lint_tags = tags;
self
}

/// Runs the analysis and returns all results (if any exist).
pub async fn run(self) -> std::result::Result<AnalysisResults, NonEmpty<Arc<Error>>> {
warn_unknown_rules(&self.exceptions);
if tracing::enabled!(tracing::Level::INFO) {
let mut enabled_rules = vec![];
let mut disabled_rules = vec![];
for rule in wdl_lint::rules() {
if is_rule_enabled(
&self.enabled_lint_tags,
&self.disabled_lint_tags,
&self.exceptions,
rule.as_ref(),
) {
enabled_rules.push(rule.id());
} else {
disabled_rules.push(rule.id());
}
}
info!("enabled lint rules: {:?}", enabled_rules);
info!("disabled lint rules: {:?}", disabled_rules);
}
let config = wdl_analysis::Config::default()
.with_diagnostics_config(get_diagnostics_config(&self.exceptions))
.with_ignore_filename(self.ignore_filename);
Expand All @@ -116,8 +146,12 @@ impl Analysis {
let validator = Box::new(move || {
let mut validator = Validator::default();

if self.lint {
let visitor = get_lint_visitor(&self.exceptions);
if self.enabled_lint_tags.count() > 0 {
let visitor = get_lint_visitor(
&self.enabled_lint_tags,
&self.disabled_lint_tags,
&self.exceptions,
);
validator.add_visitor(visitor);
}

Expand Down Expand Up @@ -150,7 +184,8 @@ impl Default for Analysis {
Self {
sources: Default::default(),
exceptions: Default::default(),
lint: Default::default(),
enabled_lint_tags: TagSet::new(&[]),
disabled_lint_tags: TagSet::new(&[]),
ignore_filename: None,
init: Box::new(|| {}),
progress: Box::new(|_, _, _| Box::pin(async {})),
Expand Down Expand Up @@ -194,11 +229,36 @@ fn get_diagnostics_config(exceptions: &HashSet<String>) -> DiagnosticsConfig {
}))
}

/// Gets a lint visitor with the excepted rules removed.
fn get_lint_visitor(exceptions: &HashSet<String>) -> Linter {
Linter::new(wdl_lint::rules().into_iter().filter(|rule| {
!exceptions
/// Determines if a rule should be enabled.
fn is_rule_enabled(
enabled_lint_tags: &TagSet,
disabled_lint_tags: &TagSet,
exceptions: &HashSet<String>,
rule: &dyn Rule,
) -> bool {
enabled_lint_tags.intersect(rule.tags()).count() > 0
&& disabled_lint_tags.intersect(rule.tags()).count() == 0
&& !exceptions
.iter()
.any(|exception| exception.eq_ignore_ascii_case(rule.id()))
}

/// Gets a lint visitor with the rules depending on provided options.
///
/// `enabled_lint_tags` controls which rules are considered for being added to
/// the visitor. `disabled_lint_tags` and `exceptions` act as filters on the set
/// considerd by `enabled_lint_tags`.
fn get_lint_visitor(
enabled_lint_tags: &TagSet,
disabled_lint_tags: &TagSet,
exceptions: &HashSet<String>,
) -> Linter {
Linter::new(wdl_lint::rules().into_iter().filter(|rule| {
is_rule_enabled(
enabled_lint_tags,
disabled_lint_tags,
exceptions,
rule.as_ref(),
)
}))
}
2 changes: 1 addition & 1 deletion wdl-grammar/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ logos = { workspace = true }
rowan = { workspace = true }
serde = { workspace = true }
serde_with = { workspace = true }
strum = { version = "0.27", features = ["derive"] }
strum = { workspace = true }

[dev-dependencies]
anyhow = { workspace = true }
Expand Down
10 changes: 10 additions & 0 deletions wdl-lint/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

#### Added

* New `Tag::Documentation` ([#592](https://github.com/stjude-rust-labs/wdl/pull/592)).

#### Fixed

* The `LineWidth` lint rule now ignores import statements ([#590](https://github.com/stjude-rust-labs/wdl/pull/590)).

#### Changed

* Some lint rules had their `tags()` modified ([#592](https://github.com/stjude-rust-labs/wdl/pull/592)).
* `TagSet::new()` now allows empty TagSets to be created ([#592](https://github.com/stjude-rust-labs/wdl/pull/592)).
* `TagSet::new()` no longer implicitly adds `Tag::Style` to sets including `Tag::Naming` or `Tag::Spacing` ([#592](https://github.com/stjude-rust-labs/wdl/pull/592)).

## 0.15.0 - 08-13-2025

## 0.14.0 - 07-31-2025
Expand Down
1 change: 1 addition & 0 deletions wdl-lint/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ rowan = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
strsim = { workspace = true }
strum = { workspace = true }
tracing = { workspace = true }
url = { workspace = true }
wdl-analysis = { path = "../wdl-analysis", version = "0.12.0" }
Expand Down
2 changes: 1 addition & 1 deletion wdl-lint/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ pub trait Rule: Visitor {
fn related_rules(&self) -> &[&'static str];
}

/// Gets the default rule set.
/// Gets all of the lint rules.
pub fn rules() -> Vec<Box<dyn Rule>> {
let rules: Vec<Box<dyn Rule>> = vec![
Box::<rules::DoubleQuotesRule>::default(),
Expand Down
4 changes: 2 additions & 2 deletions wdl-lint/src/rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ mod line_width;
mod lint_directive_formatted;
mod lint_directive_valid;
mod matching_output_meta;
mod meta_decscription;
mod meta_description;
mod meta_key_value_formatting;
mod meta_sections;
mod output_name;
Expand Down Expand Up @@ -69,7 +69,7 @@ pub use line_width::*;
pub use lint_directive_formatted::*;
pub use lint_directive_valid::*;
pub use matching_output_meta::*;
pub use meta_decscription::*;
pub use meta_description::*;
pub use meta_key_value_formatting::*;
pub use meta_sections::*;
pub use output_name::*;
Expand Down
2 changes: 1 addition & 1 deletion wdl-lint/src/rules/comment_whitespace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl Rule for CommentWhitespaceRule {
}

fn tags(&self) -> TagSet {
TagSet::new(&[Tag::Spacing])
TagSet::new(&[Tag::Spacing, Tag::Style])
}

fn exceptable_nodes(&self) -> Option<&'static [SyntaxKind]> {
Expand Down
2 changes: 1 addition & 1 deletion wdl-lint/src/rules/element_spacing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl Rule for ElementSpacingRule {
}

fn tags(&self) -> TagSet {
TagSet::new(&[Tag::Spacing])
TagSet::new(&[Tag::Spacing, Tag::Style])
}

fn exceptable_nodes(&self) -> Option<&'static [SyntaxKind]> {
Expand Down
2 changes: 1 addition & 1 deletion wdl-lint/src/rules/ending_newline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl Rule for EndingNewlineRule {
}

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

fn exceptable_nodes(&self) -> Option<&'static [SyntaxKind]> {
Expand Down
2 changes: 1 addition & 1 deletion wdl-lint/src/rules/expression_spacing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ impl Rule for ExpressionSpacingRule {
}

fn tags(&self) -> TagSet {
TagSet::new(&[Tag::Spacing])
TagSet::new(&[Tag::Spacing, Tag::Style])
}

fn exceptable_nodes(&self) -> Option<&'static [SyntaxKind]> {
Expand Down
2 changes: 1 addition & 1 deletion wdl-lint/src/rules/input_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl Rule for InputNameRule {
}

fn tags(&self) -> TagSet {
TagSet::new(&[Tag::Naming])
TagSet::new(&[Tag::Naming, Tag::Style])
}

fn exceptable_nodes(&self) -> Option<&'static [wdl_ast::SyntaxKind]> {
Expand Down
2 changes: 1 addition & 1 deletion wdl-lint/src/rules/matching_output_meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ impl Rule for MatchingOutputMetaRule<'_> {
}

fn tags(&self) -> TagSet {
TagSet::new(&[Tag::Completeness])
TagSet::new(&[Tag::Completeness, Tag::Documentation])
}

fn exceptable_nodes(&self) -> Option<&'static [SyntaxKind]> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl Rule for MetaDescriptionRule {
}

fn tags(&self) -> TagSet {
TagSet::new(&[Tag::Completeness])
TagSet::new(&[Tag::Completeness, Tag::Documentation])
}

fn exceptable_nodes(&self) -> Option<&'static [wdl_ast::SyntaxKind]> {
Expand Down
2 changes: 1 addition & 1 deletion wdl-lint/src/rules/meta_sections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl Rule for MetaSectionsRule {
}

fn tags(&self) -> TagSet {
TagSet::new(&[Tag::Completeness, Tag::Clarity])
TagSet::new(&[Tag::Completeness, Tag::Clarity, Tag::Documentation])
}

fn exceptable_nodes(&self) -> Option<&'static [SyntaxKind]> {
Expand Down
2 changes: 1 addition & 1 deletion wdl-lint/src/rules/output_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ impl Rule for OutputNameRule {
}

fn tags(&self) -> TagSet {
TagSet::new(&[Tag::Naming])
TagSet::new(&[Tag::Naming, Tag::Style])
}

fn exceptable_nodes(&self) -> Option<&'static [wdl_ast::SyntaxKind]> {
Expand Down
2 changes: 1 addition & 1 deletion wdl-lint/src/rules/parameter_meta_matched.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ impl Rule for ParameterMetaMatchedRule {
}

fn tags(&self) -> TagSet {
TagSet::new(&[Tag::Completeness, Tag::Sorting])
TagSet::new(&[Tag::Completeness, Tag::Sorting, Tag::Documentation])
}

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