golangci-lint --version (or git commit if you don't use binary distribution)cat .golangci.ymlrun:
# default concurrency is a available CPU number
concurrency: 4
# timeout for analysis, e.g. 30s, 5m, default is 1m
deadline: 5m
# which dirs to skip: they won't be analyzed;
# can use regexp here: generated.*, regexp is applied on full path;
# default value is empty list, but next dirs are always skipped independently
# from this option's value:
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
skip-dirs:
- genfiles$
- vendor$
# which files to skip: they will be analyzed, but issues from them
# won't be reported. Default value is empty list, but there is
# no need to include all autogenerated files, we confidently recognize
# autogenerated files. If it's not please let us know.
skip-files:
- ".*\\.pb\\.go"
- ".*\\.gen\\.go"
# all available settings of specific linters
linters-settings:
errcheck:
# report about not checking of errors in type assetions: `a := b.(MyStruct)`;
# default is false: such cases aren't reported by default.
check-type-assertions: false
# report about assignment of errors to blank identifier: `num, _ := strconv.Atoi(numStr)`;
# default is false: such cases aren't reported by default.
check-blank: false
govet:
# report about shadowed variables
check-shadowing: false
golint:
# minimal confidence for issues, default is 0.8
min-confidence: 0.0
gofmt:
# simplify code: gofmt with `-s` option, true by default
simplify: true
goimports:
# put imports beginning with prefix after 3rd-party packages;
# it's a comma-separated list of prefixes
local-prefixes: istio.io/
gocyclo:
# minimal code complexity to report, 30 by default (but we recommend 10-20)
min-complexity: 10
maligned:
# print struct with more effective memory layout or not, false by default
suggest-new: true
dupl:
# tokens count to trigger issue, 150 by default
threshold: 100
goconst:
# minimal length of string constant, 3 by default
min-len: 3
# minimal occurrences count to trigger, 3 by default
min-occurrences: 3
depguard:
list-type: blacklist
include-go-root: false
packages:
- github.com/davecgh/go-spew/spew
misspell:
# Correct spellings using locale preferences for US or UK.
# Default is to use a neutral variety of English.
# Setting locale to US will correct the British spelling of 'colour' to 'color'.
locale: US
lll:
# max line length, lines longer will be reported. Default is 120.
# '\t' is counted as 1 character by default, and can be changed with the tab-width option
line-length: 160
# tab width in spaces. Default to 1.
tab-width: 1
unused:
# treat code as a program (not a library) and report unused exported identifiers; default is false.
# XXX: if you enable this setting, unused will report a lot of false-positives in text editors:
# if it's called for subdir of a project it can't find funcs usages. All text editor integrations
# with golangci-lint call it on a directory with the changed file.
check-exported: false
unparam:
# call graph construction algorithm (cha, rta). In general, use cha for libraries,
# and rta for programs with main packages. Default is cha.
algo: cha
# Inspect exported functions, default is false. Set to true if no external program/library imports your code.
# XXX: if you enable this setting, unparam will report a lot of false-positives in text editors:
# if it's called for subdir of a project it can't find external interfaces. All text editor integrations
# with golangci-lint call it on a directory with the changed file.
check-exported: false
nakedret:
# make an issue if func has more lines of code than this setting and it has naked returns; default is 30
max-func-lines: 30
prealloc:
# XXX: we don't recommend using this linter before doing performance profiling.
# For most programs usage of prealloc will be a premature optimization.
# Report preallocation suggestions only on simple loops that have no returns/breaks/continues/gotos in them.
# True by default.
simple: true
range-loops: true # Report preallocation suggestions on range loops, true by default
for-loops: false # Report preallocation suggestions on for loops, false by default
linters:
enable:
- deadcode
- goimports
- golint
- govet
- gosimple
- interfacer
- lll
- misspell
- staticcheck
- structcheck
- ineffassign
- unconvert
- unparam
- unused
- varcheck
enable-all: false
disable:
- gocritic
- prealloc
- typecheck
- megacheck
- nakedret
- scopelint
- gochecknoglobals
- gochecknoinits
- gosec
# start here to enable back all gometalinter linters
- errcheck
- goconst
- maligned
disable-all: false
presets:
- bugs
- unused
fast: false
issues:
# List of regexps of issue texts to exclude, empty list by default.
# But independently from this option we use default exclude patterns,
# it can be disabled by `exclude-use-default: false`. To list all
# excluded by default patterns execute `golangci-lint run --help`
exclude: []
# Independently from option `exclude` we use default exclude patterns,
# it can be disabled by this option. To list all
# excluded by default patterns execute `golangci-lint run --help`.
# Default value for this option is true.
exclude-use-default: true
# Maximum issues count per one linter. Set to 0 to disable. Default is 50.
max-per-linter: 0
# Maximum count of issues with the same text. Set to 0 to disable. Default is 3.
max-same-issues: 0
go version && go env$ go version && go env
go version go1.11.2 linux/amd64
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/admin/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/admin/go"
GOPROXY=""
GORACE=""
GOROOT="/home/admin/linka-tools/go"
GOTMPDIR=""
GOTOOLDIR="/home/admin/linka-tools/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build140861160=/tmp/go-build -gno-record-gcc-switches"
golangci-lint run -vINFO [config_reader] Config search paths: [./ /home/admin/scanning/task-source/sofa-mosn /home/admin/scanning/task-source /home/admin/scanning /home/admin /home /]
INFO [config_reader] Used config file .golangci.yml
INFO [lintersdb] Active 12 linters: [deadcode goimports golint govet ineffassign interfacer lll misspell structcheck unconvert unparam varcheck]
INFO [lintersdb] Active presets: [bugs unused]
INFO [loader] Go packages loading at mode load deps types and syntax took 548.623388ms
ERRO Running error: context loading failed: failed to load program with go/packages: go [list -e -json -compiled -test=true -export=false -deps=true -find=false -- ./...]: exit status 1: go build github.com/.../pkg/admin: no Go files in
go build github.com/.../pkg/buffer: no Go files in
go build github.com/.../pkg/config: no Go files in
......
hi, thank you for reporting!
github.com/.../pkg/buffer: no Go files in means that this package wasn't loaded: most often this happens when dependencies weren't installed. Is it dependency?
hi, thank you for reporting!
github.com/.../pkg/buffer: no Go files inmeans that this package wasn't loaded: most often this happens when dependencies weren't installed. Is it dependency?
yes, it's dependency, and I probably know the reason. thx for your reply.
@Rico1900

in my case (on jenkins), it solved my problem:
add in .golangci.yml
run:
modules-download-mode: vendor
Feel I've just hit the same blocker. My program uses modules, so the vendorsolution would not apply.
I'm first running go generate to get around any compile errors, then run linter. The build works locally but fails on travis:
make
rm -rf bin/ pkg/ dist/ *.zip
Generating embedded assets
GO111MODULE=on go generate ./...
go: finding github.com/google/go-github v17.0.0+incompatible
go: finding github.com/gorilla/mux v1.7.2
go: finding github.com/mjibson/esc v0.2.0
go: finding github.com/tcnksm/go-latest v0.0.0-20170313132115-e3007ae9052e
go: finding github.com/gorilla/handlers v1.4.0
go: finding golang.org/x/sys v0.0.0-20190516110030-61b9204099cb
go: finding golang.org/x/tools v0.0.0-20190517183331-d88f79806bbd
go: finding golang.org/x/text v0.3.2
go: finding golang.org/x/crypto v0.0.0-20190513172903-22d7a77e9e5f
go: finding gopkg.in/urfave/cli.v1 v1.20.0
go: finding github.com/google/go-querystring v1.0.0
go: finding github.com/eclipse/paho.mqtt.golang v1.2.0
go: finding github.com/gorilla/websocket v1.4.0
go: finding golang.org/x/sys v0.0.0-20190412213103-97732733099d
go: finding github.com/grid-x/serial v0.0.0-20171015094157-98648473d6ff
golangci-lint run
level=error msg="Running error: context loading failed: failed to load program with go/packages:
go [list -e -json -compiled -test=true -export=false -deps=true -find=false -- ./...]: exit status 1:
go build github.com/eclipse/paho.mqtt.golang: no Go files in
go build github.com/gorilla/handlers: no Go files in
go build github.com/gorilla/mux: no Go files in
go build github.com/gorilla/websocket: no Go files in
go build github.com/grid-x/modbus: no Go files in
go build github.com/tcnksm/go-latest: no Go files in
go build gopkg.in/urfave/cli.v1: no Go files in
"
make: *** [checks] Error 3
The command "make" exited with 2.
Sources are in https://github.com/andig/mbmd/tree/rename.
may i know fix/workaround to resolve the issue ?
you need just to install all dependencies
Sorry to comment on a closed issue but how to make golangci-lint work with Go Modules?
I had to manually install all the dependencies (go get -u github.com/.../...), while they were already there with Modules (go get) and GO111MODULE was set to on.
Is there anything I'm missing here?
A possible solution, I guess, would be to disable Go Modules, go get, enable modules again, run golangci-lint. I'd like to avoid that path if there is a better solution though
@tsauvajon Have you tried this?
run:
modules-download-mode: vendor
Same via command line: --modules-download-mode vendor
Adding a .golintci.yml file would solve the issue locally, but the CI would then show the real problem:
import cycle not allowed
which was a useful error as two files were importing each other
It's failing without flag --moduls-download-mode vendor
level=error msg="Running error: context loading failed: failed to load packages: failed to load with go/packages:
err: exit status 1:
stderr: go: github.com/<private-package>:
invalid version: git fetch -f origin refs/heads/*:refs/heads/* refs/tags/*:refs/tags/* in /home/runner/go/pkg/mod/cache/vcs/<edited>: exit status 128:\n\t
fatal: could not read Username for 'https://github.com': terminal prompts disabled\n"
and it's failing with multiples errors when flag added
multiple (per each modules which is listed in go.mod)
...
...could not import...
...
As a side note, notice the modules-download-mode: vendor in the configuration file: sadly, this did not help at all.
Most helpful comment
@Rico1900