diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f472be4..5788529 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,6 +23,19 @@ jobs: cache-dependency-path: ./go.sum id: go + - name: golangci-lint + uses: golangci/golangci-lint-action@3a919529898de77ec3da873e3063ca4b10e7f5cc # v3 + with: + # Optional: version of golangci-lint to use in form of v1.2 or v1.2.3 or `latest` to use the latest version + version: v1.55.2 + # Optional: working directory, useful for monorepos + working-directory: . + # Optional: golangci-lint command line arguments. + args: --verbose + # Optional: if set to true then the all caching functionality will be complete disabled, + # takes precedence over all other caching options. + skip-cache: true + - name: Build run: go build ./... diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..34c05c3 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,27 @@ +linters: + enable: + - errorlint + - gci + - gocritic + - gofumpt + - misspell + - nonamedreturns + +linters-settings: + errorlint: + # Check whether fmt.Errorf uses the %w verb for formatting errors. + # See the https://github.com/polyfloyd/go-errorlint for caveats. + errorf: true + # Permit more than 1 %w verb, valid per Go 1.20 (Requires errorf:true) + errorf-multi: true + # Check for plain type assertions and type switches. + asserts: true + # Check for plain error comparisons. + comparison: true + gci: + sections: + - standard + - default + - prefix(github.com/testcontainers) +run: + timeout: 5m diff --git a/examples_test.go b/examples_test.go index d195cd4..8046188 100644 --- a/examples_test.go +++ b/examples_test.go @@ -17,8 +17,8 @@ func ExampleSelfSigned() { certsDir := tmp + "/certs" defer os.RemoveAll(certsDir) - if err := os.MkdirAll(certsDir, 0755); err != nil { - log.Fatal(err) + if err := os.MkdirAll(certsDir, 0o755); err != nil { + log.Fatal(err) // nolint: gocritic } // Generate a certificate for localhost and save it to disk. @@ -51,7 +51,10 @@ func ExampleSelfSigned() { server.Handler = http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) { w.Header().Set("Content-Type", "text/plain") - w.Write([]byte("TLS works!\n")) + _, err := w.Write([]byte("TLS works!\n")) + if err != nil { + log.Printf("Failed to write response: %v", err) + } }) go func() { @@ -90,5 +93,4 @@ func ExampleSelfSigned() { // Output: // TLS works! - }