bioconda-utils icon indicating copy to clipboard operation
bioconda-utils copied to clipboard

[Feature request] Add Lint for shellcheck

Open zeehio opened this issue 3 years ago • 0 comments

Problem

Many recipes have shell scripts (e.g. build.sh, post-link.sh, pre-unlink.sh). Some of those scripts have portability issues, such as:

  • do not have a shebang. example
  • do not quote directories example (conda already warns about avoiding spaces, but anyway better safe than sorry)
  • Have bashisms even if they are declared as /bin/sh scripts example
  • ...

This makes those scripts fragile, or lead to unwanted effects.

For instance, if a user installs a package on a conda environment with spaces, like /path/with spaces a post installation script like:

#!/bin/sh
DIR="/path/with spaces"
# whatever work done here
rm -rf $DIR

will remove "/path/with" and "spaces" instead of "/path/with spaces"

More dangerously could be a path with a trailing space:

#!/bin/sh

#DIR="/path/with-a-trailing-space /"
#rm -rf $DIR

Which I have commented out because you do not want to remove / by accident.

Solution: shellcheck

shellcheck is a tool that checks shell scripts and looks for potential and common errors. See more bad-code examples here: https://github.com/koalaman/shellcheck/blob/master/README.md#gallery-of-bad-code

It is widely available (as a debian package, installable through brew on osx and on conda-forge).

Linting bioconda scripts with shellcheck could prevent many of those issues.

shellcheck recipes/bioconductor-dapardata/*.sh

imatge

It would be great to try to have an integrated linter in bioconda to detect those issues and suggest corrections.

zeehio avatar Jan 05 '21 11:01 zeehio