dspinellis / git-issue

Git-based decentralized issue management

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Fix ShellCheck issues

CyberShadow opened this issue · comments

ShellCheck is a shell script linter, and is good at identifying potential problems in shell scripts. Currently, it identifies 133 notes and 29 warnings in git-issue.sh.

Some of these seem to indicate potential problems:

  • Use of unquoted string expansion and command substitution changes the effect of the commands when the substitution result contains whitespace or globbing characters. An example of this occurs as part of the problem fixed by #47, which manifested (for the particular part of the test suite executing said code) as only a "line 755: [: too many arguments" message in the log.

  • Use of shell features not present in the POSIX shell, such as local variables.

  • Use of obsolete POSIX commands, such as fgrep.

It would be nice to fix applicable issues and add ShellCheck exceptions elsewhere. I've had success with running ShellCheck as a CI step as well, so that pull requests are automatically verified.

Additionally, enabling some shell options which improve correctness would be nice:

  • set -e will ensure the script does not continue whenever a command fails. External commands may fail due to an arbitrary number of reasons, incl. unpredictable ones such as I/O failure or exhaustion of system resources; continuing after such a failure would be incorrect.

  • set -u will guard against using unset variables, which is additional defense against typos and logic errors.

  • set -o pipefail is a Bash feature which causes the exit status of a pipeline to be non-zero if any of the commands failed, which helps to correctly stop execution should any part of a pipeline fail. (Mentioning this as the script is currently not strictly POSIX anyway.)

These are all good points. I'd like to see this gradually implemented. I suggest we strive for wide shell compatibility, and avoid adding bash-specific extensions.