Description
Hello :),
I may have used readonly or local keywords in some of my shell scripts in the past.
But at some point, I forgot about this keywords.
For new checks and feature suggestions
- https://www.shellcheck.net/ (i.e. the latest commit) currently gives no useful warnings about this
- I searched through https://github.com/koalaman/shellcheck/issues and didn't find anything related
See #1944
for the issue that recalled me of it.
I checked that no current rule (activated with --enable=all for example) yields suggestions to add such keywords in your code.
I have a very simple rule to propose:
If there is only one match of the regexp like "^\s*@my_variable_name@=.*$" adapted to the variable in the current file, propose to add readonly keyword. Another feature would be to define a project variant of this to check all lines of bash scripts in . for example instead of just the current file. Regarding local vs global variable in functions, it could make sense that each variable in a function is defined with local or declare or typeset or that a warning is issued by some rule (the case of exterior variables could be dealed with # shellcheck disable=SC1111(@my_variable_name@)
at beginning of function with function scope.
Best regards,
Laurent Lyaudet