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.35k stars 348 forks source link

`--keep-padding` unindents, creating mismatched indentation #1103

Closed jonashaag closed 1 month ago

jonashaag commented 1 month ago
#!/bin/bash

case $res in
  x)
    if true; then
      while true; do
        case $res in
          x)
            break
            ;;
          *) ;;
        esac
      done
    fi
    ;;
esac
shfmt -s -i 2 --keep-padding tmp
#!/bin/bash

case $res in
  x)
    if true; then
      while true; do
        case $res in
          x)
            break
            ;;
          *) ;;
      esac                # <====
    done                  # <====
  fi                      # <====
    ;;
esac
mvdan commented 1 month ago

Thanks for reporting this; the option is very broken and ultimately a bad idea, so it's no longer maintained and will be removed in the next major version. I'm not keeping issues about it open because I don't plan on tackling any of them. I suggest you avoid the option entirely. https://github.com/mvdan/sh/issues/658