From 6cbec7ade388067467507f996c02707e2c2e6e4a Mon Sep 17 00:00:00 2001 From: Choko Date: Wed, 12 Jun 2024 11:55:27 +0900 Subject: [PATCH 1/2] Add shell formatting tasks / workspace settings --- README.md | 1 + go-build.code-workspace | 18 +++++++++++++++++- standard.go | 22 ++++++++++++++++++++++ versions.go | 2 +- 4 files changed, 41 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 79863ae..eb30c78 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,7 @@ format and lint tasks target the following languages: - Go - Markdown +- Shell-like, including Dockerfile (files supported by [mvdan-sh](https://github.com/mvdan/sh)) - YAML All supporting tasks are executed with `go run` - this means that all languages diff --git a/go-build.code-workspace b/go-build.code-workspace index e96fbdf..975accc 100644 --- a/go-build.code-workspace +++ b/go-build.code-workspace @@ -6,10 +6,22 @@ } ], "extensions": { - "recommendations": ["esbenp.prettier-vscode"] + "recommendations": ["esbenp.prettier-vscode", "foxundermoon.shell-format"] }, "settings": { "editor.tabSize": 2, + "[dockerfile]": { + "editor.formatOnSave": true, + "editor.defaultFormatter": "foxundermoon.shell-format" + }, + "[dotenv]": { + "editor.formatOnSave": true, + "editor.defaultFormatter": "foxundermoon.shell-format" + }, + "[ignore]": { + "editor.formatOnSave": true, + "editor.defaultFormatter": "foxundermoon.shell-format" + }, "[github-actions-workflow]": { "editor.formatOnSave": true, "editor.defaultFormatter": "esbenp.prettier-vscode" @@ -24,6 +36,10 @@ "editor.formatOnSave": true, "editor.defaultFormatter": "esbenp.prettier-vscode" }, + "[shellscript]": { + "editor.formatOnSave": true, + "editor.defaultFormatter": "foxundermoon.shell-format" + }, "[yaml]": { "editor.formatOnSave": true, "editor.defaultFormatter": "esbenp.prettier-vscode" diff --git a/standard.go b/standard.go index a0eff3e..9a0fa9f 100644 --- a/standard.go +++ b/standard.go @@ -79,6 +79,28 @@ func DefineTasks(opts ...Option) { })) } + if !conf.excluded("format-shell") { + RegisterFormatTask(goyek.Define(goyek.Task{ + Name: "format-shell", + Usage: "Formats shell-like code, including Dockerfile, ignore, dotenv.", + Parallel: true, + Action: func(a *goyek.A) { + cmd.Exec(a, fmt.Sprintf("go run github.com/wasilibs/go-prettier/cmd/prettier@%s --no-error-on-unmatched-pattern --write '**/*.sh' '**/*.bash' '**/Dockerfile' '**/*.dockerfile' '**/.*ignore' '**/.env*'", verGoPrettier)) + }, + })) + } + + if !conf.excluded("lint-shell") { + RegisterLintTask(goyek.Define(goyek.Task{ + Name: "lint-shell", + Usage: "Lints shell-like code, including Dockerfile, ignore, dotenv.", + Parallel: true, + Action: func(a *goyek.A) { + cmd.Exec(a, fmt.Sprintf("go run github.com/wasilibs/go-prettier/cmd/prettier@%s --no-error-on-unmatched-pattern --check '**/*.sh' '**/*.bash' '**/Dockerfile' '**/*.dockerfile' '**/.*ignore' '**/.env*'", verGoPrettier)) + }, + })) + } + if !conf.excluded("format-yaml") { RegisterFormatTask(goyek.Define(goyek.Task{ Name: "format-yaml", diff --git a/versions.go b/versions.go index 1feee73..3c81171 100644 --- a/versions.go +++ b/versions.go @@ -2,6 +2,6 @@ package build const ( verGolangCILint = "v1.58.1" - verGoPrettier = "79c5c1b6332968320c44f93a6a367c54b31796d3" + verGoPrettier = "16a91d6604f1e9fa12ffd31e04e1eb6a28ad5afb" verGoYamllint = "v1.35.1" ) From 86f8cc0631567af2c6824c5ad6df4ec4ab9128b5 Mon Sep 17 00:00:00 2001 From: Choko Date: Wed, 12 Jun 2024 12:08:54 +0900 Subject: [PATCH 2/2] More README --- README.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index eb30c78..3e03a98 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,9 @@ format and lint tasks target the following languages: - YAML All supporting tasks are executed with `go run` - this means that all languages -can be processed with only a single tool dependency, Go itself. +can be processed with only a single tool dependency, Go itself. Programs like +prettier are invoked using [wasilibs](https://github.com/wasilibs) to achieve +this. Note that the goyek default of non-verbose output is overridden since it seems generally better to have verbose output. `-v=false` should be passed to a build