Skip to content

[Feature request] Add Lint for shellcheck #691

@zeehio

Description

@zeehio

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions