Skip to content
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" #796

Merged
merged 1 commit into from
Jan 27, 2022
Merged

cmd/shfmt: change -ln default to "auto" #796

merged 1 commit into from
Jan 27, 2022

Conversation

mvdan
Copy link
Owner

@mvdan mvdan commented Jan 22, 2022

(see commit message)

Fixes #622.

The man page describes the logic in detail.
In short, the default is no longer just "assume bash",
as it will try to detect the language from the filename and shebang,
and only fall back to "bash" if those fail.

Users who specify a language themselves, either via -ln or editorconfig,
should see no change in behavior whatsoever.
Those relying on the default should generally see an improvement,
as they might no longer have issues with directories mixing languages.

One potential regression is cases like:

	$ cat foo.sh
	foo=(bar baz) # actually bash

That is, bash scripts which use "sh" extensions or shebangs.
"sh" stands for POSIX shell, so the new logic will parse them as such,
whereas the old logic would parse them as bash.
Still, that seems like an easy fix on the part of the user:
they can either change the extension or shebang to be clear,
or they can explicitly set up the option to "bash".

Note that the added "auto" logic applies to all kinds of inputs:
explicit files, directories to be walked, and standard input.

Fixes #622.
@mvdan
Copy link
Owner Author

mvdan commented Jan 27, 2022

Going to merge this for now. Reviews and testing are still very much welcome, even after this lands in master.

@mvdan mvdan merged commit a876f44 into master Jan 27, 2022
@mvdan mvdan deleted the lang-auto branch January 27, 2022 22:38
@kolyshkin
Copy link

Tested (better late than never I guess); filed #802

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

cmd/shfmt: change the language default from "bash" to "auto"
2 participants