mvdan / sh

A shell parser, formatter, and interpreter with bash support; includes shfmt
https://pkg.go.dev/mvdan.cc/sh/v3
BSD 3-Clause "New" or "Revised" License
6.97k stars 332 forks source link

Add flag to enforce ${var} #1029

Closed AlexSkrypnyk closed 10 months ago

AlexSkrypnyk commented 10 months ago

Can we please have an option to force ${var} everywhere. This would be very useful for those of us who wants their scripts to be consistent.

p.s. Let's not turn this issue into a holy war about whether it is a right choice to have every variable to be wrapped in ${} - let people decide this.

thank you

AlexSkrypnyk commented 10 months ago

I ended up coming up with this https://github.com/AlexSkrypnyk/shell-var-lint until this issue is resolved

mvdan commented 10 months ago

Enforcing it for everyone would be far too aggressive; there's nothing wrong with $var. Remember that shfmt is a formatter, so it needs to lean towards being conservative.

It's perfectly fine for others to build a linter or more aggressive "consistency enforcer" tool on top of the same Go packages in this Go module. I personally don't have the time and resources for that.

mvdan commented 10 months ago

I slipped up on the reply - you asked for an option. We want to keep the number of formatting options to a minimum, to avoid something like man indent with its dozens of knobs. So the bar for them is pretty high - we only add an option when a large number of users would benefit, or when it helps satisfy a well known style guide like Google's.