Skip to content

Commit

Permalink
ci: update golangci-lint version
Browse files Browse the repository at this point in the history
Remove some unnecessary nolint comments.
Replace gocyclo with maintidx.
Add some new linters, and fix some errors reported by them.
  • Loading branch information
dnephin committed Apr 16, 2022
1 parent ba04258 commit fcb6826
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 38 deletions.
5 changes: 3 additions & 2 deletions .circleci/config.yml
@@ -1,12 +1,13 @@
version: 2.1

orbs:
go: gotest/tools@0.0.13
go: gotest/tools@0.0.14

workflows:
ci:
jobs:
- lint
- lint:
golangci-lint-version: 1.45.2
- go/test:
name: test-golang-1.15
executor:
Expand Down
15 changes: 11 additions & 4 deletions .golangci.yml
@@ -1,11 +1,11 @@
linters-settings:
gocyclo:
min-complexity: 10
goconst:
min-len: 5
min-occurrences: 10
lll:
line-length: 100
maintidx:
under: 40

issues:
exclude-use-default: false
Expand All @@ -15,7 +15,7 @@ issues:
- text: 'always receives'
linters: [unparam]
- path: _test\.go
linters: [errcheck, staticcheck, lll]
linters: [errcheck, staticcheck, lll, maintidx]
- path: internal/difflib/difflib\.go
text: .
- text: 'return value of .*Close` is not checked'
Expand All @@ -36,9 +36,10 @@ linters:
- depguard
- dogsled
- errcheck
- errorlint
- exportloopref
- gocognit
- goconst
- gocyclo
- gofmt
- goimports
- golint
Expand All @@ -47,8 +48,13 @@ linters:
- ineffassign
- interfacer
- lll
- maintidx
- misspell
- nakedret
- nestif
- nilerr
- nilnil
- nolintlint
- prealloc
- staticcheck
- structcheck
Expand All @@ -58,4 +64,5 @@ linters:
- unparam
- unused
- varcheck
- wastedassign
- whitespace
1 change: 0 additions & 1 deletion assert/assert_test.go
Expand Up @@ -337,7 +337,6 @@ func expectFailNowed(t testingT, fakeT *fakeTestingT, expected string) {
}
}

