If you ignore the "unused" variables as you mentioned, using rua in the AUR is rather handy:
rua shellcheck path/to/my/PKGBUILD # run shellcheck on a PKGBUILD, discovering potential problems with the build instruction. Takes care of PKGBUILD-specific variables.
I'm happy with clean-chroot-manager right now but the shellcheck integration is nice. I would ultimately want the suggestions in my editor, so I'll look into adding the CLI options in Spacemacs.
]]>What a blunt-axe approach to problem solving... oh well, if it works, it works
You don't need an AUR helper for it though.
]]>rua shellcheck path/to/my/PKGBUILD # run shellcheck on a PKGBUILD, discovering potential problems with the build instruction. Takes care of PKGBUILD-specific variables.
You definitely don't want to add confusing code that isn't very readable just to work around an inefficiency in your linter, so if you are going to clutter up your PKGBUILD (despite that per definition all PKGBUILDs share the same quirks) at least let it be comments.
Shellcheck would be a more reliable tool if someone modified it to be aware of the specificities of this derived dialect of shell, and not complain about them. Then, perhaps, the warnings for undefined or unused variables could actually be used rather than ignored due to being always wrong.
]]>I still think there is some value in SC2154 for when the variable is misspelled. Probably using "${srcdir:?}" is a little confusing to someone reading the script.
]]>My .vimrc contains the following lines to make shellcheck less useless:
" PKGBUILD is a subclass of sh
let g:syntastic_filetype_map = { "PKGBUILD": "sh" }
" Syntastic shouldn't check for makepkg variables or erroring `cd`s.
if @% =~ 'PKGBUILD$' || &ft ==? 'PKGBUILD'
let b:syntastic_sh_shellcheck_post_args = "-e SC2034,SC2154,SC2164"
endif
For example, should I be applying SC2164 and SC2154 which makes my change directory lines look like this?
cd "${srcdir:?}" || exit
I was also wondering about the several "unused" variables at the top of PKGBUILDs. SC2034 complains about unused variables. Perhaps just disabling the shellcheck warning on these would be best.
# shellcheck disable=SC2034
pkgname=losslesscut
pkgver=2.6.2
pkgrel=2
pkgdesc="Crossplatform GUI tool for lossless trimming/cutting of video/audio files"
arch=('x86_64')
url="https://github.com/mifi/lossless-cut"
license=('MIT')
Or, can the "export" keyword be used in a PKGBUILD script like so?
pkgname=losslesscut
pkgver=2.6.2
export pkgdesc="Crossplatform GUI tool for lossless trimming/cutting of video/audio files"
export arch=('x86_64')
export url="https://github.com/mifi/lossless-cut"
export license=('MIT')