Replies: 3 comments 8 replies
-
Well - you mention two separate issues: ShellcheckIn regards to shellcheck - you should not shellcheck the partial snippets, but just the final script. So if you have a shellcheck violation, it is either because you are checking a partial script or your own code is indeed not compliant. More info in Bashly Homepage > Testing Your Script. Uppercase globalsIn regards to upper case globals - this is unlikely to happen. Bashly is opinionated. It is my view that CAPITAL_VARS represent variables that came from the outside (environment). Although I agree that in some circles the standard could be CAPS == Global, I am not sharing that view and do not want to have capital letter variables plastered all over my script. As always, I am happy to be convinced otherwise and I might change my mind. |
Beta Was this translation helpful? Give feedback.
-
Here's a (hacky) trick I used to solve this with no need to change anything in bashly code:
# shellcheck disable=2034
declare -gn ARGS=args DEPS=deps Now Same thing for |
Beta Was this translation helpful? Give feedback.
-
Request
Declare all global variables using UPPERCASE (e.g.:
$ARGS
,$DEPS
).I understand that this can be an issue for backward compatibility (bashly users who are already referencing
$args
in their scripts). So an alternative solution would be to provide a flag likeupcase_global_variables
inbashly-settings.yml
.Motivation
Using UPCASE in global variable names is pretty common. But to be honest, the reason I'm opening this discussion because shellcheck complains when we refer a variable that is not (visibly) assigned.
Example: when I try to use
${args[something]}
shellcheck complains thatargs is referenced but not assigned
[SC2154].Using UPCASE in the variable name solves this issue. As explained in the SC2154 page
I can solve it in my end by using
# shellcheck disable=2154
right above the lines where I use references to$args
.Alternatively I could disable this shellcheck in the whole file or in the whole project, which is something I don't recommend, since this is an important thing to have enabled (to check that the variable is indeed assigned, and that the name is not misspelled).
Using shellcheck as a shell script linter is (hopefully) popular these days, then it would be neat to be able to use the power of bashly with no need to tweak shellcheck configs.
Beta Was this translation helpful? Give feedback.
All reactions