Skip to content

Commit

Permalink
fileutil: Omit zsh extensions and shebangs
Browse files Browse the repository at this point in the history
To prevent `shfmt` from discovering `zsh` files which aren't currently
supported for formatting.

This fixes mvdan#535 and the following test:

    > cmpenv stdout find.golden
     diff stdout find.golden
     --- stdout
     +++ find.golden
     @@ -16,6 +16,4 @@
      modify/shebang-space
      modify/shebang-tabs
      modify/shebang-usr-sh
     -skip/ext.zsh
     -skip/shebang-zsh
      symlink/subdir/ext-shebang.sh

     FAIL: testdata/script/walk.txtar:10: stdout and find.golden differ

It could be considered a breaking change to `shfmt` and `fileutil`.

There's some discussion in that issue about whether it's beneficial to
match `zsh` files because they can _sometimes_ be formatted if they
don't contain any zsh-specific syntax, but without any way to explicitly
exclude them from discovery it's more of a hindrance than help.
  • Loading branch information
dcarley committed Oct 9, 2024
1 parent 5dc448b commit 47f716b
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions fileutil/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (
)

var (
shebangRe = regexp.MustCompile(`^#!\s?/(usr/)?bin/(env\s+)?(sh|bash|mksh|bats|zsh)(\s|$)`)
extRe = regexp.MustCompile(`\.(sh|bash|mksh|bats|zsh)$`)
shebangRe = regexp.MustCompile(`^#!\s?/(usr/)?bin/(env\s+)?(sh|bash|mksh|bats)(\s|$)`)
extRe = regexp.MustCompile(`\.(sh|bash|mksh|bats)$`)
)

// TODO: consider removing HasShebang in favor of Shebang in v4
Expand Down

0 comments on commit 47f716b

Please sign in to comment.