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
7.16k stars 338 forks source link

Surrounding whitespace in variable assignment #765

Closed allan2 closed 2 years ago

allan2 commented 2 years ago

This is a feature request to format surrounding whitespace in variable assignment.

Example:

Format

a = 5

as

a=5
mvdan commented 2 years ago

I don't think we can do that; those are different and valid programs. For instance:

$ a() { echo "hello!" "$@"; }
$ a = 5
hello! = 5
$ echo $a

$ a=5
$ echo $a
5

shfmt is a code formatter, so it can't do any automated changes that will change the behavior of programs, because those could easily break user's programs.

mvdan commented 2 years ago

Closing as per the above.