Ask HN: Let’s build Checkstyle for Bash?

84

After working with Bash and Shellcheck for a few months, I noticed I could improve my code quality by making it compliant with the Shell Style Guide by Google [0]. While working on that, I thought some aspects of this Shell style guide can be verified automatically, granted some assumptions/opinions are formed. So I looked around for linting tools and autoformatters for Bash:

Shellcheck: https://github.com/koalaman/shellcheck

From Asynchronous Lint Engine (ALE): https://github.com/dense-analysis/ale/blob/master/supported-tools.md

– bashate: https://github.com/openstack/bashate

– cspell: https://github.com/streetsidesoftware/cspell/tree/main/packages/cspell

– Bash Language Server: https://github.com/bash-lsp/bash-language-server

– shell -n flag: https://www.gnu.org/software/bash/manual/bash.html#index-set

– sh(shfmt): https://github.com/mvdan/sh

– shdoc: https://github.com/reconquest/shdoc

From this stack post [1]:

– checkbashisms: http://man.he.net/man1/checkbashisms

– shlint: https://github.com/duggan/shlint (archived)

Prettier: https://marketplace.visualstudio.com/items?itemName=esbenp.prettier-vscode

Within all these linters and auto-formatters I did not find checks that enforce, for example, the Function Comments of the Shell Style Guide by Google:

All function comments should describe the intended API behaviour using:

    Description of the function.
    Globals: List of global variables used and modified.
    Arguments: Arguments taken.
    Outputs: Output to STDOUT or STDERR.
    Returns: Returned values other than the default exit status of the last command run.

Hence, I thought we could make a Bash linting tool that verifies compliance with the Shell Style Guide by Google. To do so, a brief start was made here [2]. It identifies/lists elements in that style guide that may be verified automatically. Since Bash has been around longer than me, I think there may be some people better suited for the development of this enhanced linter. Hence, I thought it might be wise, for impact and usability, to share this idea here.

What do you say, HN?

[0]: https://google.github.io/styleguide/shellguide.html

[1]: https://stackoverflow.com/questions/3668665/is-there-a-static-analysis-tool-like-lint-or-perlcritic-for-shell-scripts

[2]: https://github.com/TruCol/checkstyle-for-bash

Vanic
WRITTEN BY

Vanic

“Simplicity, patience, compassion.
These three are your greatest treasures.
Simple in actions and thoughts, you return to the source of being.
Patient with both friends and enemies,
you accord with the way things are.
Compassionate toward yourself,
you reconcile all beings in the world.”
― Lao Tzu, Tao Te Ching