diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 652b65d..a92adf7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,21 +9,6 @@ on: pull_request: jobs: - check-modules: - runs-on: ubuntu-latest - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - name: Install Go(lang) - uses: actions/setup-go@v5 - with: - go-version: 1.21.x - - name: Check module dependencies - run: | - go version - test -z "$(go mod tidy && git status go.* --porcelain)" - go mod verify - run-unit-tests: runs-on: ubuntu-latest steps: diff --git a/.github/workflows/linter.yml b/.github/workflows/linter.yml new file mode 100644 index 0000000..b7f4360 --- /dev/null +++ b/.github/workflows/linter.yml @@ -0,0 +1,42 @@ +name: Lint + +on: + push: + pull_request: + +jobs: + check-modules: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v4 + - name: Install Go(lang) + uses: actions/setup-go@v5 + with: + go-version: 1.21.x + - name: Check module dependencies + run: | + go version + test -z "$(go mod tidy && git status go.* --porcelain)" + go mod verify + + lint: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + - name: Install Go + uses: actions/setup-go@v5 + with: + go-version: 1.21.x + - name: Retrieve golangci-lint version + run: | + echo "Version=$(head -n 1 "${GITHUB_WORKSPACE}/.golangci.yml" | tr -d '# ')" >> $GITHUB_OUTPUT + id: version + - name: golangci-lint + uses: golangci/golangci-lint-action@v3 + with: + version: ${{ steps.version.outputs.Version }} + only-new-issues: true diff --git a/.golangci.yml b/.golangci.yml new file mode 100644 index 0000000..5749395 --- /dev/null +++ b/.golangci.yml @@ -0,0 +1,126 @@ +# v1.55.2 +# Please don't remove the first line. It is used in CI to determine the golangci-lint version +run: + deadline: 5m + +issues: + # Maximum issues count per one linter. Set to 0 to disable. Default is 50. + max-issues-per-linter: 0 + # Maximum count of issues with the same text. Set to 0 to disable. Default is 3. + max-same-issues: 0 + + # We want to try and improve the comments in the k6 codebase, so individual + # non-golint items from the default exclusion list will gradually be added + # to the exclude-rules below + exclude-use-default: false + + exclude-rules: + # Exclude duplicate code and function length and complexity checking in test + # files (due to common repeats and long functions in test code) + - path: _(test|gen)\.go + linters: + - cyclop + - dupl + - gocognit + - funlen + - lll + - linters: + - forbidigo + text: 'use of `os\.(SyscallError|Signal|Interrupt)` forbidden' + +linters-settings: + nolintlint: + # Disable to ensure that nolint directives don't have a leading space. Default is true. + allow-leading-space: false + exhaustive: + default-signifies-exhaustive: true + govet: + check-shadowing: true + cyclop: + max-complexity: 25 + maligned: + suggest-new: true + dupl: + threshold: 150 + goconst: + min-len: 10 + min-occurrences: 4 + funlen: + lines: 80 + statements: 60 + forbidigo: + forbid: + - '^(fmt\\.Print(|f|ln)|print|println)$' + # Forbid everything in os, except os.Signal and os.SyscalError + - '^os\.(.*)$(# Using anything except Signal and SyscallError from the os package is forbidden )?' + # Forbid everything in syscall except the uppercase constants + - '^syscall\.[^A-Z_]+$(# Using anything except constants from the syscall package is forbidden )?' + - '^logrus\.Logger$' + +linters: + disable-all: true + enable: + - asasalint + - asciicheck + - bidichk + - bodyclose + - contextcheck + - cyclop + - dogsled + - dupl + - durationcheck + - errcheck + - errchkjson + - errname + - errorlint + - exhaustive + - exportloopref + - forbidigo + - forcetypeassert + - funlen + - gocheckcompilerdirectives + - gochecknoglobals + - gocognit + - goconst + - gocritic + - gofmt + - gofumpt + - goimports + - gomoddirectives + - goprintffuncname + - gosec + - gosimple + - govet + - importas + - ineffassign + - interfacebloat + - lll + - makezero + - misspell + - nakedret + - nestif + - nilerr + - nilnil + - noctx + - nolintlint + - nosprintfhostport + - paralleltest + - prealloc + - predeclared + - promlinter + - revive + - reassign + - rowserrcheck + - sqlclosecheck + - staticcheck + - stylecheck + - tenv + - tparallel + - typecheck + - unconvert + - unparam + - unused + - usestdlibvars + - wastedassign + - whitespace + fast: false