Skip to content
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

fix: redundant-none-rule #324 #333

Open
wants to merge 19 commits into
base: main
Choose a base branch
from

Conversation

prathmesh703
Copy link

@prathmesh703 prathmesh703 commented Mar 4, 2025

START SECTION: adding a new linting rule

This pull request adds a new rule to wdl-lint.

  • Rule Name: redundant-rule

fixes #324
added the lint rule that fires when = None is redundantly specified.

Before submitting this PR, please make sure:

  • You have added a few sentences describing the PR here.
  • You have added yourself or the appropriate individual as the assignee.
  • You have added at least one relevant code reviewer to the PR.
  • Your code builds clean without any errors or warnings.
  • You have added an entry to the relevant CHANGELOG.md (see
    "keep a changelog" for more information).
  • Your commit messages follow the conventional commit style.

Rule specific checks:

  • You have added the rule as an entry within RULES.md.
  • You have added the rule to the rules() function in wdl-lint/src/lib.rs.
  • You have added a test case in wdl-lint/tests/lints that covers every
    possible diagnostic emitted for the rule within the file where the rule
    is implemented.
  • [ ] If you have implemented a new Visitor callback, you have also
    overridden that callback method for the special Validator
    (wdl-ast/src/validation.rs) and LintVisitor
    (wdl-lint/src/visitor.rs) visitors. These are required to ensure the new
    visitor callback will execute.
  • You have run gauntlet --refresh to ensure that there are no
    unintended changes to the baseline configuration file (Gauntlet.toml).
  • You have run gauntlet --refresh --arena to ensure that all of the
    rules added/removed are now reflected in the baseline configuration file
    (Arena.toml).

Comment on lines 50 to 54
wdl_ast::SyntaxKind::VersionStatementNode,
wdl_ast::SyntaxKind::WorkflowDefinitionNode,
wdl_ast::SyntaxKind::TaskDefinitionNode,
wdl_ast::SyntaxKind::InputSectionNode,
wdl_ast::SyntaxKind::BoundDeclNode,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
wdl_ast::SyntaxKind::VersionStatementNode,
wdl_ast::SyntaxKind::WorkflowDefinitionNode,
wdl_ast::SyntaxKind::TaskDefinitionNode,
wdl_ast::SyntaxKind::InputSectionNode,
wdl_ast::SyntaxKind::BoundDeclNode,
wdl_ast::SyntaxKind::VersionStatementNode,
wdl_ast::SyntaxKind::InputSectionNode,
wdl_ast::SyntaxKind::BoundDeclNode,

}

fn tags(&self) -> TagSet {
TagSet::new(&[Tag::Style])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
TagSet::new(&[Tag::Style])
TagSet::new(&[Tag::Clarity])

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally, I'd tag it with both.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yea that's true. It should have both the Clarity and Style tag to be consistent with other similar rules.


fn explanation(&self) -> &'static str {
"Optional inputs with explicit None assignments can be simplified. For example, \
String? foo = None can be shortened to String? foo."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@a-frantz - I don't particularly like this snippet from the spec (the variable names, that is), but showing that the two are equivalent could be helpful as part of this text. I've made a simple edit suggestion below, but I'm curious if you think a longer explanation is preferable.

    # the following are equivalent undefined optional declarations
    String? maybe_five_but_is_not
    String? also_maybe_five_but_is_not = None
Suggested change
String? foo = None can be shortened to String? foo."
`String? foo = None` is equivalent to and can be shortened to `String? foo`."

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm ambivalent between your suggested edit and making it more verbose. I think the shorter text is "ok", but when the day comes that we create a dedicated website/wiki for all the lints, we might want to expand on it to include some "full" code snippets as examples. But given that we're currently only rendering this text in the terminal (from sprocket explain <rule>), brevity might be preferable?

Copy link
Member

@a-frantz a-frantz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please follow the instructions in the PR checklist to get this incorporated correctly. Your new rule isn't currently running, so we can't see what the diagnostics look like once rendered.

@prathmesh703
Copy link
Author

@a-frantz please can you tell me where i'm getting wrong and what should i do ?

@a-frantz
Copy link
Member

a-frantz commented Mar 9, 2025

From the PR template checklist:

You have added the rule to the rules() function in wdl-lint/src/lib.rs.

This is needed so that your new rule can execute in the tests.

While you're at that, please go through the rest of the checklist and make any changes needed there.

@a-frantz
Copy link
Member

please fix all the errors reported by our CI before further review

@prathmesh703
Copy link
Author

sure

@prathmesh703 prathmesh703 marked this pull request as draft March 19, 2025 11:01
@prathmesh703 prathmesh703 changed the title Fixes #324 redundant-none-rule fix: redundant-none-rule #324 Mar 19, 2025
@claymcleod claymcleod added the S-awaiting-revisions State: awaiting revisions based on code review feedback label Mar 19, 2025
@prathmesh703 prathmesh703 marked this pull request as ready for review March 22, 2025 05:25
@claymcleod claymcleod added S-needs-review State: awaiting initial or additional review and removed S-awaiting-revisions State: awaiting revisions based on code review feedback labels Mar 23, 2025
note[CallInputSpacing]: call input not properly spaced
┌─ tests/lints/redudant-none/source.wdl:16:21
16 │ call test_task {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd fix this one and all of the non-relevant rules—we want tests to only show results for the specific rule that we are testing, not introduce unrelated warnings that need to be excepted.

input {
String required_str
Int? optional_int # should not flag, correct optional syntax
String? optional_str = None # should flag, redundant None for optional
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see this one being flagged in the output.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@claymcleod sorry ! I will check it soon

@prathmesh703
Copy link
Author

@a-frantz I will fix this soon

@prathmesh703
Copy link
Author

@a-frantz error: missing documentation for a module --> wdl-lint\src\rules.rs:36:1 | 36 | mod redundant_none; | ^^^^^^^^^^^^^^^^^^^
This error is coming on failing of the CI/lint
How to fix this type of error . Do I have to add documentation anywhere?

@a-frantz
Copy link
Member

@a-frantz error: missing documentation for a module --> wdl-lint\src\rules.rs:36:1 | 36 | mod redundant_none; | ^^^^^^^^^^^^^^^^^^^ This error is coming on failing of the CI/lint How to fix this type of error . Do I have to add documentation anywhere?

Yes, you need to add documentation to everywhere that clippy reports is missing documentation. You can check locally by running cargo clippy --all-features and it will point out everywhere that needs to be documented.

@a-frantz
Copy link
Member

@peterhuene peterhuene added the S-awaiting-pass-CI State: awaiting the CI to pass label Mar 25, 2025
@claymcleod claymcleod removed the S-needs-review State: awaiting initial or additional review label Mar 26, 2025
@claymcleod claymcleod force-pushed the main branch 3 times, most recently from 3dc8137 to f4c832c Compare March 26, 2025 01:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-awaiting-pass-CI State: awaiting the CI to pass
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New lint rule: don't redundantly specify = None for optional inputs
6 participants