Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nolintlint: respect build constraints #3833

Open
4 tasks done
leonklingele opened this issue May 13, 2023 · 0 comments
Open
4 tasks done

nolintlint: respect build constraints #3833

leonklingele opened this issue May 13, 2023 · 0 comments
Labels
area: nolint Related to nolint directive and nolintlint

Comments

@leonklingele
Copy link
Contributor

leonklingele commented May 13, 2023

Welcome

  • Yes, I'm using a binary release within 2 latest major releases. Only such installations are supported.
  • Yes, I've searched similar issues on GitHub and didn't find any.
  • Yes, I've included all information below (version, config, etc.).
  • Yes, I've tried with the standalone linter if available (e.g., gocritic, go vet, etc.). (https://golangci-lint.run/usage/linters/)

Description of the problem

Please excuse if this is not the appropriate place to report this issue at. I don't know the exact reason why the problem described in the following occurs. To me it seems the nolintlint evaluator doesn't respect Go build constraints.

I was working on this PR: gofiber/fiber#2462

The golangci-lint CI action was failing on a file having a Go build constraint of //go:build go1.20` due to `Error: directive `//nolint:gosec // unsafe is used for better performance here` is unused for linter "gosec" (nolintlint).
See the failing job here: https://github.com/gofiber/fiber/actions/runs/4968641325/jobs/8891360463.

The issue was fixed by removing the nolint:gosec directive, although unsafe package was used. See this commit:
gofiber/fiber@bcefaac

For another file depending on Go < 1.20, the nolint directive however was correctly identified & used: https://github.com/gofiber/fiber/blob/bcefaaca110919a8f9e1a357dd639408b0f0cfac/utils/convert_s2b_old.go#L16

Version of golangci-lint

Run golangci/golangci-lint-action@v3
  with:
    version: v1.51.0
    github-token: ***
    only-new-issues: false
    skip-cache: false
    skip-pkg-cache: false
    skip-build-cache: false

