-
Notifications
You must be signed in to change notification settings - Fork 27
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
feat: implement DisallowedDeclarationName
rule
#343
base: main
Are you sure you want to change the base?
feat: implement DisallowedDeclarationName
rule
#343
Conversation
follow the PR template please. Re-write your PR description according to https://github.com/stjude-rust-labs/wdl/blob/main/.github/pull_request_template.md?plain=1 |
…ct types in declaration names
6587d56
to
41148c2
Compare
@a-frantz I've addressed all your feedback:
All tests are now passing. Let me know if you'd like me to make any additional improvements! |
I think your force push went wrong. I still see the old code I reviewed earlier. |
beebcb5
to
41148c2
Compare
@a-frantz I just force-pushed the updated implementation again. You should now be able to see the changes that address all your feedback. Let me know if you have any further questions or if there are additional improvements needed. |
still seeing the old code. I think there's something wrong with your |
Also, your PR description still doesn't have the proper checklist items. Please copy and paste from the template I linked earlier |
111492e
to
5e3649f
Compare
@a-frantz I've made another push with a visible marker comment at the top of the file: //! FIXING PUSH ISSUE - THIS COMMENT SHOULD BE VISIBLE IN THE PR Please check the "Files changed" tab to verify that you can now see the updated code. The changes should now include:
Let me know if you still can't see the updated code. |
@a-frantz I've updated the PR description to use the proper template with checklist items as requested. Also, I've made another push with visible changes to the rule file - you should now be able to see the updated implementation in the "Files changed" tab. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe there was some confusion earlier. I see your push worked, but there are still some issues that I highlighted before that weren't resolved. I unresolved the relevant github threads.
326aadf
to
87d9332
Compare
@a-frantz I've addressed all your feedback:
I've pushed all these changes. Please let me know if there's anything else I need to fix. |
5e7a53f
to
77b3457
Compare
@a-frantz sorry to bother you again |
DisallowedDeclarationName
DisallowedDeclarationName
DisallowedDeclarationName
rule
@a-frantz, this is ready for rereview. |
SyntaxKind::InputSectionNode, | ||
SyntaxKind::OutputSectionNode, | ||
SyntaxKind::BoundDeclNode, | ||
SyntaxKind::UnboundDeclNode, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
context: We try to keep each list of "exceptable nodes" minimal, preferring the most specific node when excepting two different nodes would lead to the same behavior.
That being said, this will need to be expanded to include task and workflow definition nodes so that all private declarations of a task or workflow can be "excepted" at once. That would make this list one of our longer lists of exceptable nodes, but each node would cover a different set of declarations.
Please add those two nodes to this list, and then I think we'll have all our bases covered.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
task and workflow definitions still need to be added here
let name = decl.name(); | ||
let name_str = name.as_str(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: these don't get used till line 172, and I prefer to keep declarations close to where they're used. Can you move these down? It reduces the need to scroll up and down looking for where something is used/defined.
Hi @a-frantz, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you reBLESS the tests and Arena? Or did the latest round of tweaks not result in any changes?
I've updated the implementation with the suggested improvements:
This approach avoids hardcoding specific types and should be more maintainable going forward. |
wdl-lint/RULES.md
Outdated
@@ -16,6 +16,7 @@ be out of sync with released packages. | |||
| `DeprecatedObject` | Deprecated | Ensures that the deprecated `Object` construct is not used. | | |||
| `DeprecatedPlaceholderOption` | Deprecated | Ensures that the deprecated placeholder options construct is not used. | | |||
| `DescriptionMissing` | Completeness | Ensures that each meta section has a description key. | | |||
| `DisallowedDeclarationName` | Naming | Ensures that declaration names do not have type prefixes or suffixes. | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| `DisallowedDeclarationName` | Naming | Ensures that declaration names do not have type prefixes or suffixes. | | |
| `DisallowedDeclarationName` | Naming | Ensures that declaration names do not have type suffixes. | |
verbose and often redundant. For example, use 'counter' instead of 'counterInt' or \ | ||
'is_active' instead of 'isActiveBoolean'." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
verbose and often redundant. For example, use 'counter' instead of 'counterInt' or \ | |
'is_active' instead of 'isActiveBoolean'." | |
verbose and often redundant. For example, use 'counter' instead of 'counter_int' or \ | |
'is_active' instead of 'is_active_boolean'." |
} | ||
} | ||
|
||
// Get declaration name after type checking (moving closer to usage) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Get declaration name after type checking (moving closer to usage) |
let name = decl.name(); | ||
let name_str = name.as_str(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let name = decl.name(); | |
let name_str = name.as_str(); | |
let name = decl.name().as_str(); |
let name_lower = name_str.to_lowercase(); | ||
if name_lower.ends_with(&type_lower) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let name_lower = name_str.to_lowercase(); | |
if name_lower.ends_with(&type_lower) { | |
if name.to_lowercase().ends_with(&type_lower) { |
.collect() | ||
} | ||
|
||
#[cfg(test)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The tests you've written here are essentially the same as the tests checked by source.wdl
and source.errors
, so I think it's ok to just delete all these.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you except
DisallowedDeclarationName
from this source.wdl
to prevent these errors?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please fix all of these
warning[DisallowedDeclarationName]: declaration identifier 'int' ends with type name 'Int' | ||
┌─ tests/lints/disallowed-input-name/source.wdl:24:13 | ||
│ | ||
24 │ Int int = 1 # This is OK |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we just delete this line from source.wdl
to prevent this diagnostic. It's not a good example anymore
@a-frantz All done, please review it once and let me know if any further improvement is needed. |
@Gyan-max please fix everything reported by CI. But this is really close! Nice work |
On it! |
@a-frantz All tests are now passing with both cargo test and cargo clippy, and I've blessed the test baselines using BLESS=1. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mostly nits about unhelpful comments. We like to avoid comments that are describing something "obvious", although that is kind of subjective 🤷
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can except
NonmatchingOutput
and InputSorting
, but please correct the rest of the diagnostics reported here that aren't related to the new lint.
SyntaxKind::InputSectionNode, | ||
SyntaxKind::OutputSectionNode, | ||
SyntaxKind::BoundDeclNode, | ||
SyntaxKind::UnboundDeclNode, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
task and workflow definitions still need to be added here
// Get the declaration name | ||
let binding = decl.name(); | ||
let name = binding.text(); | ||
|
||
// Get the declaration type | ||
let ty = decl.ty(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Get the declaration name | |
let binding = decl.name(); | |
let name = binding.text(); | |
// Get the declaration type | |
let ty = decl.ty(); | |
let binding = decl.name(); | |
let name = binding.text(); | |
let ty = decl.ty(); |
// Add the primitive type name | ||
type_names.insert(primitive_type.to_string()); | ||
// Also check for "Bool" | ||
type_names.insert("Bool".to_string()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Add the primitive type name | |
type_names.insert(primitive_type.to_string()); | |
// Also check for "Bool" | |
type_names.insert("Bool".to_string()); | |
type_names.insert(primitive_type.to_string()); | |
type_names.insert("Bool".to_string()); |
} | ||
} | ||
|
||
// Get the element for diagnostic reporting |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Get the element for diagnostic reporting |
Decl::Unbound(d) => SyntaxElement::from(d.inner().clone()), | ||
}; | ||
|
||
// Check if the declaration name ends with one of the type names |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Check if the declaration name ends with one of the type names |
// Check if the short type name appears as the last word | ||
if let Some(last_word) = words.last() { | ||
if last_word.to_lowercase() == type_lower { | ||
let diagnostic = decl_identifier_with_type(decl.name().span(), name, type_name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let diagnostic = decl_identifier_with_type(decl.name().span(), name, type_name); | |
let diagnostic = decl_identifier_with_type(binding.span(), name, type_name); |
// Special handling for short type names (3 characters or less) | ||
// These require word-based checks to avoid false positives | ||
if type_lower.len() <= 3 { | ||
// Split the identifier into words |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// Split the identifier into words |
@a-frantz I addressed all your feedbacks sorry for unnecessary bother and thankyou for your guidance. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we maybe want to leave File
and String
as ignored, but why don't you bless Arena with those enabled and I'll review what comes up, then we can decide what to do with those two types.
#[derive(Debug, Default)] | ||
pub struct DisallowedDeclarationNameRule { | ||
/// Tracks whether we're currently within an input or output declaration section | ||
in_declaration_section: bool, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the point of this? It doesn't look like your using it, and I don't think we would care for this rule. Declarations everywhere (inputs, outputs, private decls) should all be handled the same.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added this because while running the tests it was showing an error.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you share the error? I'm not following
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just give me a minute, I'm running the tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok I think everything ending in string
and file
can be ignored. Please update the logic to allow those two type suffixes and then rebless everything
This pull request adds a new rule to
wdl-lint
.DisallowedDeclarationNameRule
This rule checks for declaration names that contain their type (like
File fileInput
) which is considered poor style as it adds unnecessary verbosity and creates redundancy since the type is already declared. The rule identifies declarations likeFile fileInput
,Int my_int
, andArray[String] stringArray
as problematic.Before submitting this PR, please make sure:
CHANGELOG.md
.Rule specific checks:
RULES.md
.rules()
function inwdl-lint/src/lib.rs
.wdl-lint/tests/lints
that covers everypossible diagnostic emitted for the rule within the file where the rule
is implemented.
Visitor
callback, you have alsooverridden that callback method for the special
Validator
(
wdl-ast/src/validation.rs
) andLintVisitor
(
wdl-lint/src/visitor.rs
) visitors.gauntlet --refresh
to ensure that there are nounintended changes to the baseline configuration file (
Gauntlet.toml
).gauntlet --refresh --arena
to ensure that all of therules added/removed are now reflected in the baseline configuration file
(
Arena.toml
).Fixes #215