Live data from Hacker News

Ask HN: Let's build Checkstyle for Bash?

news.ycombinator.com

1–10 of 71 posts

Ask HN: Let's build Checkstyle for Bash?

#1
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-...

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

- cspell: https://github.com/streetsidesoftware/cspell/tree/main/packa...

- 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.p...

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-stati...

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

Re: Ask HN: Let's build Checkstyle for Bash?

#2
Out of pure curiosity, in what context do you write sufficient amounts of Bash scripts that style checking is a worry that needs your attention? While I also write small one-offs or bootstrap scripts here and there, in most cases it's my experience that developers opt for other languages for anything beyond small snippets.

Re: Ask HN: Let's build Checkstyle for Bash?

#3
post #2

Out of pure curiosity, in what context do you write sufficient amounts of Bash scripts that style checking is a worry that needs your attention? While I also write small one-offs or bootstrap scripts here and there, in most cases it's my experience that developers opt for other languages for anything beyond small snippets.

Largely same sentiment. Pure POSIX shell scripts for embedded systems, sure, but I'm not sure if there is a niche that requires Bash scripting. Not discouraging these efforts of course but I'm not sure that it'll be worth it.

Re: Ask HN: Let's build Checkstyle for Bash?

#4
post #2

Out of pure curiosity, in what context do you write sufficient amounts of Bash scripts that style checking is a worry that needs your attention? While I also write small one-offs or bootstrap scripts here and there, in most cases it's my experience that developers opt for other languages for anything beyond small snippets.

Largely same sentiment. Pure POSIX shell scripts for embedded systems, sure, but I'm not sure if there is a niche that requires Bash scripting. Not discouraging these efforts of course but I'm not sure that it'll be worth it.

The niche is installer scripts. Because there is one certainty: Bash is available everywhere.

Re: Ask HN: Let's build Checkstyle for Bash?

#5
I think we should really be working to deprecate large bash scripts. If you write enough to care about code quality you might want to just use Python.

I'd say look at things like Oil(Is that project ever going to be the next big thing like it claims?).... but writing large scripts in ANY shell doesn't seem like the best plan.

What about an Ansible linter? Do those exist? I'm starting to suspect Ansible might be a better choice for a lot of what people do with bash, even if you are running om a desktop.

Re: Ask HN: Let's build Checkstyle for Bash?

#6
post #2

Out of pure curiosity, in what context do you write sufficient amounts of Bash scripts that style checking is a worry that needs your attention? While I also write small one-offs or bootstrap scripts here and there, in most cases it's my experience that developers opt for other languages for anything beyond small snippets.

What do you use the; if you want:

- Self contained in one file

- Easily edited with vi/nano (i.e. through a console ssh session)

- Readily available on most Linux base installations

- No crazy runtime installation requirements

Edit: formatting)

Re: Ask HN: Let's build Checkstyle for Bash?

#7
post #4

Earlier quoted context omitted.

Largely same sentiment. Pure POSIX shell scripts for embedded systems, sure, but I'm not sure if there is a niche that requires Bash scripting. Not discouraging these efforts of course but I'm not sure that it'll be worth it.

The niche is installer scripts. Because there is one certainty: Bash is available everywhere.

> Bash is available everywhere

POSIX mistake number 1: Bash isn't available everywhere, even when restricted to Linux. Even Debian avoids bash for a good reason (Bash is slower than most POSIX shell implementations), although it's installed by default for convenience.

Re: Ask HN: Let's build Checkstyle for Bash?

#8

I think we should really be working to deprecate large bash scripts. If you write enough to care about code quality you might want to just use Python. I'd say look at things like Oil(Is that project ever going to be the next big thing like it claims?).... but writing large scripts in ANY shell doesn't seem like the best plan. What about an Ansible linter? Do those exist? I'm starting to suspect Ansible might be a bet…

Shell scripts are nicer than Python, though. There was a brief moment in time where Python nearly rivaled shell scripts in convenience and straightforwardness, but November of 2008 was many years ago, now.

We should probably deprecate Bash, though. It doesn't offer enough over the standard for it to be worth it.

Re: Ask HN: Let's build Checkstyle for Bash?

#10
post #8

I think we should really be working to deprecate large bash scripts. If you write enough to care about code quality you might want to just use Python. I'd say look at things like Oil(Is that project ever going to be the next big thing like it claims?).... but writing large scripts in ANY shell doesn't seem like the best plan. What about an Ansible linter? Do those exist? I'm starting to suspect Ansible might be a bet…

Shell scripts are nicer than Python, though. There was a brief moment in time where Python nearly rivaled shell scripts in convenience and straightforwardness, but November of 2008 was many years ago, now. We should probably deprecate Bash, though. It doesn't offer enough over the standard for it to be worth it.

> We should probably deprecate Bash, though. It doesn't offer enough over the standard for it to be worth it.

Arrays make a world of a difference. Deprecate sh, keep bash.

Post reply on HN