diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e6bff518..4a0544c6 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 diff --git a/.golangci.yaml b/.golangci.yaml new file mode 100644 index 00000000..3047e937 --- /dev/null +++ b/.golangci.yaml @@ -0,0 +1,7 @@ +--- +version: "2" +run: + allow-parallel-runners: true +linters: + disable: + - "errcheck" \ No newline at end of file diff --git a/mage/main.go b/mage/main.go index 0062bd35..f25fb92b 100644 --- a/mage/main.go +++ b/mage/main.go @@ -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)) } } diff --git a/mage/main_test.go b/mage/main_test.go index 8b21fb4b..05c2774c 100644 --- a/mage/main_test.go +++ b/mage/main_test.go @@ -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) } } diff --git a/mg/deps_test.go b/mg/deps_test.go index 8424544f..f1f51109 100644 --- a/mg/deps_test.go +++ b/mg/deps_test.go @@ -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) } }() @@ -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) @@ -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) @@ -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) diff --git a/mg/fn_test.go b/mg/fn_test.go index 8ca481c8..4c1d08e6 100644 --- a/mg/fn_test.go +++ b/mg/fn_test.go @@ -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) } @@ -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") } diff --git a/parse/parse.go b/parse/parse.go index c64e7cc2..3e157638 100644 --- a/parse/parse.go +++ b/parse/parse.go @@ -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) } @@ -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 { @@ -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{