Skip to content

add linting and update go versions in CI #527

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 11 additions & 17 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,23 @@ jobs:
strategy:
fail-fast: false
matrix:
go-version:
- stable
go-version: # see https://endoflife.date/go
- 1.24.x
- 1.23.x
- 1.22.x
- 1.21.x
- 1.20.x
- 1.19.x
- 1.18.x
- 1.17.x
- 1.16.x
- 1.15.x
- 1.14.x
- 1.13.x
- 1.12.x
- 1.11.x
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Set up Go ${{ matrix.go-version }}
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}

- name: Test
run: |
go vet ./...
go test -tags CI -race ./...
env:
GOPATH: /home/runner/go
- name: golangci-lint
uses: golangci/golangci-lint-action@latest
with:
version: latest
args: -v -c .golangci.yaml
7 changes: 7 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
version: "2"
run:
allow-parallel-runners: true
linters:
disable:
- "errcheck"
2 changes: 1 addition & 1 deletion mage/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ func ParseAndRun(stdout, stderr io.Writer, stdin io.Reader, args []string) int {
case None:
return Invoke(inv)
default:
panic(fmt.Errorf("Unknown command type: %v", cmd))
panic(fmt.Errorf("unknown command type: %v", cmd))
}
}

Expand Down
2 changes: 1 addition & 1 deletion mage/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -920,7 +920,7 @@ func TestOnlyStdLib(t *testing.T) {
if err != nil {
t.Fatal(err)
}
if !filepath.HasPrefix(pkg.Dir, build.Default.GOROOT) {
if !strings.HasPrefix(pkg.Dir, build.Default.GOROOT) {
t.Errorf("import of non-stdlib package: %s", s.Path.Value)
}
}
Expand Down
8 changes: 4 additions & 4 deletions mg/deps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func TestDepError(t *testing.T) {
t.Fatal("expected panic, but didn't get one")
}
actual := fmt.Sprint(err)
if "ouch" != actual {
if actual != "ouch" {
t.Fatalf(`expected to get "ouch" but got "%s"`, actual)
}
}()
Expand All @@ -103,7 +103,7 @@ func TestDepFatal(t *testing.T) {
t.Fatal("expected panic, but didn't get one")
}
actual := fmt.Sprint(v)
if "ouch!" != actual {
if actual != "ouch!" {
t.Fatalf(`expected to get "ouch!" but got "%s"`, actual)
}
err, ok := v.(error)
Expand Down Expand Up @@ -132,7 +132,7 @@ func TestDepTwoFatal(t *testing.T) {
}
actual := fmt.Sprint(v)
// order is non-deterministic, so check for both orders
if "ouch!\nbang!" != actual && "bang!\nouch!" != actual {
if actual != "ouch!\nbang!" && actual != "bang!\nouch!" {
t.Fatalf(`expected to get "ouch!" and "bang!" but got "%s"`, actual)
}
err, ok := v.(error)
Expand All @@ -157,7 +157,7 @@ func TestDepWithUnhandledFunc(t *testing.T) {
t.Fatalf("Expected type error from panic")
}
}()
var NotValid func(string) string = func(a string) string {
var NotValid = func(a string) string {
return a
}
Deps(NotValid)
Expand Down
6 changes: 3 additions & 3 deletions mg/fn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func TestFuncCheck(t *testing.T) {
t.Error("func is not on a namespace")
}

hasContext, isNamespace, err = checkF(Foo.Bare, nil)
_, _, err = checkF(Foo.Bare, nil)
if err != nil {
t.Error(err)
}
Expand Down Expand Up @@ -117,11 +117,11 @@ func TestFuncCheck(t *testing.T) {
}

defer func() {
if r := recover(); r !=nil {
if r := recover(); r != nil {
t.Error("expected a nil function argument to be handled gracefully")
}
}()
_, _, err = checkF(nil, []interface{}{1,2})
_, _, err = checkF(nil, []interface{}{1, 2})
if err == nil {
t.Error("expected a nil function argument to be invalid")
}
Expand Down
9 changes: 2 additions & 7 deletions parse/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func checkDupes(info *PkgInfo, imports []*Import) error {
for _, f := range funcs[alias] {
ids = append(ids, f.ID())
}
return fmt.Errorf("alias %q duplicates existing target(s): %s\n", alias, strings.Join(ids, ", "))
return fmt.Errorf("alias %q duplicates existing target(s): %s", alias, strings.Join(ids, ", "))
}
funcs[alias] = append(funcs[alias], f)
}
Expand Down Expand Up @@ -792,11 +792,6 @@ func hasContextParam(ft *ast.FuncType) (bool, error) {
return true, nil
}

func hasVoidReturn(ft *ast.FuncType) bool {
res := ft.Results
return res.NumFields() == 0
}

func hasErrorReturn(ft *ast.FuncType) (bool, error) {
res := ft.Results
if res.NumFields() == 0 {
Expand Down Expand Up @@ -847,7 +842,7 @@ func funcType(ft *ast.FuncType) (*Function, error) {
}

func toOneLine(s string) string {
return strings.TrimSpace(strings.Replace(s, "\n", " ", -1))
return strings.TrimSpace(strings.ReplaceAll(s, "\n", " "))
}

var argTypes = map[string]string{
Expand Down