Thanks to visit codestin.com
Credit goes to github.com

Skip to content

gomoddirectives: false-negative / false-positive #5736

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

Closed
6 of 7 tasks
TheRoSS opened this issue Apr 15, 2025 · 4 comments · Fixed by #5739
Closed
6 of 7 tasks

gomoddirectives: false-negative / false-positive #5736

TheRoSS opened this issue Apr 15, 2025 · 4 comments · Fixed by #5739
Assignees
Labels
area: cache bug Something isn't working

Comments

@TheRoSS
Copy link

TheRoSS commented Apr 15, 2025

Welcome

  • Yes, I'm using a binary release within 2 latest releases. Only such installations are supported.
  • Yes, I've searched similar issues on GitHub and didn't find any.
  • Yes, I've read the typecheck section of the FAQ.
  • Yes, I've tried with the standalone linter if available (e.g., gocritic, go vet, etc.).
  • I agree to follow this project's Code of Conduct

How did you install golangci-lint?

go install

Description of the problem

I had 'replace' directive in the go.mod file. Linter complained with gomoddirectives error on line 127. I removed this line. But linter continues to complain.

WARN [runner/source_code] Failed to get line 127 for file /home/alex/ws/rupor/video/go.mod: invalid file line index0 (126) >= len(fc) (126) 
go.mod:127:1: replacement are not allowed: gitlab-b.rutube.ru/cyber-rom/rupor/cmatch-scheduler (gomoddirectives)

But there is no line 127 at all in the go.mod file anymore.
If I switch to another git branch the error disappears. If I switch back to the original branch the error returns back too.

The problem can be solved with command

golangci-lint cache clean

From this I can conclude that linter takes go.mod file from cache even after its modification.

The problem arises not permanently. I saw it second time during 4 months.

P.S. I used jetbrains GoLand 2024.3.5 to edit go.mod file. Maybe it matters.

Version of golangci-lint

$ golangci-lint --version
golangci-lint has version v1.64.8 built with go1.23.8 from (unknown, modified: ?, mod sum: "h1:y5TdeVidMtBGG32zgSC7ZXTFNHrsJkDnpO4ItB3Am+I=") on (unknown)

Configuration

run:
  concurrency: 4
  timeout: 5m
  tests: true
  modules-download-mode: readonly
  allow-parallel-runners: true
  allow-serial-runners: true
  go: '1.23'

issues:
  fix: true
  max-issues-per-linter: 0
  max-same-issues: 0
  exclude-rules:
    - path: ^(.*/)?(integration_)?test/
      linters:
        - gosec
        - goconst
        - mnd
    - path: _test\.go$
      linters:
        - gosec
        - goconst
        - mnd
  exclude-dirs:
    - \.vendor\.pb$
    - vendor$
    - mocks$
  exclude-files:
    - \.pb\.go$
    - \.pb\.gw\.go$
    - \.swagger\.go$
    - _mocks\.go$

  include:
    #gosec
    - EXC0006
    - EXC0007
    - EXC0008
    - EXC0009
    - EXC0010

linters-settings:
  errcheck:
    check-type-assertions: true

  goconst:
    min-len:         2
    min-occurrences: 2

  gocritic:
    settings:
      captLocal:
        paramsOnly: false

  goimports:
    local-prefixes: <some prefix>

  misspell:
    locale: US

  gosimple:
    checks:
      - "all"

  govet:
    enable-all: true
    disable:
      - fieldalignment # disable alignment of structures
      - shadow # disable all shadows declaration

