Shellcheck: Explain flag

Created on 18 Oct 2018  路  6Comments  路  Source: koalaman/shellcheck

Is there any interest in an --explain flag that would give an offline version of the wiki documentation? I dislike needing to have a browser open to get the longer descriptions.

Basically exactly what rustc --explain OPT does.

For new checks and feature suggestions

Here's a snippet or screenshot that shows the feature:

$ shellcheck --explain SC2148

Correct code:

#!/bin/sh
echo "$RANDOM"  # Unsupported in sh. Produces warning.

#!/bin/bash
echo "$RANDOM"  # Supported in bash. No warnings.

Rationale:

Different shells support different features. To give effective advice, ShellCheck needs to know which shell your script is going to run on. You will get a different numbers of warnings about different things depending on your target shell.

ShellCheck normally determines your target shell from the shebang (having e.g. #!/bin/sh as the first line). The shell can also be specified from the CLI with -s, e.g. shellcheck -s sh file.

If you don't specify shebang nor -s, ShellCheck gives this message and proceeds with some default (bash).

Note that this error can not be ignored with a directive. It is not a suggestion to improve your script, but a warning that ShellCheck lacks information it needs to be helpful.

Exceptions

None. Please either add a shebang or use -s.

Most helpful comment

One of the major purposes of the wiki is to serve as an errata, so I really don't want it hard-coded into the binary.

Just a couple of weeks ago ShellCheck started advertising the fact that it has a wiki (#920), so this information is already more discoverable than with an --explain flag. The Integration checklist also has wiki links as a point.

How about doing this as an add-on, like a fancier version of:

shellcheck-explain() { curl -Lqs "https://www.shellcheck.net/wiki/$1.md" | fold | less;  }

Or if the point is to work offline, how about converting the wiki pages to man pages for a shellcheck-man package that distros can easily update outside of regular shellcheck releases?

All 6 comments

You effectively want to ship the wiki with the code?

That's one way of putting it. I believe there's precedent, notably in the rust compiler and maybe also elm? But I feel that the practice of shipping man pages with a binary is also similar.

This might imply a shift in the way the wiki is maintained (into being more of an integral part of the project, living side by side with the code), that could be a good thing?

Nonetheless, those pages are helpful and it's annoying to have to switch from my editor to look them up or not have them available when offline.

A quick example of my use case would be similar to what I do here (except the explanation would be opened in a editor split rather than mpv)

Edit: To be clear, I'm open to implementing it myself, but before I do that, I'd like to know if it would be welcome.

I see. I guess it is like shipping man pages and having a web site of same, ala Perl for one example. I guess that鈥檚 @koalaman 鈥榮 call.

One of the major purposes of the wiki is to serve as an errata, so I really don't want it hard-coded into the binary.

Just a couple of weeks ago ShellCheck started advertising the fact that it has a wiki (#920), so this information is already more discoverable than with an --explain flag. The Integration checklist also has wiki links as a point.

How about doing this as an add-on, like a fancier version of:

shellcheck-explain() { curl -Lqs "https://www.shellcheck.net/wiki/$1.md" | fold | less;  }

Or if the point is to work offline, how about converting the wiki pages to man pages for a shellcheck-man package that distros can easily update outside of regular shellcheck releases?

I'll see what I can do about that. Would such a project be maintained in the same repo? Can a github project maintain multiple types of releases? Or should I create another repo?

Another similar issue is #1122

Was this page helpful?
0 / 5 - 0 ratings