Skip to content

golangci-lint run cannot find golang files in the current directory #1833

Closed
@zealws

Description

@zealws
  • 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. (https://golangci-lint.run/usage/linters/)
Description of the problem

golangci-lint run (with no other arguments) cannot find any golang files in a simple repository with one golang file:

zeal@theos ~/go/src/github.com/zealws/test
# ls
main.go

zeal@theos ~/go/src/github.com/zealws/test
# golangci-lint run
ERRO Running error: context loading failed: no go files to analyze 

The main.go file is perfectly valid go:

zeal@theos ~/go/src/github.com/zealws/test
# go run main.go 
hello world!

Things I tried which didn't help:

  • Making the directory a git repository and committing the main.go
  • Moving the directory into my $GOPATH
  • Moving the main.go into a subdirectory
  • Copying main.go into a second file.
  • Running golangci-lint run ./... instead.
  • Changing the package name in main.go to lib

The only way I was able to get golangci-lint run to lint the main.go file was providing it as an argument, i.e.: golangci-lint run main.go

Version of golangci-lint
# golangci-lint --version
golangci-lint has version 1.38.0 built from 507703b on 2021-03-10T00:37:58Z
Config file

None.

Go environment
# go version && go env
go version go1.16 linux/amd64
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/home/zeal/.cache/go-build"
GOENV="/home/zeal/.config/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOINSECURE=""
GOMODCACHE="/home/zeal/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="linux"
GOPATH="/home/zeal/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/lib/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GOVCS=""
GOVERSION="go1.16"
GCCGO="gccgo"
AR="ar"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD="/dev/null"
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-build3533911002=/tmp/go-build -gno-record-gcc-switches"
Verbose output of running
zeal@theos ~/go/src/github.com/zealws/test
# golangci-lint cache clean
zeal@theos ~/go/src/github.com/zealws/test
# golangci-lint run -v
INFO [config_reader] Config search paths: [./ /home/zeal/go/src/github.com/zealws/test /home/zeal/go/src/github.com/zealws /home/zeal/go/src/github.com /home/zeal/go/src /home/zeal/go /home/zeal /home /] 
INFO [lintersdb] Active 10 linters: [deadcode errcheck gosimple govet ineffassign staticcheck structcheck typecheck unused varcheck] 
INFO [loader] Go packages loading at mode 575 (deps|types_sizes|compiled_files|files|imports|name|exports_file) took 27.460736ms 
ERRO Running error: context loading failed: no go files to analyze 
INFO Memory: 2 samples, avg is 72.1MB, max is 72.1MB 
INFO Execution took 30.037261ms                   
Code example or link to a public repository

This file was at main.go in the current directory, while running golangci-lint run

package main

import "fmt"

func main() {
        fmt.Println("hello world!")
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions