Skip to content

Commit be39cec

Browse files
authored
Merge pull request #59 from vbatts/lint
*.go: linting and adding lint to the checks done
2 parents 6f5b21b + 21d1635 commit be39cec

File tree

5 files changed

+51
-6
lines changed

5 files changed

+51
-6
lines changed

.github/workflows/lint.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: lint
2+
3+
on:
4+
pull_request:
5+
branches_ignore: []
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
strategy:
11+
matrix:
12+
go: ['1.20']
13+
14+
name: Documentation and Linting
15+
steps:
16+
17+
- uses: actions/checkout@v2
18+
with:
19+
path: go/src/github.com/vbatts/git-validation
20+
21+
# commit for v1 release
22+
- uses: actions/setup-go@0caeaed6fd66a828038c2da3c0f662a42862658f
23+
with:
24+
go-version: ${{ matrix.go }}
25+
26+
- name: lint
27+
env:
28+
GOPATH: /home/runner/work/git-validation/git-validation/go
29+
run: |
30+
set -x
31+
export PATH=$GOPATH/bin:$PATH
32+
cd go/src/github.com/vbatts/git-validation
33+
go run mage.go -v lint

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ using the `GIT_CHECK_EXCLUDE` environment variable. Multiple paths should be sep
107107
When making a change, verify it with:
108108

109109
```shell
110-
go run mage.go vet build test
110+
go run mage.go lint vet build test
111111
```
112112

113113
## Rules

main.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ var (
2727
flTravisPROnly = flag.Bool("travis-pr-only", true, "when on travis, only run validations if the CI-Build is checking pull-request build")
2828
)
2929

30+
func init() {
31+
logrus.SetOutput(os.Stderr)
32+
}
33+
3034
func main() {
3135
flag.Parse()
3236

validate/rules.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,14 @@ func SanitizeFilters(filtStr string) (filters []string) {
7575
//
7676
// Some `includes` rules have values assigned to them.
7777
// i.e. -run "dco,message_regexp='^JIRA-[0-9]+ [A-Z].*$'"
78-
//
7978
func FilterRules(rules []Rule, includes []string) []Rule {
8079
ret := []Rule{}
8180

8281
for _, r := range rules {
8382
for i := range includes {
8483
if strings.Contains(includes[i], "=") {
8584
chunks := strings.SplitN(includes[i], "=", 2)
86-
if strings.ToLower(r.Name) == strings.ToLower(chunks[0]) {
85+
if strings.EqualFold(r.Name, chunks[0]) {
8786
// for these rules, the Name won't be unique per se. There may be
8887
// multiple "regexp=" with different values. We'll need to set the
8988
// .Value = chunk[1] and ensure r is dup'ed so they don't clobber
@@ -93,7 +92,7 @@ func FilterRules(rules []Rule, includes []string) []Rule {
9392
ret = append(ret, newR)
9493
}
9594
} else {
96-
if strings.ToLower(r.Name) == strings.ToLower(includes[i]) {
95+
if strings.EqualFold(r.Name, includes[i]) {
9796
ret = append(ret, r)
9897
}
9998
}

validate/runner.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"os"
66
"path/filepath"
77

8+
"github.com/sirupsen/logrus"
89
"github.com/vbatts/git-validation/git"
910
)
1011

@@ -29,7 +30,11 @@ func NewRunner(root string, rules []Rule, commitrange string, verbose bool) (*Ru
2930
if err != nil {
3031
return nil, err
3132
}
32-
defer os.Chdir(cwd)
33+
defer func() {
34+
if err := os.Chdir(cwd); err != nil {
35+
logrus.Warnf("changing working directory to %q failed: %s", cwd, err)
36+
}
37+
}()
3338

3439
if err := os.Chdir(newroot); err != nil {
3540
return nil, err
@@ -56,7 +61,11 @@ func (r *Runner) Run() error {
5661
if err != nil {
5762
return err
5863
}
59-
defer os.Chdir(cwd)
64+
defer func() {
65+
if err := os.Chdir(cwd); err != nil {
66+
logrus.Warnf("changing working directory to %q failed: %s", cwd, err)
67+
}
68+
}()
6069

6170
if err := os.Chdir(r.Root); err != nil {
6271
return err

0 commit comments

Comments
 (0)