Skip to content

Commit

Permalink
cmd/shfmt: Add support for minify and simplify via EditorConfig
Browse files Browse the repository at this point in the history
Closes #819.
  • Loading branch information
ColemanTom committed May 23, 2024
1 parent 23633a4 commit 0acaa23
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
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

0 comments on commit 0acaa23

Please sign in to comment.