You are not logged in.
I like to use shellcheck for my shell scripts. I'm wondering if it is good practice to use shellcheck suggestions on PKGBUILD scripts. I would think it is a good idea to prevent bugs, but I have never seen them used.
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')
Offline
PKGBUILDs are called with set -e, so the cd failing will abort. $srcdir is guaranteed to exist. A PKGBUILD is just a part of the script, so the unused variables really are used, you just don't have the whole thing.
Last edited by Scimmia (2020-02-23 16:55:36)
Offline
For all the reasons Scimmia just pointed out, I would generally consider that shellcheck is not especially useful for PKGBUILDs.
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
Managing AUR repos The Right Way -- aurpublish (now a standalone tool)
Offline
Thanks for the tips! I use Spacemacs usually and I only know how to apply exceptions within the comments.
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.
Offline
Does spacemacs provide a linter that runs shellcheck? If so, there may be a way to tune it depending on the filetype. vim and Syntastic is pretty nice as it is very configurable.
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.
Managing AUR repos The Right Way -- aurpublish (now a standalone tool)
Offline
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.
Offline
That literally just runs this script: https://github.com/vn971/rua/blob/maste … ck-wrapper
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.
Managing AUR repos The Right Way -- aurpublish (now a standalone tool)
Offline
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.
Offline