Skip to content

fix: shorten spans and remove some fixes #260

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Dec 6, 2024
Merged
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
170 changes: 85 additions & 85 deletions Arena.toml

Large diffs are not rendered by default.

33 changes: 21 additions & 12 deletions wdl-lint/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Added

* Added a `RedundantInputAssignment` rule ([#244](https://github.com/stjude-rust-labs/wdl/pull/244))
* Added a `RedundantInputAssignment` rule ([#244](https://github.com/stjude-rust-labs/wdl/pull/244)).

## Changed

* Upgraded some `note` diagnostics to `warning` in `ContainerValue` rule ([#244](https://github.com/stjude-rust-labs/wdl/pull/244)).

## Fixed

* Shortened many reported spans and ensured all lint diagnostics use a `fix` message ([#260](https://github.com/stjude-rust-labs/wdl/pull/260)).
* `BlankLinesBetweenElements` logic was tweaked to prevent firing a redundant message with `VersionFormatting` rule ([#260](https://github.com/stjude-rust-labs/wdl/pull/260)).

## 0.8.0 - 10-22-2024

Expand All @@ -21,28 +30,28 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Changed

* Change how some rules report whitespace spans ([#206](https://github.com/stjude-rust-labs/wdl/pull/206))
* Cover a missing case in `BlankLinesBetweenElements` ([#206](https://github.com/stjude-rust-labs/wdl/pull/206))
* Don't redundantly report the same issue from different rules or checks ([#206](https://github.com/stjude-rust-labs/wdl/pull/206))
* `PreambleComments` and `PreambleWhitespace` have been refactored into 3 rules: `PreambleFormatting`, `VersionFormatting`, and `PreambleCommentAfterVersion` ([#187](https://github.com/stjude-rust-labs/wdl/pull/187))
* test files have been cleaned up ([#187](https://github.com/stjude-rust-labs/wdl/pull/187))
* Some `warning` diagnostics are now `note` diagnostics ([#187](https://github.com/stjude-rust-labs/wdl/pull/187))
* Change how some rules report whitespace spans ([#206](https://github.com/stjude-rust-labs/wdl/pull/206)).
* Cover a missing case in `BlankLinesBetweenElements` ([#206](https://github.com/stjude-rust-labs/wdl/pull/206)).
* Don't redundantly report the same issue from different rules or checks ([#206](https://github.com/stjude-rust-labs/wdl/pull/206)).
* `PreambleComments` and `PreambleWhitespace` have been refactored into 3 rules: `PreambleFormatting`, `VersionFormatting`, and `PreambleCommentAfterVersion` ([#187](https://github.com/stjude-rust-labs/wdl/pull/187)).
* test files have been cleaned up ([#187](https://github.com/stjude-rust-labs/wdl/pull/187)).
* Some `warning` diagnostics are now `note` diagnostics ([#187](https://github.com/stjude-rust-labs/wdl/pull/187)).

### Added

* Added comments to the trailing whitespace check of the `Whitespace` rule ([#177](https://github.com/stjude-rust-labs/wdl/pull/177))
* Added a `MalformedLintDirective` rule ([#194](https://github.com/stjude-rust-labs/wdl/pull/194))
* Added comments to the trailing whitespace check of the `Whitespace` rule ([#177](https://github.com/stjude-rust-labs/wdl/pull/177)).
* Added a `MalformedLintDirective` rule ([#194](https://github.com/stjude-rust-labs/wdl/pull/194)).

### Fixed

* Fixed inline comment detection edge case ([#219](https://github.com/stjude-rust-labs/wdl/pull/219))
* Fixed inline comment detection edge case ([#219](https://github.com/stjude-rust-labs/wdl/pull/219)).

## 0.6.0 - 09-16-2024

### Fixed

* Lint directives finally work :tada: ([#162](https://github.com/stjude-rust-labs/wdl/pull/162))
* Updated iter method in lines_with_offset util function to apply new clippy lint ([#172](https://github.com/stjude-rust-labs/wdl/pull/172))
* Lint directives finally work :tada: ([#162](https://github.com/stjude-rust-labs/wdl/pull/162)).
* Updated iter method in lines_with_offset util function to apply new clippy lint ([#172](https://github.com/stjude-rust-labs/wdl/pull/172)).

## 0.5.0 - 08-22-2024

Expand Down
36 changes: 31 additions & 5 deletions wdl-lint/src/rules/blank_lines_between_elements.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@ fn excess_blank_line(span: Span) -> Diagnostic {
Diagnostic::note("extra blank line(s) found")
.with_rule(ID)
.with_highlight(span)
.with_fix("remove the blank line(s)")
.with_fix("remove extra blank line(s)")
}

/// Creates a missing blank line diagnostic.
fn missing_blank_line(span: Span) -> Diagnostic {
Diagnostic::note("missing blank line")
.with_rule(ID)
.with_highlight(span)
.with_fix("add a blank line before this element")
.with_fix("add a blank line")
}

/// Track the position within a document
Expand Down Expand Up @@ -492,14 +492,21 @@ impl Visitor for BlankLinesBetweenElementsRule {
/// Check if the given syntax node is the first element in the block.
fn is_first_element(syntax: &SyntaxNode) -> bool {
let mut prev = syntax.prev_sibling_or_token();
let mut comment_seen = false;
while let Some(ref cur) = prev {
match cur {
NodeOrToken::Token(t) => {
if t.kind() == SyntaxKind::OpenBrace {
return true;
}
if t.kind() == SyntaxKind::Comment {
comment_seen = true;
}
}
NodeOrToken::Node(_) => {
NodeOrToken::Node(n) => {
if n.kind() == SyntaxKind::VersionStatementNode {
return !comment_seen;
}
return false;
}
}
Expand Down Expand Up @@ -546,6 +553,25 @@ fn check_prior_spacing(
exceptable_nodes: &Option<&'static [SyntaxKind]>,
) {
if let Some(prior) = syntax.prev_sibling_or_token() {
let span = match prior {
NodeOrToken::Token(ref t) => Span::new(
t.text_range().start().into(),
(syntax.text_range().start() - t.text_range().start()).into(),
),
NodeOrToken::Node(ref n) => Span::new(
n.last_token()
.expect("node should have tokens")
.text_range()
.start()
.into(),
(syntax.text_range().start()
- n.last_token()
.expect("node should have tokens")
.text_range()
.start())
.into(),
),
};
match prior.kind() {
SyntaxKind::Whitespace => {
let count = prior
Expand All @@ -572,7 +598,7 @@ fn check_prior_spacing(
}
} else if count < 2 && element_spacing_required {
state.exceptable_add(
missing_blank_line(syntax.text_range().to_span()),
missing_blank_line(span),
SyntaxElement::from(syntax.clone()),
exceptable_nodes,
);
Expand All @@ -584,7 +610,7 @@ fn check_prior_spacing(
// we're missing a blank line.
if element_spacing_required && !first {
state.exceptable_add(
missing_blank_line(syntax.text_range().to_span()),
missing_blank_line(span),
SyntaxElement::from(syntax.clone()),
exceptable_nodes,
);
Expand Down
2 changes: 1 addition & 1 deletion wdl-lint/src/rules/call_input_spacing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fn call_input_missing_newline(span: Span) -> Diagnostic {
Diagnostic::note("call inputs must be separated by newline")
.with_rule(ID)
.with_highlight(span)
.with_fix("add newline before the input")
.with_fix("add a newline after each input")
}

/// Creates call input assignment diagnostic.
Expand Down
2 changes: 1 addition & 1 deletion wdl-lint/src/rules/command_mixed_indentation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ fn mixed_indentation(command: Span, span: Span, kind: IndentationKind) -> Diagno
"this command section uses both tabs and spaces in leading whitespace",
command,
)
.with_fix("use the same whitespace character for indentation")
.with_fix("use either tabs or spaces exclusively for indentation")
}

/// Detects mixed indentation in a command section.
Expand Down
12 changes: 7 additions & 5 deletions wdl-lint/src/rules/comment_whitespace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ fn inline_preceding_whitespace(span: Span) -> Diagnostic {
Diagnostic::note("in-line comments should be preceded by two spaces")
.with_rule(ID)
.with_highlight(span)
.with_fix("this comment must be preceded with two spaces")
.with_fix("add two spaces before the comment delimiter")
}

/// Creates a diagnostic when the comment token is not followed by a single
Expand All @@ -40,7 +40,7 @@ fn following_whitespace(span: Span) -> Diagnostic {
Diagnostic::note("comment delimiter should be followed by a single space")
.with_rule(ID)
.with_highlight(span)
.with_fix("follow this comment delimiter with a single space")
.with_fix("add a single space after the comment delimiter")
}

/// Creates a diagnostic when non-inline comment has insufficient indentation.
Expand Down Expand Up @@ -139,8 +139,9 @@ impl Visitor for CommentWhitespaceRule {
|| prior.as_token().expect("should be a token").text() != " "
{
// Report a diagnostic if there are not two spaces before the comment delimiter
let span = Span::new(comment.span().start(), 1);
state.exceptable_add(
inline_preceding_whitespace(comment.span()),
inline_preceding_whitespace(span),
SyntaxElement::from(comment.syntax().clone()),
&self.exceptable_nodes(),
);
Expand All @@ -167,10 +168,11 @@ impl Visitor for CommentWhitespaceRule {
.expect("should have prior whitespace");
if this_indentation != expected_indentation {
// Report a diagnostic if the comment is not indented properly
let span = Span::new(comment.span().start(), 1);
match this_indentation.len().cmp(&expected_indentation.len()) {
Ordering::Greater => state.exceptable_add(
excess_indentation(
comment.span(),
span,
expected_indentation.len() / INDENT.len(),
this_indentation.len() / INDENT.len(),
),
Expand All @@ -179,7 +181,7 @@ impl Visitor for CommentWhitespaceRule {
),
Ordering::Less => state.exceptable_add(
insufficient_indentation(
comment.span(),
span,
expected_indentation.len() / INDENT.len(),
this_indentation.len() / INDENT.len(),
),
Expand Down
16 changes: 9 additions & 7 deletions wdl-lint/src/rules/container_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ fn mutable_tag(span: Span) -> Diagnostic {

/// Creates an "empty array" diagnostic.
fn empty_array(span: Span) -> Diagnostic {
Diagnostic::note(String::from(
Diagnostic::warning(String::from(
"empty arrays are ambiguous and should contain at least one entry",
))
.with_rule(ID)
Expand All @@ -78,12 +78,14 @@ fn array_to_string_literal(span: Span) -> Diagnostic {
/// Creates a diagnostic indicating that an array contains one or more 'any'
/// URIs.
fn array_containing_anys(spans: impl Iterator<Item = Span>) -> Diagnostic {
let mut diagnostic = Diagnostic::note(String::from("arrays containing any are ambiguous"))
.with_rule(ID)
.with_fix(format!(
"remove these entries or change the array to a string literal with the value of \
`{ANY_CONTAINER_VALUE}`"
));
let mut diagnostic = Diagnostic::warning(format!(
"container arrays containing `{ANY_CONTAINER_VALUE}` are ambiguous"
))
.with_rule(ID)
.with_fix(format!(
"remove these entries or change the array to a string literal with the value of \
`{ANY_CONTAINER_VALUE}`"
));

for span in spans {
diagnostic = diagnostic.with_highlight(span)
Expand Down
4 changes: 2 additions & 2 deletions wdl-lint/src/rules/description_missing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ fn description_missing(span: Span, parent: SectionParent) -> Diagnostic {
))
.with_rule(ID)
.with_highlight(span)
.with_fix("add a `description` key to this meta section")
.with_fix("add a `description` key to the meta section")
}

/// Detects unsorted input declarations.
Expand Down Expand Up @@ -132,7 +132,7 @@ impl Visitor for DescriptionMissingRule {
section
.syntax()
.first_token()
.unwrap()
.expect("metadata section should have tokens")
.text_range()
.to_span(),
section.parent(),
Expand Down
6 changes: 3 additions & 3 deletions wdl-lint/src/rules/disallowed_input_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,23 @@ fn decl_identifier_too_short(span: Span) -> Diagnostic {
Diagnostic::note("declaration identifier must be at least 3 characters")
.with_rule(ID)
.with_highlight(span)
.with_fix("rename the declaration to a name with at least 3 characters")
.with_fix("rename the identifier to be at least 3 characters long")
}

/// Diagnostic for input names that start with [iI]n[A-Z_]
fn decl_identifier_starts_with_in(span: Span) -> Diagnostic {
Diagnostic::note("declaration identifier starts with 'in'")
.with_rule(ID)
.with_highlight(span)
.with_fix("rename the declaration to a name that does not start with 'in'")
.with_fix("rename the identifier to not start with 'in'")
}

/// Diagnostic for input names that start with "input"
fn decl_identifier_starts_with_input(span: Span) -> Diagnostic {
Diagnostic::note("declaration identifier starts with 'input'")
.with_rule(ID)
.with_highlight(span)
.with_fix("rename the declaration to a name that does not start with 'input'")
.with_fix("rename the identifier to not start with 'input'")
}

/// A lint rule for disallowed input names.
Expand Down
6 changes: 3 additions & 3 deletions wdl-lint/src/rules/disallowed_output_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,23 @@ fn decl_identifier_too_short(span: Span) -> Diagnostic {
Diagnostic::note("declaration identifier must be at least 3 characters")
.with_rule(ID)
.with_highlight(span)
.with_fix("rename the declaration to a name with at least 3 characters")
.with_fix("rename the identifier to be at least 3 characters long")
}

/// Diagnostic for input names that start with [oO]ut[A-Z_]
fn decl_identifier_starts_with_out(span: Span) -> Diagnostic {
Diagnostic::note("declaration identifier starts with 'out'")
.with_rule(ID)
.with_highlight(span)
.with_fix("rename the declaration to a name that does not start with 'out'")
.with_fix("rename the identifier to not start with 'out'")
}

/// Diagnostic for input names that start with "output"
fn decl_identifier_starts_with_output(span: Span) -> Diagnostic {
Diagnostic::note("declaration identifier starts with 'output'")
.with_rule(ID)
.with_highlight(span)
.with_fix("rename the declaration to a name that does not start with 'output'")
.with_fix("rename the identifier to not start with 'output'")
}

/// A lint rule for disallowed output names.
Expand Down
2 changes: 1 addition & 1 deletion wdl-lint/src/rules/double_quotes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fn use_double_quotes(span: Span) -> Diagnostic {
Diagnostic::note("string defined with single quotes")
.with_rule(ID)
.with_highlight(span)
.with_fix("change the single quotes to double quotes")
.with_fix("change the string to use double quotes")
}

/// Detects strings that are not defined with double quotes.
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 @@ -23,7 +23,7 @@ fn missing_ending_newline(span: Span) -> Diagnostic {
Diagnostic::note("missing newline at the end of the file")
.with_rule(ID)
.with_label("expected a newline to follow this", span)
.with_fix("add an empty line at the end of the file")
.with_fix("add a newline at the end of the file")
}

/// Creates a "multiple ending newline" diagnostic.
Expand Down
Loading
Loading