Skip to content

Commit

Permalink
feat: refine example config for shell scripts
Browse files Browse the repository at this point in the history
Signed-off-by: Brian McGee <[email protected]>
  • Loading branch information
brianmcgee committed Aug 21, 2024
1 parent a581352 commit d4c115e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 29 deletions.
33 changes: 17 additions & 16 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,22 +107,23 @@ func TestReadConfigFile(t *testing.T) {
as.Equal([]string{"*.rs"}, rust.Includes)
as.Nil(rust.Excludes)

// shell
shell, ok := cfg.Formatters["shell"]
as.True(ok, "shell formatter not found")
as.Equal("/bin/sh", shell.Command)
as.Equal([]string{
"-euc",
`# First lint all the scripts
shellcheck "$@"
# Then format them
shfmt -i 2 -s -w "$@"
`,
"--",
}, shell.Options)
as.Equal([]string{"*.sh"}, shell.Includes)
as.Nil(shell.Excludes)
// shellcheck
shellcheck, ok := cfg.Formatters["shellcheck"]
as.True(ok, "shellcheck formatter not found")
as.Equal("shellcheck", shellcheck.Command)
as.Equal(1, shellcheck.Priority)
as.Nil(shellcheck.Options)
as.Equal([]string{"*.sh"}, shellcheck.Includes)
as.Nil(shellcheck.Excludes)

//shfmt
shfmt, ok := cfg.Formatters["shfmt"]
as.True(ok, "shfmt formatter not found")
as.Equal("shfmt", shfmt.Command)
as.Equal(2, shfmt.Priority)
as.Equal(shfmt.Options, []string{"-i", "2", "-s", "-w"})
as.Equal([]string{"*.sh"}, shfmt.Includes)
as.Nil(shfmt.Excludes)

// terraform
terraform, ok := cfg.Formatters["terraform"]
Expand Down
22 changes: 9 additions & 13 deletions test/examples/treefmt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,20 +69,16 @@ command = "rustfmt"
options = ["--edition", "2018"]
includes = ["*.rs"]

[formatter.shell]
command = "/bin/sh"
options = [
"-euc",
"""
# First lint all the scripts
shellcheck "$@"
# Then format them
shfmt -i 2 -s -w "$@"
""",
"--", # bash swallows the second argument when using -c
]
[formatter.shellcheck]
command = "shellcheck"
includes = ["*.sh"]
priority = 1

[formatter.shfmt]
command = "shfmt"
options = ["-i", "2", "-s", "-w"]
includes = ["*.sh"]
priority = 2

[formatter.terraform]
# Careful, only terraform 1.3.0 or later accept a list of files.
Expand Down

0 comments on commit d4c115e

Please sign in to comment.