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.1k stars 336 forks source link

cmd/shfmt: support editorconfig properties for `-s` and `-mn` #819

Open jfly opened 2 years ago

jfly commented 2 years ago

Right now I have to keep my text editor's autoformatting code in sync with my project's Makefile to invoke shfmt. It would be nice to keep that version controlled on my project's .editorconfig file. Is that possible? If not, is it something you'd be open to a PR adding support for?

Thanks!

mvdan commented 2 years ago

Hmm. If you look at shfmt -h, you will notice that flags like -s and -mn aren't grouped with the parser or printer options, because they are neither of those - instead, they are extra steps which are run between the parse and the print stages.

I hadn't really thought about whether these two should be supported in editorconfig files. I guess if one squints a bit, they could be considered printer flags, as they alter how a shell script is printed out.

I can't really think of a reason why we shouldn't add support for them, so let's do it. I lean towards doing both rather than just -s, just for the sake of consistency.

sellout commented 1 year ago

While they’re separate flags, there’s really a progression of none → simplify → minify, so I would recommend a single editorconfig option accepting those three values as an enumeration. Not sure what a good name for it is, though. Perhaps something like rewrite_style?

mvdan commented 1 year ago

You're right that it doesn't make sense to use minify without simplify, and I don't even think it is currently possible. But I do want the editorconfig knobs to mirror the flags one-to-one, as otherwise it's a bit confusing. If the two flags being separate is weird, we should unify them, probably for v4.

ColemanTom commented 3 months ago

I have raised a MR for this, keeping the names consistent with the command line options. If minifiy is enabled, simplify is automatically enabled too.