Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a linter for fish like there is for bash with shellcheck?

Tags:

debugging

fish

For sh/bash/zsh there is https://github.com/koalaman/shellcheck however there won't be support for fish with it https://github.com/koalaman/shellcheck/issues/209 - is there any linters for fish?

like image 548
balupton Avatar asked Mar 07 '17 23:03

balupton


1 Answers

To my knowledge, there is not (and obviously this is impossible to prove).

And if someone were to create such a thing, there'd need to be consensus about what the "typical beginner's syntax issues" and "semantic problems that cause a shell to behave strangely and counter-intuitively" are.

Fish doesn't have many of POSIX sh's warts (as it was written as a reaction to them). Some examples from the shellcheck README:

echo $1                           # Unquoted variables

Fish's quoting behavior is quite different - in particular, there is no word splitting on variables, so unquoted variables usually do what you want.

v='--verbose="true"'; cmd $v      # Literal quotes in variables

This is presumably an (unsuccessful) attempt to defeat word splitting, which isn't necessary.

This example nicely illustrates the issue - there are multiple decades worth of sh scripts. The flaws and unintuitive behaviors are really well known. So well known in fact, that the common-but-incorrect workarounds are known as well. That's just not the case for fish.

(Obviously, other examples do apply to fish as well, especially the "Frequently misused commands" section.)


Some things in fish that I know new users often trip over:

  • Unquoted variables expand to one argument per element in the list (since every variable is one). That includes zero if the list is empty, which is an issue with test - e.g. test -n $var will return 0 because fish's test builtin is one of the few parts that are POSIX-compatible (since POSIX demands test with one argument returns 0). Double-quote if you always need one argument.

  • {} expands to nothing and {x} expands to "x", which means find -exec needs quoting, as do some git commit-ishes (HEAD@{4}). (edit: This has since been changed, {} expands to {} and {x} expands to {x} unless x has a comma or other expansion, so HEAD@{4} works)

like image 183
faho Avatar answered Oct 29 '22 02:10

faho