Skip to content

Commit

Permalink
Merge pull request #194 from kachick/rewrite-script-with-go
Browse files Browse the repository at this point in the history
Rewrite linter glue bash with go
  • Loading branch information
kachick committed Jul 28, 2023
2 parents 669cd42 + 8250756 commit 9149395
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .githooks/pre-commit
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ set -euxo pipefail
shopt -s globstar

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

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

[tasks.fmt]
command = './scripts/fmt.bash'
Expand All @@ -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'
Expand Down
48 changes: 48 additions & 0 deletions cmd/lint/main.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
}
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module github.com/kachick/dotfiles

go 1.20

require github.com/bmatcuk/doublestar/v4 v4.6.0
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
13 changes: 0 additions & 13 deletions scripts/lint.bash

This file was deleted.

0 comments on commit 9149395

Please sign in to comment.