// nolint: unparam
func expectFailed(t testingT, fakeT *fakeTestingT, expected string) {
if ht, ok := t.(helperT); ok {
ht.Helper()
Expand Down
3 changes: 2 additions & 1 deletion assert/cmd/gty-migrate-from-testify/main.go
Expand Up @@ -2,6 +2,7 @@ package main

import (
"bytes"
"errors"
"fmt"
"go/ast"
"go/format"
Expand Down Expand Up @@ -78,7 +79,7 @@ func handleExitError(name string, err error) {
switch {
case err == nil:
return
case err == pflag.ErrHelp:
case errors.Is(err, pflag.ErrHelp):
os.Exit(0)
default:
log.Println(name + ": Error: " + err.Error())
Expand Down
2 changes: 1 addition & 1 deletion assert/cmd/gty-migrate-from-testify/migrate.go
Expand Up @@ -141,7 +141,7 @@ func convertTestifySingleArgCall(tcall call) ast.Node {
}
}

// nolint: gocyclo
// nolint: maintidx
func convertTestifyAssertion(tcall call, migration migration) ast.Node {
imports := migration.importNames

Expand Down
5 changes: 3 additions & 2 deletions assert/cmp/compare.go
Expand Up @@ -166,7 +166,7 @@ func Contains(collection interface{}, item interface{}) Comparison {
return func() Result {
colValue := reflect.ValueOf(collection)
if !colValue.IsValid() {
return ResultFailure(fmt.Sprintf("nil does not contain items"))
return ResultFailure("nil does not contain items")
}
msg := fmt.Sprintf("%v does not contain %v", collection, item)

Expand Down Expand Up @@ -248,6 +248,7 @@ type causer interface {
}

func formatErrorMessage(err error) string {
// nolint: errorlint // unwrapping is not appropriate here
if _, ok := err.(causer); ok {
return fmt.Sprintf("%q\n%+v", err, err)
}
Expand Down Expand Up @@ -308,7 +309,7 @@ func ErrorType(err error, expected interface{}) Comparison {
}
return cmpErrorTypeEqualType(err, expectedType)
case nil:
return ResultFailure(fmt.Sprintf("invalid type for expected: nil"))
return ResultFailure("invalid type for expected: nil")
}

expectedType := reflect.TypeOf(expected)
Expand Down
1 change: 0 additions & 1 deletion assert/cmp/compare_test.go
Expand Up @@ -441,7 +441,6 @@ func assertFailureHasPrefix(t testingT, res Result, prefix string) {
}
}

// nolint: unparam
func assertFailureTemplate(t testingT, res Result, args []ast.Expr, expected string) {
if ht, ok := t.(helperT); ok {
ht.Helper()
Expand Down
3 changes: 1 addition & 2 deletions fs/report.go
Expand Up @@ -72,7 +72,6 @@ func removeCarriageReturn(in []byte) []byte {
return bytes.Replace(in, []byte("\r\n"), []byte("\n"), -1)
}

// nolint: gocyclo
func eqFile(x, y *file) []problem {
p := eqResource(x.resource, y.resource)

Expand Down Expand Up @@ -159,7 +158,7 @@ func eqSymlink(x, y *symlink) []problem {

func eqDirectory(path string, x, y *directory) []failure {
p := eqResource(x.resource, y.resource)
var f []failure // nolint: prealloc
var f []failure
matchedFiles := make(map[string]bool)

for _, name := range sortedKeys(x.items) {
Expand Down
4 changes: 2 additions & 2 deletions golden/golden_test.go
Expand Up @@ -203,7 +203,7 @@ func setupGoldenFileWithDir(t *testing.T, dirname, content string) (string, func
_ = os.MkdirAll(filepath.Join("testdata", dirname), 0755)
f, err := ioutil.TempFile(dirpath, t.Name()+"-")
assert.NilError(t, err, "fail to create test golden file")
defer f.Close() // nolint: errcheck
defer f.Close()

_, err = f.Write([]byte(content))
assert.NilError(t, err)
Expand All @@ -218,7 +218,7 @@ func setupGoldenFile(t *testing.T, content string) (string, func()) {
_ = os.Mkdir("testdata", 0755)
f, err := ioutil.TempFile("testdata", t.Name()+"-")
assert.NilError(t, err, "fail to create test golden file")
defer f.Close() // nolint: errcheck
defer f.Close()

_, err = f.Write([]byte(content))
assert.NilError(t, err)
Expand Down
1 change: 0 additions & 1 deletion icmd/command.go
Expand Up @@ -77,7 +77,6 @@ func (r *Result) Compare(exp Expected) error {
return r.match(exp)
}

// nolint: gocyclo
func (r *Result) match(exp Expected) error {
errors := []string{}
add := func(format string, args ...interface{}) {
Expand Down
32 changes: 12 additions & 20 deletions icmd/exitcode.go
@@ -1,32 +1,24 @@
package icmd

import (
"fmt"
"syscall"
"errors"

exec "golang.org/x/sys/execabs"
)

// getExitCode returns the ExitStatus of a process from the error returned by
// exec.Run(). If the exit status could not be parsed an error is returned.
func getExitCode(err error) (int, error) {
if exiterr, ok := err.(*exec.ExitError); ok {
if procExit, ok := exiterr.Sys().(syscall.WaitStatus); ok {
return procExit.ExitStatus(), nil
}
}
return 0, fmt.Errorf("failed to get exit code: %w", err)
}

func processExitCode(err error) (exitCode int) {
func processExitCode(err error) int {
if err == nil {
return 0
}
exitCode, exiterr := getExitCode(err)
if exiterr != nil {
// TODO: Fix this so we check the error's text.
// we've failed to retrieve exit code, so we set it to 127
return 127

var exitErr *exec.ExitError
if errors.As(err, &exitErr) {
if exitErr.ProcessState == nil {
return 0
}
if code := exitErr.ProcessState.ExitCode(); code != -1 {
return code
}
}
return exitCode
return 127
}
1 change: 0 additions & 1 deletion internal/assert/assert.go
Expand Up @@ -23,7 +23,6 @@ type helperT interface {
const failureMessage = "assertion failed: "

// Eval the comparison and print a failure messages if the comparison has failed.
// nolint: gocyclo
func Eval(
t LogT,
argSelector argSelector,
Expand Down

0 comments on commit fcb6826

Please sign in to comment.