Skip to content

Should skip_dirs skip analyzing, not just reporting? #4084

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
5 tasks done
alexbozhenko opened this issue Sep 14, 2023 · 6 comments
Closed
5 tasks done

Should skip_dirs skip analyzing, not just reporting? #4084

alexbozhenko opened this issue Sep 14, 2023 · 6 comments
Labels
question Further information is requested

Comments

@alexbozhenko
Copy link

Welcome

Description of the problem

Hi.
It seems like that presence of some invalid code in thrid_party breaks the golangci-lint (see reproducer below).
Would it be possible to change the behavior of skip_dirs to not even look at those dirs?

Version of golangci-lint

golangci-lint --version
golangci-lint has version v1.54.2 built with go1.21.0 from (unknown, mod sum: "h1:oR9zxfWYxt7hFqk6+fw6Enr+E7F0SN2nqHhJYyIb0yo=") on (unknown)

Configuration

Fails even with empty config.

Go environment

$ go version && go env
go version go1.21.0 linux/amd64
GO111MODULE=''
GOARCH='amd64'
GOBIN=''
GOCACHE='/home/abozhenko/.cache/go-build'
GOENV='/home/abozhenko/.config/go/env'
GOEXE=''
GOEXPERIMENT=''
GOFLAGS=''
GOHOSTARCH='amd64'
GOHOSTOS='linux'
GOINSECURE=''
GOMODCACHE='/home/abozhenko/go/pkg/mod'
GONOPROXY=''
GONOSUMDB=''
GOOS='linux'
GOPATH='/home/abozhenko/go'
GOPRIVATE=''
GOPROXY='https://proxy.golang.org,direct'
GOROOT='/usr/local/go'
GOSUMDB='sum.golang.org'
GOTMPDIR=''
GOTOOLCHAIN='auto'
GOTOOLDIR='/usr/local/go/pkg/tool/linux_amd64'
GOVCS=''
GOVERSION='go1.21.0'
GCCGO='gccgo'
GOAMD64='v1'
AR='ar'
CC='gcc'
CXX='g++'
CGO_ENABLED='1'
GOMOD='/home/abozhenko/reproducer/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-build1925773406=/tmp/go-build -gno-record-gcc-switches'

Verbose output of running

$ golangci-lint cache clean
$ golangci-lint run -v
INFO [config_reader] Config search paths: [./ /home/abozhenko/reproducer /home/abozhenko /home /]
INFO [lintersdb] Active 6 linters: [errcheck gosimple govet ineffassign staticcheck unused]
INFO [loader] Go packages loading at mode 575 (types_sizes|exports_file|imports|files|name|compiled_files|deps) took 92.790205ms
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 139.655µs
ERRO [linters_context] typechecking error: C++ source files not allowed when not using cgo or SWIG: build_test.cc
INFO [linters_context/goanalysis] analyzers took 1.903543341s with top 10 stages: buildir: 1.167198861s, ctrlflow: 107.034199ms, fact_deprecated: 99.824768ms, printf: 98.27748ms, fact_purity: 96.808395ms, SA5012: 88.347249ms, nilness: 88.166993ms, typedness: 79.023279ms, inspect: 76.311676ms, directives: 124.947µs
WARN [runner] Can't run linter goanalysis_metalinter: buildir: failed to load package : could not load export data: no export data for "github.com/cncf/xds/go/udpa/data/orca/v1"
INFO [runner] processing took 3.388µs with stages: nolint: 617ns, max_same_issues: 360ns, skip_dirs: 359ns, exclude: 217ns, severity-rules: 205ns, cgo: 181ns, autogenerated_exclude: 156ns, path_prettifier: 134ns, max_from_linter: 134ns, filename_unadjuster: 132ns, identifier_marker: 130ns, source_code: 126ns, exclude-rules: 124ns, skip_files: 114ns, fixer: 114ns, path_prefixer: 49ns, path_shortener: 49ns, uniq_by_line: 48ns, sort_results: 47ns, diff: 46ns, max_per_file_from_linter: 46ns
INFO [runner] linters took 1.162426691s with stages: goanalysis_metalinter: 1.162384212s
ERRO Running error: 1 error occurred:
        * can't run linter goanalysis_metalinter: buildir: failed to load package : could not load export data: no export data for "github.com/cncf/xds/go/udpa/data/orca/v1"

INFO Memory: 14 samples, avg is 168.0MB, max is 241.5MB
INFO Execution took 1.260500811s

A minimal reproducible example or link to a public repository

mkdir reproducer
cd reproducer/
mkdir third_party
git clone https://github.com/cncf/xds third_party/
go mod init reproducer
golangci-lint run

Validation

  • Yes, I've included all information above (version, config, etc.).
@alexbozhenko alexbozhenko added the bug Something isn't working label Sep 14, 2023
@boring-cyborg
Copy link

boring-cyborg bot commented Sep 14, 2023

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

@ldez ldez added question Further information is requested and removed bug Something isn't working labels Sep 15, 2023
@ldez
Copy link
Member

ldez commented Sep 15, 2023

hello,

skip_dirs only ignores the reports from directories.
Your code should compile.

@ldez ldez closed this as completed Sep 15, 2023
@alexbozhenko
Copy link
Author

alexbozhenko commented Sep 15, 2023

Well, there is not even my code in this case. I have https://github.com/cncf/xds in the third-party directory, and there are some .cc files that give this error:

ERRO [linters_context] typechecking error: C++ source files not allowed when not using cgo or SWIG: build_test.cc

Although I have this as a git submodule in my repo, I do not have control over all the files that are present there, so it seems logical to have the option to ignore them completely

I can run golangci-lint and specify only dirs that contain my source code, but I feel like it would be nice to have option to avoid the directory completely.
That would also mean less unnecessary work and a faster run.
Would you be open for a PR?

And thank you so much for what you are doing, Ludovic.

@alexbozhenko
Copy link
Author

Same question was asked here https://stackoverflow.com/questions/59857704/golangci-lint-want-to-really-ignore-a-go-file-not-simply-analyse-it-and-supp
So I guess I am not the only one who needs this.

@ldez
Copy link
Member

ldez commented Sep 15, 2023

If they are required to compile, you cannot skip those files.

Also, the tricks used by syzkaller work only because the files are not required to compile: the files use an "external" function to fill something outside of the files themself, they are independent and don't impact the compilation.

The code should compile, it's not an option.

The real question is: why do you use a submodule instead of just importing the dependency (and use vendoring if you want to keep a local copy)?

@alexbozhenko
Copy link
Author

Thanks for the comment.
@ldez do you think this is an ok workaround:

golangci-lint run $(find * -maxdepth 0 -type d ! -name third_party ! -name vendor -printf '%f/...\n')

Or such invocation can cause some problems, e.g. missing linting problems?

And I will check if we can switch to vendoring, thanks for the suggestion!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants