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

Add shell formatting tasks / workspace settings #16

Merged
merged 2 commits into from
Jun 12, 2024
Merged
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
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,13 @@ 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
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
Expand Down
18 changes: 17 additions & 1 deletion go-build.code-workspace
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down
22 changes: 22 additions & 0 deletions standard.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ package build

const (
verGolangCILint = "v1.58.1"
verGoPrettier = "79c5c1b6332968320c44f93a6a367c54b31796d3"
verGoPrettier = "16a91d6604f1e9fa12ffd31e04e1eb6a28ad5afb"
verGoYamllint = "v1.35.1"
)