Skip to content

Commit

Permalink
Merge pull request #195 from kachick/rewrite-fmt-with-go
Browse files Browse the repository at this point in the history
Replace fmt glue bash with go
  • Loading branch information
kachick committed Jul 28, 2023
2 parents 0fc574e + e6fd1c4 commit 3a5935f
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 16 deletions.
4 changes: 1 addition & 3 deletions .githooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,5 @@

set -euxo pipefail

shopt -s globstar

./scripts/fmt.bash
makers fmt
makers lint
6 changes: 5 additions & 1 deletion Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ args = [
]

[tasks.fmt]
command = './scripts/fmt.bash'
command = 'go'
args = [
'run',
'./cmd/fmt',
]

[tasks.check]
alias = "lint"
Expand Down
46 changes: 46 additions & 0 deletions cmd/fmt/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package main

import (
"log"
"os"
"os/exec"
"strings"

doublestar "github.com/bmatcuk/doublestar/v4"
)

func main() {
wd, err := os.Getwd()
if err != nil {
log.Fatalln(err)
}
fsys := os.DirFS(wd)

bashPaths, err := doublestar.Glob(fsys, "./**/*.bash")
if err != nil {
log.Fatalln(err)
}
nixPaths, err := doublestar.Glob(fsys, "./**/*.nix")
if err != nil {
log.Fatalln(err)
}

cmds := []struct {
path string
args []string
}{
{"dprint", []string{"fmt"}},
{"shfmt", append([]string{"--write"}, bashPaths...)},
{"nixpkgs-fmt", nixPaths},
{"typos", []string{".", ".github", ".config", ".vscode", "--write-changes"}},
{"go", []string{"fmt", "./..."}},
}

for _, cmd := range cmds {
output, err := exec.Command(cmd.path, cmd.args...).Output()
log.Printf("%s %s\n%s\n", cmd.path, strings.Join(cmd.args, " "), output)
if err != nil {
log.Fatalln(err)
}
}
}
12 changes: 0 additions & 12 deletions scripts/fmt.bash

This file was deleted.

0 comments on commit 3a5935f

Please sign in to comment.