prepare environment
  Checking for go.mod: go.mod
  Finding needed golangci-lint version...
  Installing golangci-lint v1.51.0...
  Downloading https://github.com/golangci/golangci-lint/releases/download/v1.51.0/golangci-lint-1.51.0-linux-amd64.tar.gz ...
  Cache not found for input keys: golangci-lint.cache-[2](https://github.com/gofiber/fiber/actions/runs/4968641325/jobs/8891360463#step:4:2)784-4060f4964adef5e6ff14aa501850a90ee8[3](https://github.com/gofiber/fiber/actions/runs/4968641325/jobs/8891360463#step:4:3)66fde, golangci-lint.cache-278[4](https://github.com/gofiber/fiber/actions/runs/4968641325/jobs/8891360463#step:4:4)-
  /usr/bin/tar xz --overwrite --warning=no-unknown-keyword --overwrite -C /home/runner -f /home/runner/work/_temp/87d13fd[5](https://github.com/gofiber/fiber/actions/runs/4968641325/jobs/8891360463#step:4:5)-1[6](https://github.com/gofiber/fiber/actions/runs/4968641325/jobs/8891360463#step:4:6)0b-4b[7](https://github.com/gofiber/fiber/actions/runs/4968641325/jobs/8891360463#step:4:7)f-917c-[8](https://github.com/gofiber/fiber/actions/runs/4968641325/jobs/8891360463#step:4:8)cd[9](https://github.com/gofiber/fiber/actions/runs/4968641325/jobs/8891360463#step:4:10)6c00eda6
  Installed golangci-lint into /home/runner/golangci-lint-1.51.0-linux-amd64/golangci-lint in 874ms
  Prepared env in 878ms

Configuration file

https://github.com/gofiber/fiber/blob/77c1b4868a686254a839fbbb88d7f46cbadb055a/.golangci.yml

# Created based on v1.51.0
# NOTE: Keep this in sync with the version in .github/workflows/linter.yml

run:
  modules-download-mode: readonly
  skip-dirs-use-default: false
  skip-dirs:
    - internal

output:
  sort-results: true

linters-settings:
  errcheck:
     check-type-assertions: true
     check-blank: true
     disable-default-exclusions: true

  errchkjson:
    report-no-exported: true

  exhaustive:
    default-signifies-exhaustive: true

  forbidigo:
    forbid:
      - ^(fmt\.Print(|f|ln)|print|println)$
      - 'http\.Default(Client|Transport)'
      # TODO: Eventually enable these patterns
      # - 'time\.Sleep'
      # - 'panic'

  gocritic:
    disabled-checks:
      - ifElseChain

  gofumpt:
    module-path: github.com/gofiber/fiber
    extra-rules: true

  gosec:
    config:
      global:
        audit: true

  govet:
    check-shadowing: true
    enable-all: true
    disable:
      - shadow
      - fieldalignment
      - loopclosure

  grouper:
    import-require-single-import: true
    import-require-grouping: true

  misspell:
    locale: US

  nolintlint:
    require-explanation: true
    require-specific: true

  nonamedreturns:
    report-error-in-defer: true

  predeclared:
    q: true

  promlinter:
    strict: true

  revive:
    enable-all-rules: true
    rules:
      # Provided by gomnd linter
      - name: add-constant
        disabled: true
      - name: argument-limit
        disabled: true
      # Provided by bidichk
      - name: banned-characters
        disabled: true
      - name: cognitive-complexity
        disabled: true
      - name: cyclomatic
        disabled: true
      - name: early-return
        severity: warning
        disabled: true
      - name: exported
        disabled: true
      - name: file-header
        disabled: true
      - name: function-result-limit
        disabled: true
      - name: function-length
        disabled: true
      - name: line-length-limit
        disabled: true
      - name: max-public-structs
        disabled: true
      - name: modifies-parameter
        disabled: true
      - name: nested-structs
        disabled: true
      - name: package-comments
        disabled: true

  stylecheck:
    checks:
      - all
      - -ST1000
      - -ST1020
      - -ST1021
      - -ST1022

  tagliatelle:
    case:
      rules:
        json: snake

  #tenv:
  #  all: true

  #unparam:
  #  check-exported: true

  wrapcheck:
    ignorePackageGlobs:
      - github.com/gofiber/fiber/*
      - github.com/valyala/fasthttp

issues:
   exclude-use-default: false

linters:
  enable:
    - asasalint
    - asciicheck
    - bidichk
    - bodyclose
    - containedctx
    - contextcheck
    - depguard
    - dogsled
    - durationcheck
    - errcheck
    - errchkjson
    - errname
    - errorlint
    - execinquery
    - exhaustive
    - exportloopref
    - forbidigo
    - forcetypeassert
    - goconst
    - gocritic
    - gofmt
    - gofumpt
    - goimports
    - gomoddirectives
    - goprintffuncname
    - gosec
    - gosimple
    - govet
    - grouper
    - loggercheck
    - misspell
    - nakedret
    - nilerr
    - nilnil
    - noctx
    - nolintlint
    - nonamedreturns
    - nosprintfhostport
    - predeclared
    - promlinter
    - reassign
    - revive
    - rowserrcheck
    - sqlclosecheck
    - staticcheck
    - stylecheck
    - tagliatelle
    # - testpackage # TODO: Enable once https://github.com/gofiber/fiber/issues/2252 is implemented
    - thelper
    # - tparallel # TODO: Enable once https://github.com/gofiber/fiber/issues/2254 is implemented
    - typecheck
    - unconvert
    - unparam
    - unused
    - usestdlibvars
    - wastedassign
    - whitespace
    - wrapcheck

Go environment

Run actions/setup-go@v4
  with:
    go-version: 1.[2](https://github.com/gofiber/fiber/actions/runs/4968641325/jobs/8891360463#step:2:2)0.x
    check-latest: false
    token: ***
    cache: true
Setup go version spec 1.20.x
Found in cache @ /opt/hostedtoolcache/go/1.20.[4](https://github.com/gofiber/fiber/actions/runs/4968641325/jobs/8891360463#step:2:4)/x[6](https://github.com/gofiber/fiber/actions/runs/4968641325/jobs/8891360463#step:2:6)4
Added go to the path
Successfully set up Go version 1.20.x
/opt/hostedtoolcache/go/1.20.4/x64/bin/go env GOMODCACHE
/opt/hostedtoolcache/go/1.20.4/x64/bin/go env GOCACHE
/home/runner/go/pkg/mod
/home/runner/.cache/go-build
Warning: Restore cache failed: Dependencies file is not found in /home/runner/work/fiber/fiber. Supported file pattern: go.sum
go version go1.20.4 linux/amd64

go env
  GO111MODULE=""
  GOARCH="amd64"
  GOBIN=""
  GOCACHE="/home/runner/.cache/go-build"
  GOENV="/home/runner/.config/go/env"
  GOEXE=""
  GOEXPERIMENT=""
  GOFLAGS=""
  GOHOSTARCH="amd64"
  GOHOSTOS="linux"
  GOINSECURE=""
  GOMODCACHE="/home/runner/go/pkg/mod"
  GONOPROXY=""
  GONOSUMDB=""
  GOOS="linux"
  GOPATH="/home/runner/go"
  GOPRIVATE=""
  GOPROXY="https://proxy.golang.org,direct"
  GOROOT="/opt/hostedtoolcache/go/1.20.4/x64"
  GOSUMDB="sum.golang.org"
  GOTMPDIR=""
  GOTOOLDIR="/opt/hostedtoolcache/go/1.20.4/x64/pkg/tool/linux_amd64"
  GOVCS=""
  GOVERSION="go1.20.4"
  GCCGO="gccgo"
  GOAMD64="v1"
  AR="ar"
  CC="gcc"
  CXX="g++"
  CGO_ENABLED="1"
  GOMOD="/dev/null"
  GOWORK=""
  CGO_CFLAGS="-O2 -g"
  CGO_CPPFLAGS=""
  CGO_CXXFLAGS="-O2 -g"
  CGO_FFLAGS="-O2 -g"
  CGO_LDFLAGS="-O2 -g"
  PKG_CONFIG="pkg-config"
  GOGCCFLAGS="-fPIC -m64 -pthread -Wl,--no-gc-sections -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build[19](https://github.com/gofiber/fiber/actions/runs/4968641325/jobs/8891360463#step:2:20)6036[35](https://github.com/gofiber/fiber/actions/runs/4968641325/jobs/8891360463#step:2:36)90=/tmp/go-build -gno-record-gcc-switches"

Verbose output of running

run golangci-lint
  Running [/home/runner/golangci-lint-1.51.0-linux-amd64/golangci-lint run --out-format=github-actions] in [] ...
  Error: directive `//nolint:gosec // unsafe is used for better performance here` is unused for linter "gosec" (nolintlint)
  
  level=warning msg="[linters_context] rowserrcheck is disabled because of generics. You can track the evolution of the generics support by following the https://github.com/golangci/golangci-lint/issues/2649."
  level=warning msg="[linters_context] sqlclosecheck is disabled because of generics. You can track the evolution of the generics support by following the https://github.com/golangci/golangci-lint/issues/2649."
  level=warning msg="[linters_context] wastedassign is disabled because of generics. You can track the evolution of the generics support by following the https://github.com/golangci/golangci-lint/issues/2649."
  level=error msg="Timeout exceeded: try increasing it by passing --timeout option"
  
  Error: golangci-lint exit with code 4
  Ran golangci-lint in 71644ms

Code example or link to a public repository

gofiber/fiber#2462

@leonklingele leonklingele added the bug Something isn't working label May 13, 2023
@ldez ldez added question Further information is requested and removed bug Something isn't working labels Jun 2, 2023
@ldez ldez added area: nolint Related to nolint directive and nolintlint and removed question Further information is requested labels Mar 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: nolint Related to nolint directive and nolintlint
Projects
None yet
Development

No branches or pull requests

2 participants