linters:
  disable-all: true
  enable:
    - asciicheck # checks that your code does not contain non-ASCII identifiers
    - bidichk # checks for dangerous unicode character sequences
    - bodyclose # checks whether HTTP response body is closed successfully
    - copyloopvar # checks for pointers to enclosing loop variables
    - dogsled # checks assignments with too many blank identifiers (e.g. x, , , _, := f())
    - errcheck # errcheck is a program for checking for unchecked errors in Go code
    - errname # checks that sentinel errors are prefixed with the Err and error types are suffixed with the Error
    - gocognit # computes and checks the cognitive complexity of functions
    - goconst # finds repeated strings that could be replaced by a constant
    - gocritic # provides diagnostics that check for bugs, performance and style issues
    - gocyclo # computes and checks the cyclomatic complexity of functions
    - gofmt # gofmt checks whether code was gofmt-ed
    - goimports # check import statements are formatted according to the 'goimport' command
    - gomoddirectives # manages the use of 'replace', 'retract', and 'excludes' directives in go.mod
    - gosec # inspects source code for security problems
    - gosimple # linter for Go source code that specializes in simplifying code
    - govet # reports suspicious constructs
    - ineffassign # detects when assignments to existing variables are not used
    - misspell # finds commonly misspelled English words in comments
    - mnd # an analyzer to detect magic numbers
    - nilerr # finds the code that returns nil even if it checks that
    - noctx # finds sending http request without context
    - prealloc # finds slice declarations that could potentially be pre-allocated
    - predeclared # finds code that shadows one of Go's predeclared
    - revive # configurable linter for Go, provides a framework for development of custom rules.
    - staticcheck # https://staticcheck.io/docs/
    - stylecheck # stylecheck is a replacement for golint
    - unconvert # remove unnecessary type conversions
    - unparam # reports unused function parameters
    - unused # checks Go code for unused constants, variables, functions and types
    - whitespace # tool for detection of leading and trailing whitespace

Go environment

go version go1.23.8 linux/amd64
GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/alex/.cache/go-build'
GOENV='/home/alex/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/alex/.gvm/pkgsets/go1.23.8/global/pkg/mod'
GONOPROXY='gitlab.cyrm.ru/*,gitlab-b.rutube.ru/cyber-rom/rupor/*,gitlab.rutube.ru/*'
GONOSUMDB='gitlab.cyrm.ru/*,gitlab-b.rutube.ru/cyber-rom/rupor/*,gitlab.rutube.ru/*'
GOOS='linux'
GOPATH='/home/alex/.gvm/pkgsets/go1.23.8/global'
GOPRIVATE='gitlab.cyrm.ru/*,gitlab-b.rutube.ru/cyber-rom/rupor/*,gitlab.rutube.ru/*'
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/home/alex/.gvm/gos/go1.23.8'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/home/alex/.gvm/gos/go1.23.8/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.23.8'
GODEBUG=''
GOTELEMETRY='local'
GOTELEMETRYDIR='/home/alex/.config/go/telemetry'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/home/alex/ws/rupor/video/go.mod'
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 -ffile-prefix-map=/tmp/go-build3323948570=/tmp/go-build -gno-record-gcc-switches'

Verbose output of running

