Add optional check for whether a variable can be readonly#3115
Add optional check for whether a variable can be readonly#3115Flu wants to merge 4 commits intokoalaman:masterfrom
readonly#3115Conversation
|
This a neat check, but unfortunately ShellCheck's poor DFA makes it a lot trickier than it ought to be:
ShellCheck does have a significantly more correct DFA algorithm that does track control flow properly (ShellCheck.CFG), but it is correspondingly more complex and would require a whole lot more compiler type graph operations in order to determine that the variable is only set once. |
So does this mean that using ShellCheck.CFG would make this kind of check possible, but it would be complicated to take into account all of the possible edge cases? Cause if so, I could still try. I don't know if it's worth the effort for such a small and optional check, but I could give it a shot if it's technically possible |
50074dc to
eac8eff
Compare
Adds an optional check for triggering a SC2331 for variables that are declared (and/or initialized) but never assigned to again. If a variable is found that matches, a note is given to maybe declare it as
readonly.Also implemented tests for it, as well as for the option itself in Checker.hs
In accordance to #2987, but it's not the full issue.
Let me know if you want to implement the full issue suggestion, as part of the same optional check, another optional check, etc.