-
-
Notifications
You must be signed in to change notification settings - Fork 348
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cmd/shfmt: change -ln default to "auto" #429
Comments
An alternative approach is to make |
I don't think you will ever find a project which mixes posix/bash scripts together. Libraries (which are included with
It should be possible to do without implementing TLDR: choice of a shell is a project wide decision and implementing this flag will bring more harm than good. |
I disagree that projects stick to one shell. At work we have repos that mix bash and posix. Bash for development scripts that are simpler to write with bashisms, and posix for scripts that need to run inside deployed containers which only include busybox.
In that case I think they should be forced to change the shebang to
They'll default to bash, which will parse pretty much any shell script out there; I'm not sure that this would be a problem in practice. I get your point about the inconsistency, but if they want explicit consistency, they can use shebangs or
I'm not convinced; see my example above about our work repos. How would we catch those? Using The only alternative for us to catch those errors is to manually implement this shell language detection logic ourselves, or to use a separate tool to "detect incorrect bashisms". Both seem like worse options to me. |
Another option is to add a new "lint" tool in this repo that would catch this error. But of course, practically noone would run this tool, and existing |
Actually
This actually makes a lot of sense, especially if you port some good checks from https://github.com/koalaman/shellcheck |
I am aware of shellcheck, but it implements a lot of checks, and I'm just too lazy to implement something as complex as that :) |
It just occurred to me that this has a huge overlap with #393. At the very least, I shouldn't add |
I've resurrected this idea in #622, by the way. |
This way, when one does
shfmt -l -w .
, files with#!/bin/sh
shebangs would be formatted as if-ln posix
had been specified. The tool already has to parse shebangs when detecting if extension-less files are actually shell scripts, so this wouldn't be extra overhead.The logic for
-ln=auto
is as follows:bash
The big advantage is that this will flag shell scripts using
#!/bin/sh
and bashisms at the same time, which is a bug. A*.sh
script without a shebang that also uses bashisms won't be caught, but I think doing that would be far too prone to false positives; calling such a script likebash foo.sh
is common, and not all that bad. The logic would ignore filename extensions altogether.On the flip side, the
-ln
flag will become a bit more complex. I think I can explain the new logic with an extra line or two in the usage text.Thoughts?
The text was updated successfully, but these errors were encountered: