Repository navigation
SC2034 - trigger for unused variables set with variable expansion or only checked for existence (fixes #3607) - #3615
Open
slycordinator wants to merge 2 commits into
Open
slycordinator wants to merge 2 commits into
slycordinator wants to merge 2 commits into
Conversation
1) Change checkUnusedAssignments to be able to handle instances where a variable is set using ${var:-0}, ${var-0}, ${var:=0}, and/or ${var=0} and not treat the variable as used in those cases, unless further used elsewhere
1a) To do this, added isSelfDefault function, which returns true if the string is an assignment of one of the above.
2) added test cases
This partially fixes issue 3607
slycordinator
marked this pull request as draft
November 10, 2026 11:07
Contributor
Author
|
Changed to a draft as I believe I've found a way to fix the other part of the referenced issue, but don't have a way to test it from home. |
* in checkUnusedAssignments, add ability to exclude variables that are merely checked for whether they are set or unset as being used
like [[ -z ${var} ]], [[ -n ${var} ]] and the same using [ ] and test
* to do this, added isSetUnsetCheck helper function that returns True if the variable in question is being checked for having been set/unset inside [[ ]] or [ ] and if is checked by a call to test
* added tests
slycordinator
marked this pull request as ready for review
November 11, 2026 05:01
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fixes #3607