Repository navigation
Description
Hi, thanks for supporting this tool.
I'm experiencing a surprising behavior when adding the --apply-ignore option and invoking shfmt to format scripts with a file name that starts with a dot (.).
Example:
shfmt --apply-ignore --diff .script.shshfmt will ignore .script.sh.
I think this happens in the CouldBeScript2 function:
Lines 67 to 84 in 2315483
| // CouldBeScript2 reports how likely a directory entry is to be a shell script. | |
| // It discards directories and other non-regular files like symbolic links, | |
| // filenames beginning with '.', and files with non-shell extensions. | |
| func CouldBeScript2(entry fs.DirEntry) ScriptConfidence { | |
| name := entry.Name() | |
| switch { | |
| case name[0] == '.': | |
| return ConfNotScript // '.' prefix (hidden file) | |
| case !entry.Type().IsRegular(): | |
| return ConfNotScript // dir, symlink, named pipes, etc | |
| case extRe.MatchString(name): | |
| return ConfIsScript // shell extension | |
| case strings.IndexByte(name, '.') > 0: | |
| return ConfNotScript // non-shell extension | |
| default: | |
| return ConfIfShebang // no extension; read and look for a shebang | |
| } | |
| } |
specifically with the lines:
Lines 73 to 74 in 2315483
| case name[0] == '.': | |
| return ConfNotScript // '.' prefix (hidden file) |
I don't have the full context that led to this implementation, but it makes it impossible to check the formatting of Bash and ZSH dotfiles, for example. Also, I didn't find any mention to it in the documentation, that only refers to EditorConfig files being considered when adding the --apply-ignore option:
Lines 47 to 52 in 2315483
| *--apply-ignore* | |
| Always apply EditorConfig ignore rules. | |
| When formatting files directly, ignore rules are skipped without this flag. | |
| Should be useful to any tools or editors which format stdin or a single file. | |
| When printing results to stdout, an ignored file results in no output at all. |
Would it be possible to make ignoring dotfiles configurable?
Thanks!
Activity
carhartl commentedon Apr 1, 2026
Possibly the files recently having been added here: 33b521e (thanks for that ❤️) would also need to yield
ConfIsScript🤔mvdan commentedon Apr 1, 2026
Thanks for reporting; this is an oversight in the logic. I had split it into two at some point in the past, but this led to splitting the logic for
--apply-ignore, and I then made the logic slightly different in the two branches.I'm joining the logic again. This leads to much more inline code, but it's less duplication and chances for bugs like this one.
ferrarimarco commentedon Apr 1, 2026
Thanks!
cmd/shfmt: --apply-ignore should not skip explicit args based on exte…
fix(deps): update module mvdan.cc/sh/v3 to v3.13.1 (#397)
chore(deps): update module mvdan.cc/sh/v3/cmd/shfmt to v3.13.1 (hetzn…
feat(builtins): format zsh startup files and zsh-shebang scripts with…