webinstall / webi-installers

Primary and community-submitted packages for webinstall.dev
https://webinstall.dev
Mozilla Public License 2.0
1.99k stars 214 forks source link

[Cheat sheet] Update shellcheck #335

Open coolaj86 opened 3 years ago

coolaj86 commented 3 years ago

I'm gonna add the error codes that I disable the most often to the cheat sheet:

SC1004 This backslash+linefeed is literal. Break outside single quotes if you just want to break the line.
# for source .env, etc
SC1091 Not following: (error message here)
SC2001 See if you can use ${variable//search/replace} instead.
SC2016 Expressions don't expand in single quotes, use double quotes for that.
SC2029 Note that, unescaped, this expands on the client side.
SC2034 foo appears unused. Verify it or export it.
SC2072 Decimals are not supported. Either use integers only, or use bc or awk to compare.
SC2086 Double quote to prevent globbing and word splitting.
SC2087 Quote 'EOF' to make here document expansions happen on the server side rather than on the client.
SC2088 Tilde does not expand in quotes. Use $HOME.
SC2129 Consider using { cmd1; cmd2; } >> file instead of individual redirects.
SC2155 Declare and assign separately to avoid masking return values.
shellcheck disable=SC2207,SC2053,SC1083,SC1091,SC2129,SC2155
coolaj86 commented 1 year ago

This is partially negated by #656

y0rune commented 8 months ago

Would you like to create a cheatsheet with all using SC disable at files? If yes I created a one line for that, using a documentation about ShellCheck:

yorune@Hana ~/git/webi-installers main $ shellcheck_gist=$(curl --silent https://gist.githubusercontent.com/nicerobot/53cee11ee0abbdc997661e65b348f375/raw/d5a97b3b18ead38f323593532050f0711084acf1/_shellcheck.md); for i in $(grep --color=no -hroE 'SC[0-9]+' | sort -u | grep SC); do echo -e "$i $(echo $shellcheck_gist | grep $i | sed 's/\[SC.*) //g' )"; done
SC1003 - Want to escape a single quote? echo 'This is how it'\''s done'.
SC1004 - This backslash+linefeed is literal. Break outside single quotes if you just want to break the line.
SC1090 - Can't follow non-constant source. Use a directive to specify location.
SC2005 - Useless `echo`? Instead of `echo $(cmd)`, just use `cmd`
SC2010 - Don't use ls | grep. Use a glob or a for loop with a condition to allow non-alphanumeric filenames.
SC2016 - Expressions don't expand in single quotes, use double quotes for that.
SC2030 - Modification of var is local (to subshell caused by pipeline).
SC2034 - foo appears unused. Verify it or export it.
SC2046 - Quote this to prevent word splitting
SC2059 - Don't use variables in the printf format string. Use printf "..%s.." "$foo".
SC2086 - Double quote to prevent globbing and word splitting.
SC2088 - Tilde does not expand in quotes. Use $HOME.
SC2154 - var is referenced but not assigned.