sh
sh copied to clipboard
cmd/shfmt: support editorconfig properties for `-s` and `-mn`
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!
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.
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?
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.