Skip to content

Commit 21e841b

Browse files
feat: add shfmt support for shell script formatting (#3)
* feat: add shfmt support for shell script formatting Add shfmt as a second WASM plugin alongside the existing gofmt plugin. This change refactors the build system to support multiple formatters, updates the release process to handle both plugins, and incorporates the mvdan.cc/sh parsing and formatting library for shell script support. Apply formatting * Apply formatting * feat: add shfmt support for shell script formatting Add shfmt as a second WASM plugin alongside the existing gofmt plugin. This change refactors the build system to support multiple formatters, updates the release process to handle both plugins, and incorporates the mvdan.cc/sh parsing and formatting library for shell script support. Apply formatting * Apply formatting --------- Co-authored-by: GitHub Actions <actions@github.com>
1 parent d8c90b0 commit 21e841b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+10391
-539
lines changed

.golangci.yml

Lines changed: 349 additions & 31 deletions
Large diffs are not rendered by default.

.releaserc.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,15 @@
88
[
99
"@semantic-release/exec",
1010
{
11-
"prepareCmd": "echo '${nextRelease.version}' > VERSION && make build"
11+
"prepareCmd": "echo '${nextRelease.version}' > cmd/gofmt/VERSION && echo '${nextRelease.version}' > cmd/shfmt/VERSION && make build"
1212
}
1313
],
1414
[
1515
"@semantic-release/github",
1616
{
1717
"assets": [
1818
{
19-
"path": "build/dprint.wasm",
20-
"label": "dprint.wasm"
19+
"path": "build/*.wasm"
2120
}
2221
]
2322
}
@@ -27,7 +26,8 @@
2726
{
2827
"message": "chore(release): ${nextRelease.version} [skip ci]\\n\\n${nextRelease.notes}",
2928
"assets": [
30-
"VERSION"
29+
"cmd/gofmt/VERSION",
30+
"cmd/shfmt/VERSION"
3131
]
3232
}
3333
]

Makefile

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,37 @@
1-
.PHONY: default build lint test vendor clean format
1+
.PHONY: default build build-gofmt build-shfmt lint test test-gofmt test-shfmt vendor clean format
22

33
export GO111MODULE=on
44

55
default: build
66

7-
build:
7+
build: build-gofmt build-shfmt
8+
9+
build-gofmt:
10+
mkdir -p build
11+
tinygo build -o=build/gofmt.wasm -target=wasm-unknown -scheduler=none -no-debug -opt=2 ./cmd/gofmt
12+
go run ./cmd/addstart/main.go build/gofmt.wasm build/gofmt-fixed.wasm
13+
mv build/gofmt-fixed.wasm build/gofmt.wasm
14+
15+
build-shfmt:
816
mkdir -p build
9-
tinygo build -o=build/dprint.wasm -target=wasm-unknown -scheduler=none -no-debug -opt=2 main.go
10-
go run ./cmd/addstart/main.go build/dprint.wasm build/dprint-fixed.wasm
11-
mv build/dprint-fixed.wasm build/dprint.wasm
17+
tinygo build -o=build/shfmt.wasm -target=wasm-unknown -scheduler=none -no-debug -opt=2 ./cmd/shfmt
18+
go run ./cmd/addstart/main.go build/shfmt.wasm build/shfmt-fixed.wasm
19+
mv build/shfmt-fixed.wasm build/shfmt.wasm
1220

1321
lint:
1422
go install github.com/golangci/golangci-lint/cmd/golangci-lint@latest
1523
golangci-lint run --verbose
1624

1725
# Force module mode and CGO so wasmer-go finds its packaged libs.
18-
test:
19-
GOFLAGS= CGO_ENABLED=1 go test -mod=mod -v=true -cover=true -coverprofile=coverage.out -count=1 ./... && go tool cover -html=coverage.out -o coverage.html
26+
test: test-gofmt test-shfmt
27+
28+
# Run tests only in gofmt command package
29+
test-gofmt:
30+
GOFLAGS= CGO_ENABLED=1 go test -mod=mod -v=true -cover=true -count=1 ./cmd/gofmt
31+
32+
# Run tests only in shfmt command package
33+
test-shfmt:
34+
GOFLAGS= CGO_ENABLED=1 go test -mod=mod -v=true -cover=true -count=1 ./cmd/shfmt
2035

2136
vendor:
2237
go mod vendor

README.md

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,22 @@
1-
# dprint-plugin-go
1+
# dprint-plugin-goat
22

3-
**dprint-plugin-go** is a formatter plugin for dprint that formats Go
4-
files using Go’s canonical formatter. It’s compiled to WebAssembly with
5-
TinyGo and plugs into dprint like any other plugin.
3+
**dprint-plugin-goat** provides two formatter plugins for dprint: one for Go files using Go's canonical formatter, and one for shell scripts using shfmt. Both are compiled to WebAssembly with TinyGo and plug into dprint like any other plugin.
64

75
##### Why ?
86

9-
Using a dprint plugin lets you keep a single, consistent formatting
10-
workflow across polyglot repos. This plugin applies `go/format` so your
11-
Go code follows the exact same rules as `gofmt`.
7+
Using dprint plugins lets you keep a single, consistent formatting workflow across polyglot repos. The gofmt plugin applies `go/format` so your Go code follows the exact same rules as `gofmt`, while the shfmt plugin formats shell scripts with the same power as the standalone shfmt tool.
128

139
## Usage
1410

15-
Add the plugin to your **dprint** configuration and format your files.
11+
### gofmt
12+
13+
Add the gofmt plugin to your **dprint** configuration to format Go files.
1614

1715
```json
1816
{
1917
"$schema": "https://dprint.dev/schemas/v0.json",
2018
"plugins": [
21-
"https://github.com/mridang/dprint-go/releases/download/v1.0.0/dprint.wasm"
19+
"https://github.com/mridang/dprint-goat/releases/download/v1.0.0/gofmt.wasm"
2220
],
2321
"includes": [
2422
"**/*.go"
@@ -33,21 +31,42 @@ Add the plugin to your **dprint** configuration and format your files.
3331
dprint fmt --log-level=debug
3432
```
3533

36-
### Options
34+
#### Options
35+
36+
This plugin mirrors `gofmt` and does not add custom options. If you pass an override config from dprint, it is accepted but ignored.
37+
38+
### shfmt
39+
40+
Add the shfmt plugin to your **dprint** configuration to format shell scripts.
41+
42+
```json
43+
{
44+
"$schema": "https://dprint.dev/schemas/v0.json",
45+
"plugins": [
46+
"https://github.com/mridang/dprint-goat/releases/download/v1.0.0/shfmt.wasm"
47+
],
48+
"includes": [
49+
"**/*.sh"
50+
]
51+
}
52+
```
53+
54+
```bash
55+
dprint fmt --log-level=debug
56+
```
57+
58+
#### Options
3759

38-
This plugin mirrors `gofmt` and does not add custom options. If you pass
39-
an override config from dprint, it is accepted but ignored.
60+
This plugin mirrors `shfmt` and does not add custom options. If you pass an override config from dprint, it is accepted but ignored.
4061

4162
## Caveats
4263

4364
None.
4465

4566
## Contributing
4667

47-
Contributions are welcome! If you find a bug or have suggestions for
48-
improvement, please open an issue or submit a pull request.
68+
Contributions are welcome! If you find a bug or have suggestions for improvement, please open an issue or submit a pull request.
4969

5070
## License
5171

5272
Apache License 2.0 © 2025 Mridang Agarwalla
53-

0 commit comments

Comments
 (0)