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

Space redirects `-sr` also seem to convert space indents to tabs #1069

Closed javydekoning closed 2 months ago

javydekoning commented 2 months ago

This causes conflicts with my editorconf (where I use 2 spaces for indents).

Running with -sr:

 function installdep() {
-  if [ ${PLAT} = "ubuntu" ]; then
-    apt-get -y update
-    # Satisfying even Ubuntu older versions.
-    apt-get -y install jq awscli ruby2.0 || apt-get -y install jq awscli ruby
-  elif [ ${PLAT} = "amz" ]; then
-    yum -y update
-    yum install -y aws-cli ruby jq
-  fi
+       if [ ${PLAT} = "ubuntu" ]; then
+               apt-get -y update
+               # Satisfying even Ubuntu older versions.
+               apt-get -y install jq awscli ruby2.0 || apt-get -y install jq awscli ruby
+       elif [ ${PLAT} = "amz" ]; then
+               yum -y update
+               yum install -y aws-cli ruby jq
+       fi
 }
mvdan commented 2 months ago

From man shfmt:

If any EditorConfig files are found, they will be used to apply formatting options. If any parser or printer flags are given to the tool, no EditorConfig files will be used. A default like -i=0 can be used for this purpose.

So your solution is to either add space_redirects = true to the EditorConfig file, or to repeat all of your EditorConfig formatting options as flags in the command line.

javydekoning commented 2 months ago

Yikes, that was easy. Thanks!

Added:

[*.sh]
space_redirects = true

To my editorconf and it's fixed