Closed quad closed 1 year ago
I don't think this should be part of "simplify" - that feature is for changes which should always be reasonable to make. I only kept it behind a flag because, technically, they are not formatting changes. This change in particular could be a bad idea in some cases. In some, like ${foo}bar
, it would change the program. In others, it could make code less consistent - I personally prefer using the longer form everywhere.
As for the minification rules, you're right that currently it's all-or-nothing. What are you thinking in terms of API? At least we'd have to somehow number or identify all the types of changes. Then we'd need to allow selecting those via a Go API like https://github.com/mvdan/sh/blob/279b806d8f2417af933a40a726ad8299395d9183/syntax/printer.go#L78, and via shfmt -mn
.
I'm going to close this for now, per my comment above. Always happy to entertain adding extra "minify" rules, but there's also no reason why these need to exist inside shfmt
. The parsing and printing logic is a library, so other tools can easily be spun up.
It would be nice to minify the code to simplify parameter expressions even when simplifying.
Perhaps what I really want is a way to turn on/off individual minifiation rules.
Would you be open to a PR implementing either?