Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cmd/shfmt: Add support for minify and simplify via EditorConfig #1062

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions cmd/shfmt/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,10 @@ func propsOptions(lang syntax.LangVariant, props editorconfig.Section) {
syntax.KeepPadding(props.Get("keep_padding") == "true")(printer)
// TODO(v4): rename to func_next_line for consistency with flags
syntax.FunctionNextLine(props.Get("function_next_line") == "true")(printer)
minify_opt := minify.val || props.Get("minify") == "true"
syntax.Minify(minify_opt)(printer)
// Keep the original value if passed by CLI, or minify is enabled, or it is in the config file
simplify.val = simplify.val || minify_opt || props.Get("simplify") == "true"
}

func formatPath(path string, checkShebang bool) error {
Expand Down
14 changes: 14 additions & 0 deletions cmd/shfmt/testdata/script/editorconfig.txtar
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@ keep_padding = true
[function_next_line.sh]
function_next_line = true

[simplify.sh]
simplify = true

[minify.sh]
minify = true

-- otherknobs/shell_variant_bash.sh --
array=(elem)
-- otherknobs/shell_variant_mksh.sh --
Expand All @@ -183,6 +189,14 @@ foo()
{
echo foo
}
-- otherknobs/simplify.sh --
foo() {
((bar))
}
-- otherknobs/minify.sh --
foo(){
((bar))
}
-- ignored/.editorconfig --
root = true

Expand Down