From 44121646a8a46b05d1f1f2b1bffc30c74aade571 Mon Sep 17 00:00:00 2001 From: Steven Hartland Date: Sat, 7 Sep 2024 10:19:46 +0100 Subject: [PATCH] ci: enhanced linting Update golangci-lint and add a configuration file which makes it much more strict. Bump version of go so we get all the latest linters. --- .github/workflows/golangci-lint.yml | 7 +-- .golangci.yaml | 83 +++++++++++++++++++++++++++++ go.mod | 2 +- 3 files changed, 86 insertions(+), 6 deletions(-) create mode 100644 .golangci.yaml diff --git a/.github/workflows/golangci-lint.yml b/.github/workflows/golangci-lint.yml index 93aed7b..808a980 100644 --- a/.github/workflows/golangci-lint.yml +++ b/.github/workflows/golangci-lint.yml @@ -17,10 +17,7 @@ jobs: steps: - uses: actions/checkout@v4 - uses: actions/setup-go@v5 - with: - go-version-file: 'go.mod' - name: golangci-lint - uses: golangci/golangci-lint-action@3cfe3a4abbb849e10058ce4af15d205b6da42804 # v4 + uses: golangci/golangci-lint-action@v6 with: - version: v1.55.2 - args: --timeout=3m + version: v1.60.3 diff --git a/.golangci.yaml b/.golangci.yaml new file mode 100644 index 0000000..0acf5c9 --- /dev/null +++ b/.golangci.yaml @@ -0,0 +1,83 @@ +run: + timeout: 2m + +linters-settings: + gosec: + excludes: + - G601 ## Implicit memory aliasing of items from a range statement - not possible in go 1.22. + cyclop: + max-complexity: 15 + nestif: + min-complexity: 10 + govet: + settings: + shadow: + strict: true + enable-all: true + nolintlint: + require-explanation: true + godot: + scope: all + +linters: + enable-all: true + disable: + # Spammy / low value + - varnamelen + - exhaustruct + - nlreturn + - wsl + - lll + - paralleltest + # Duplicate functionality. + - funlen + - gocognit + # Deprecated. + - execinquery + - gomnd + # Good but gets in the way too often. + - testpackage + # Unknown details about how Artemis works are flagged with TODO's. + - godox + # Seems to be broken. + - depguard + # Makes it messy for multiple optional tags. + - tagalign + # Not needed for go 1.22+. + - exportloopref + - errchkjson # Duplicate functionality for errcheck. + +issues: + include: + - EXC0012 + - EXC0014 + exclude-rules: + # Exclude linters which aren't an issue in tests. + - path: _test\.go + linters: + - gochecknoglobals + - wrapcheck + + # File mode permissions are fine for constants. + - text: "Magic number: 0o\\d+" + linters: + - mnd + + # Field alignment in tests isn't a performance issue. + - text: fieldalignment + path: _test\.go + + # Dynamic errors can provide useful context. + - text: "do not define dynamic errors, use wrapped static errors instead:" + linters: + - err113 + + # We need to use the `err` named return for error handling. + - text: 'named return "err" with type "error" found' + linters: + - nonamedreturns + + # Interface casting is fine in mock. + - path: mock_test\.go + linters: + - forcetypeassert diff --git a/go.mod b/go.mod index 83905d0..d258d5e 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/testcontainers/moby-ryuk -go 1.21 +go 1.23 require ( github.com/docker/docker v27.1.1+incompatible