$ golangci-lint cache clean
!!! This fixes the problem
$ golangci-lint run -v
INFO golangci-lint has version v1.64.8 built with go1.23.8 from (unknown, modified: ?, mod sum: "h1:y5TdeVidMtBGG32zgSC7ZXTFNHrsJkDnpO4ItB3Am+I=") on (unknown) 
INFO [config_reader] Config search paths: [...] 
INFO [config_reader] Used config file ./.golangci.yml
INFO [goenv] Read go env for 7.515976ms: map[string]string{"GOCACHE":"/home/.../.cache/go-build", "GOROOT":"/home/.../.gvm/gos/go1.23.8"} 
INFO [lintersdb] Active 31 linters: [asciicheck bidichk bodyclose copyloopvar dogsled errcheck errname gocognit goconst gocritic gocyclo gofmt goimports gomoddirectives gosec gosimple govet ineffassign misspell mnd nilerr noctx prealloc predeclared revive staticcheck stylecheck unconvert unparam unused whitespace] 
INFO [loader] Go packages loading at mode 8767 (compiled_files|files|name|types_sizes|deps|exports_file|imports) took 1.048974991s 
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 236.333271ms 
INFO [linters_context/goanalysis] analyzers took 0s with no stages 
INFO [runner] Applying suggested fixes            
INFO [runner] fixer took 470ns with stages: all: 470ns 
INFO [runner/exclusion_rules] Skipped 5 issues by rules: [Path: "_test\\.go$", Linters: "gosec, goconst, mnd"] 
INFO [runner/exclusion_rules] Skipped 45 issues by rules: [Path: "^(.*/)?(integration_)?test/", Linters: "gosec, goconst, mnd"] 
INFO [runner] Issues before processing: 3728, after processing: 0 
INFO [runner] Processors filtering stat (in/out): skip_dirs: 2653/2653, identifier_marker: 2266/2266, exclusion_rules: 2266/74, path_absoluter: 3728/3728, skip_files: 3728/2653, invalid_issue: 3728/3728, exclusion_paths: 3728/3728, cgo: 3728/3728, filename_unadjuster: 3728/3728, path_relativity: 3728/3728, nolint_filter: 74/0, generated_file_filter: 2653/2266 
INFO [runner] processing took 70.062434ms with stages: nolint_filter: 28.973133ms, exclusion_rules: 17.699448ms, generated_file_filter: 11.38701ms, path_relativity: 4.214477ms, skip_dirs: 3.822557ms, skip_files: 1.300504ms, invalid_issue: 927.637µs, filename_unadjuster: 909.179µs, identifier_marker: 409.35µs, cgo: 216.513µs, path_absoluter: 167.033µs, fixer: 32.391µs, max_same_issues: 535ns, max_from_linter: 469ns, exclusion_paths: 450ns, sort_results: 336ns, uniq_by_line: 292ns, diff: 290ns, source_code: 290ns, path_shortener: 221ns, max_per_file_from_linter: 114ns, severity-rules: 103ns, path_prettifier: 102ns 
INFO [runner] linters took 927.928914ms with stages: goanalysis_metalinter: 857.6949ms 
INFO File cache stats: 0 entries of total size 0B 
INFO Memory: 24 samples, avg is 66.5MB, max is 104.5MB 
INFO Execution took 2.218360717s                  

A minimal reproducible example or link to a public repository

go.mod:
...
127: replace ... => ...

This line deleted

Validation

  • Yes, I've included all information above (version, config, etc.).

Supporter

@TheRoSS TheRoSS added the bug Something isn't working label Apr 15, 2025
Copy link

boring-cyborg bot commented Apr 15, 2025

Hey, thank you for opening your first Issue ! 🙂 If you would like to contribute we have a guide for contributors.

@ldez
Copy link
Member

ldez commented Apr 15, 2025

Hello,

To be precise, the go.mod is not inside the cache; in this case, only issues are inside the cache.

The go.mod is not a Go file (it's not code), so it's outside of the main flow.

@TheRoSS
Copy link
Author

TheRoSS commented Apr 15, 2025

Hello.
You know the inners better than me)
But after cache clean the problem has gone.
As I siad this is a second time I saw this problem.
First time I solved the problem by deleting the git branch.

@ldez
Copy link
Member

ldez commented Apr 15, 2025

By clearing the cache, you are forcing the full analysis to run again, so yes, it "fixes" the problem.
My comment was here to explain the behavior, not to say the problem is unrelated to the cache.

@ldez ldez changed the title golangci-lint uses erroneous go.mod from its cache gomoddirectives: uses erroneous go.mod Apr 15, 2025
@ldez ldez changed the title gomoddirectives: uses erroneous go.mod gomoddirectives: uses erroneous go.mod in the some cases Apr 15, 2025
@ldez ldez self-assigned this Apr 15, 2025
@ldez ldez changed the title gomoddirectives: uses erroneous go.mod in the some cases gomoddirectives: false-negative / false-positive Apr 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: cache bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants