You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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 --versiongolangci-lint has version v1.64.8 built with go1.23.8 from (unknown, modified: ?, mod sum: "h1:y5TdeVidMtBGG32zgSC7ZXTFNHrsJkDnpO4ItB3Am+I=") on (unknown)
Configuration
run:
concurrency: 4timeout: 5mtests: truemodules-download-mode: readonlyallow-parallel-runners: trueallow-serial-runners: truego: '1.23'issues:
fix: truemax-issues-per-linter: 0max-same-issues: 0exclude-rules:
- path: ^(.*/)?(integration_)?test/linters:
- gosec
- goconst
- mnd
- path: _test\.go$linters:
- gosec
- goconst
- mndexclude-dirs:
- \.vendor\.pb$
- vendor$
- mocks$exclude-files:
- \.pb\.go$
- \.pb\.gw\.go$
- \.swagger\.go$
- _mocks\.go$include:
#gosec
- EXC0006
- EXC0007
- EXC0008
- EXC0009
- EXC0010linters-settings:
errcheck:
check-type-assertions: truegoconst:
min-len: 2min-occurrences: 2gocritic:
settings:
captLocal:
paramsOnly: falsegoimports:
local-prefixes: <some prefix>misspell:
locale: USgosimple:
checks:
- "all"govet:
enable-all: truedisable:
- fieldalignment # disable alignment of structures
- shadow # disable all shadows declarationlinters:
disable-all: trueenable:
- 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/amd64GO111MODULE=''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 -vINFO 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.ymlINFO [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.).
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.
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
changed the title
golangci-lint uses erroneous go.mod from its cache
gomoddirectives: uses erroneous go.mod
Apr 15, 2025
ldez
changed the title
gomoddirectives: uses erroneous go.mod
gomoddirectives: uses erroneous go.mod in the some cases
Apr 15, 2025
Welcome
typecheck
section of the FAQ.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.
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
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
Configuration
Go environment
Verbose output of running
A minimal reproducible example or link to a public repository
This line deleted
Validation
Supporter
The text was updated successfully, but these errors were encountered: