Skip to content

[Feature request][Bash] Add rules to provide tips on adding local, or readonly status to variables #2987

Open
@LLyaudet

Description

@LLyaudet

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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions