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

shfmt still complains that " &> redirects are a bash/mksh feature" although it parses the script as bash #1102

Closed coiby closed 1 month ago

coiby commented 1 month ago

Problem

shfmt makes the following complaint,

&> redirects are a bash/mksh feature (parsed as bash via -ln=auto)

which doesn't sound reasonable to me because the script is already parsed as bash

How to reproduce it

cat << 'EOF' > test.sh
#!/bin/bash
echo test 1 &>2
EOF

cat << 'EOF' > .editorconfig
root = true

[*]
shell_variant = posix
EOF

if ! shfmt -d test.sh; then
    echo "test failed"
fi
mvdan commented 1 month ago

Thanks for reporting this. As far as I can tell, the behavior in terms of parsing is correct - shell_variant = posix is applied from EditorConfig like a -ln=posix flag, so you are actually parsing in POSIX mode. It's the error message which is wrong and very confusing. I've fixed that now.

coiby commented 1 month ago

Thanks for coming up with a fix quickly!

I have one question. In the reproducer, the shebang is !/bin/bash. So do you imply EditConfig will overwrite shebang?