From fa60ee1eb1918cebc80174a7699cfafe921f3d2b Mon Sep 17 00:00:00 2001 From: Collin Kreklow Date: Wed, 15 May 2024 12:53:36 -0500 Subject: [PATCH] Update CI configuration Bump Go and golangci-lint versions to current. --- .github/workflows/lint.yml | 10 ++++---- .github/workflows/test.yml | 14 +++++------ .golangci.yml | 49 +++++++++++++++++++++++++++----------- 3 files changed, 47 insertions(+), 26 deletions(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 85f4b11..c5657bf 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -10,12 +10,12 @@ jobs: name: GolangCI-Lint steps: - name: Setup Go - uses: actions/setup-go@v3 + uses: actions/setup-go@v5 with: - go-version: '^1.19.0' + go-version: stable - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Run Lint - uses: golangci/golangci-lint-action@v3 + uses: golangci/golangci-lint-action@v6 with: - version: v1.49 + version: latest diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 694629b..217e4b5 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,15 +9,15 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - go: [ '~1.19.0', '~1.18.0' ] + go: [ 'stable', 'oldstable' ] name: Go ${{ matrix.go }} steps: - name: Setup Go - uses: actions/setup-go@v3 + uses: actions/setup-go@v5 with: go-version: ${{ matrix.go }} - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Run Tests run: go test -v -race ./... codecov: @@ -26,14 +26,14 @@ jobs: name: Codecov steps: - name: Setup Go - uses: actions/setup-go@v3 + uses: actions/setup-go@v5 with: - go-version: '~1.19.0' + go-version: 'stable' - name: Checkout - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Run Tests run: go test -v -race -coverprofile=coverage.txt -covermode=atomic ./... - name: Upload to Codecov - uses: codecov/codecov-action@v3 + uses: codecov/codecov-action@v4 with: file: ./coverage.txt diff --git a/.golangci.yml b/.golangci.yml index 7abf9ca..90cce07 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -5,61 +5,84 @@ linters: - asciicheck # Check for non-ASCII identifiers - bidichk # Checks for dangerous unicode character sequences - bodyclose # Checks whether HTTP response body is closed successfully + - canonicalheader # Checks whether net/http.Header uses canonical header - containedctx # Detects struct contained context.Context field - contextcheck # Check if a function uses a non-inherited context - cyclop # Checks function and package cyclomatic complexity - decorder # Check declaration order and count of types, constants, variables and functions - dogsled # Checks assignments with too many blank identifiers - dupl # Code clone detection + - dupword # Checks for duplicate words in the source code - durationcheck # Check for two durations multiplied together + - err113 # Check error handling expressions - errcheck # Checking for unchecked errors - - errchkjson # Checks types passed to the json encoding functions. Reports unsupported types and optionally reports occasions where the check for the returned error can be omitted + - errchkjson # Checks types passed to the JSON encoding functions - errname # Checks that sentinel errors are prefixed with `Err` and error types are suffixed with `Error` - errorlint # Find code that will cause problems with error wrapping - - execinquery # query string checker - exhaustive # Check exhaustiveness of enum switch statements - exportloopref # Checks for pointers to enclosing loop variables + - fatcontext # Detects nested contexts in loops - forbidigo # Forbids identifiers - forcetypeassert # Finds forced type assertions - funlen # Detection of long functions + - gci # Control package import order and make it always deterministic + - ginkgolinter # Enforces standards of using ginkgo and gomega + - gocheckcompilerdirectives # Checks that go compiler directive comments (//go:) are valid - gochecknoglobals # Checks that no globals are present - gochecknoinits # Checks that no init functions are present in Go code + - gochecksumtype # Run exhaustiveness checks on Go "sum types" - gocognit # Computes and checks the cognitive complexity of functions - goconst # Finds repeated strings that could be replaced by a constant - gocritic # The most opinionated Go source code linter - gocyclo # Computes and checks the cyclomatic complexity of functions - godot # Check if comments end in a period - godox # Detection of FIXME, TODO and other comment keywords - - goerr113 # Check error handling expressions - gofmt # Checks whether code was gofmt-ed + - gofumpt # Checks whether code was gofumpt-ed + - goimports # Does everything that gofmt does and checks unused imports - gomoddirectives # Manage the use of 'replace', 'retract', and 'excludes' in go.mod - goprintffuncname # Checks that printf-like functions are named with `f` at the end - gosec # Inspects source code for security problems - gosimple # Specializes in simplifying code + - gosmopolitan # Report certain i18n/l10n anti-patterns in your Go codebase - govet # Reports suspicious constructs, such as Printf calls whose arguments do not align with the format string - grouper # An analyzer to analyze expression groups - importas # Enforces consistent import aliases + - inamedparam # Reports interfaces with unnamed method parameters - ineffassign # Detects when assignments to existing variables are not used - interfacebloat # Checks the number of methods inside an interface - ireturn # Accept interfaces, return concrete types - - logrlint # Check logr arguments + - loggercheck # Checks key value pairs for common logger libraries - maintidx # Measures the maintainability index of each function - makezero # Finds slice declarations with non-zero initial length + - mirror # Reports wrong mirror patterns of bytes/strings usage - misspell # Finds commonly misspelled English words in comments - nakedret # Finds naked returns in functions greater than a specified function length - nestif # Reports deeply nested if statements - nilerr # Finds the code that returns nil even if it checks that the error is not nil - nilnil # Checks that there is no simultaneous return of `nil` error and an invalid value - nlreturn # Checks for a new line before return and branch statements + - noctx # Finds sending HTTP request without context.Context - nolintlint # Reports ill-formed or insufficient nolint directives - nosprintfhostport # Checks for misuse of Sprintf to construct a host with port in a URL + - perfsprint # Checks that fmt.Sprintf can be replaced with a faster alternative - prealloc # Finds slice declarations that could potentially be preallocated - predeclared # Find code that shadows one of Go's predeclared identifiers + - promlinter # Check Prometheus metrics naming via promlint + - protogetter # Reports direct reads from proto message fields when getters should be used - reassign # Checks that package variables are not reassigned - revive # Fast, configurable, extensible, flexible, and beautiful linter for Go + - rowserrcheck # Checks whether err of rows is checked successfully + - sloglint # Ensure consistent code style when using log/slog + - spancheck # Checks for mistakes with OpenTelemetry/Census spans + - sqlclosecheck # Checks that sql.Rows and sql.Stmt are closed - staticcheck # Go vet on steroids, applying a ton of static analysis checks + - stylecheck # Replacement for golint + - tagalign # Checks that struct tags are well aligned - tagliatelle # Checks the struct tags - tenv # Detects using os.Setenv instead of t.Setenv + - testableexamples # Checks if examples are testable + - testifylint # Checks usage of github.com/stretchr/testify - testpackage # Makes you use a separate _test package - thelper # Detects test helpers without t.Helper() and checks the consistency of test helpers - tparallel # Detects inappropriate usage of t.Parallel() method in Go test code @@ -71,23 +94,21 @@ linters: - wastedassign # Finds wasted assignment statements - whitespace # Detection of leading and trailing whitespace - wsl # Whitespace Linter - Forces you to use empty lines! + - zerologlint # Detects the wrong usage of `zerolog` that a user forgets to dispatch with `Send` or `Msg` + + # Disabled until 1.22 + #- copyloopvar # Detects places where loop variables are copied + #- intrange # Finds places where for loops could make use of an integer range #- depguard # Checks if package imports are in a list of acceptable packages #- exhaustruct # Checks if all structure fields are initialized - #- gci # Control package import order and make it always deterministic - #- gofumpt # Checks whether code was gofumpt-ed #- goheader # Checks if file header matches to pattern - #- goimports # Does everything that gofmt does and checks unused imports - #- gomnd # An analyzer to detect magic numbers - #- gomodguard # Allow and block list linter for direct Go module dependencies. This is different from depguard where there are different block types for example version constraints and module recommendations. + #- gomodguard # Allow and block list linter for direct Go module dependencies #- lll # Reports long lines - #- noctx # Finds sending HTTP request without context.Context + #- mnd # An analyzer to detect magic numbers + #- musttag # Enforce field tags in (un)marshaled structs #- nonamedreturns # Reports all named returns #- paralleltest # Detects missing usage of t.Parallel() method in tests - #- promlinter # Check Prometheus metrics naming via promlint - #- rowserrcheck # Checks whether err of rows is checked successfully - #- sqlclosecheck # Checks that sql.Rows and sql.Stmt are closed. - #- stylecheck # Replacement for golint #- varnamelen # Checks that the length of a variable's name matches its scope #- wrapcheck # Checks that errors returned from external packages are wrapped