diff --git a/.githooks/pre-commit b/.githooks/pre-commit index b3e96b20..49c51e41 100755 --- a/.githooks/pre-commit +++ b/.githooks/pre-commit @@ -5,4 +5,4 @@ set -euxo pipefail shopt -s globstar ./scripts/fmt.bash -./scripts/lint.bash +makers lint diff --git a/Makefile.toml b/Makefile.toml index 9beeeee6..259c0686 100644 --- a/Makefile.toml +++ b/Makefile.toml @@ -20,7 +20,11 @@ script = [ ] [tasks.lint] -command = './scripts/lint.bash' +command = 'go' +args = [ + 'run', + './cmd/lint', +] [tasks.fmt] command = './scripts/fmt.bash' @@ -39,6 +43,17 @@ args = [ command = 'mkdir' args = ['-p', 'dist'] +[tasks.build] +dependencies = ['prepare-build'] +command = 'go' +args = [ + 'build', + '-v', + '-o', + 'dist', + './...', +] + [tasks.test-race] dependencies = ['prepare-build'] command = 'go' diff --git a/cmd/lint/main.go b/cmd/lint/main.go new file mode 100644 index 00000000..a6fe035d --- /dev/null +++ b/cmd/lint/main.go @@ -0,0 +1,48 @@ +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{"check"}}, + {"shfmt", append([]string{"--diff"}, bashPaths...)}, + {"shellcheck", bashPaths}, + {"nixpkgs-fmt", append([]string{"--check"}, nixPaths...)}, + {"typos", []string{".", ".github", ".config", ".vscode"}}, + {"gitleaks", []string{"detect"}}, + {"go", []string{"vet", "./..."}}, + } + + 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) + } + } +} diff --git a/go.mod b/go.mod index 764067fe..76f944eb 100644 --- a/go.mod +++ b/go.mod @@ -1,3 +1,5 @@ module github.com/kachick/dotfiles go 1.20 + +require github.com/bmatcuk/doublestar/v4 v4.6.0 diff --git a/go.sum b/go.sum new file mode 100644 index 00000000..ce9f561f --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +github.com/bmatcuk/doublestar/v4 v4.6.0 h1:HTuxyug8GyFbRkrffIpzNCSK4luc0TY3wzXvzIZhEXc= +github.com/bmatcuk/doublestar/v4 v4.6.0/go.mod h1:xBQ8jztBU6kakFMg+8WGxn0c6z1fTSPVIjEY1Wr7jzc= diff --git a/scripts/lint.bash b/scripts/lint.bash deleted file mode 100755 index 9ec3e12e..00000000 --- a/scripts/lint.bash +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env bash - -set -euxo pipefail - -shopt -s globstar - -dprint check -shfmt --diff ./**/*.bash -shellcheck ./**/*.bash -nixpkgs-fmt --check ./**/*.nix -typos . .github .config .vscode -gitleaks detect -go vet ./...