-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
golangci-lint -> gocritic -> ruleguard fails with no indication #2190
Comments
Hey, thank you for opening your first Issue ! 🙂 If you would like to contribute we have a guide for contributors. |
hello, |
Check out k8s.io/kubernetes. $ cat > .golangci.yaml << EOF
run:
timeout: 30m
skip-files:
- "^zz_generated.*"
issues:
max-same-issues: 0
linters:
disable-all: true
enable:
- gocritic
linters-settings: # please keep this alphabetized
gocritic:
enabled-checks:
- ruleguard
settings:
ruleguard:
rules: "ruleguard_rules.go"
EOF
$ cat > rules.go << EOF
package gorules
import "github.com/quasilyte/go-ruleguard/dsl"
func netParseIP(m dsl.Matcher) {
m.Match(`net.ParseIP($_)`).Report("prefer utilnet.ParseIPSloppy()")
}
EOF
$ golangci-lint run -v
INFO [config_reader] Config search paths: [./ /home/thockin/src/go/src/k8s.io/kubernetes /home/thockin/src/go/src/k8s.io /home/thockin/src/go/src /home/thockin/src/go /home/thockin/src /home/thockin /home /]
INFO [config_reader] Used config file .golangci.yaml
INFO [lintersdb] Active 1 linters: [gocritic]
INFO [loader] Go packages loading at mode 575 (compiled_files|files|name|types_sizes|deps|exports_file|imports) took 59.476790173s
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 352.107499ms
INFO [linters context/goanalysis] analyzers took 1m46.65046061s with top 10 stages: gocritic: 1m46.65046061s
INFO [runner] processing took 2.975µs with stages: max_same_issues: 589ns, skip_dirs: 325ns, nolint: 240ns, cgo: 236ns, filename_unadjuster: 211ns, skip_files: 196ns, max_from_linter: 179ns, identifier_marker: 125ns, uniq_by_line: 123ns, exclude: 122ns, diff: 120ns, autogenerated_exclude: 118ns, path_prettifier: 113ns, max_per_file_from_linter: 44ns, source_code: 43ns, exclude-rules: 41ns, path_shortener: 39ns, sort_results: 38ns, path_prefixer: 37ns, severity-rules: 36ns
INFO [runner] linters took 21.235547543s with stages: gocritic: 21.235502731s
INFO File cache stats: 0 entries of total size 0B
INFO Memory: 812 samples, avg is 348.1MB, max is 1204.4MB
INFO Execution took 1m21.077419655s
$ gocritic check -v -enable ruleguard -@ruleguard.rules rules.go
panic: load embedded ruleguard rules: typechecker error: rules/rules.go:4:2: could not import github.com/quasilyte/go-ruleguard/dsl (can't find import: "github.com/quasilyte/go-ruleguard/dsl")
goroutine 1 [running]:
github.com/go-critic/go-critic/checkers.init.10()
/home/thockin/src/go/pkg/mod/github.com/go-critic/go-critic@v0.5.7/checkers/checkers.go:55 +0x611 If I force github.com/quasilyte/go-ruleguard/dsl to be vendored (which is a PITA, to be sure) then it works. It took us far too long to figure this out because golangci-lint doesn't complain at all. |
More simply, point the ruleguard config in .golangci.yaml to a non-existent file and watch it not fail. $ cat .golangci.yaml
run:
linters:
disable-all: true
enable:
- gocritic
linters-settings:
gocritic:
enabled-checks:
- ruleguard
settings:
ruleguard:
rules: "no-such-file.go"
$ ls -l no-such-file.go
ls: cannot access 'no-such-file.go': No such file or directory
$ golangci-lint run -v ./pkg/proxy/...
INFO [config_reader] Config search paths: [./ /home/thockin/src/go/src/k8s.io/kubernetes/pkg/proxy /home/thockin/src/go/src/k8s.io/kubernetes/pkg /home/thockin/src/go/src/k8s.io/kubernetes /home/thockin/src/go/src/k8s.io /home/thockin/src/go/src /home/thockin/src/go /home/thockin/src /home/thockin /home /]
INFO [config_reader] Used config file .golangci.yaml
INFO [lintersdb] Active 1 linters: [gocritic]
INFO [loader] Go packages loading at mode 575 (types_sizes|imports|name|exports_file|files|compiled_files|deps) took 558.241437ms
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 16.775999ms
INFO [linters context/goanalysis] analyzers took 0s with no stages
INFO [runner] processing took 3.096µs with stages: max_same_issues: 508ns, skip_dirs: 303ns, nolint: 253ns, cgo: 251ns, max_from_linter: 240ns, skip_files: 228ns, filename_unadjuster: 228ns, autogenerated_exclude: 140ns, diff: 132ns, exclude: 129ns, path_prettifier: 129ns, uniq_by_line: 121ns, identifier_marker: 108ns, source_code: 52ns, path_shortener: 50ns, exclude-rules: 50ns, sort_results: 49ns, max_per_file_from_linter: 42ns, severity-rules: 42ns, path_prefixer: 41ns
INFO [runner] linters took 117.817765ms with stages: gocritic: 117.779537ms
INFO File cache stats: 0 entries of total size 0B
INFO Memory: 8 samples, avg is 79.9MB, max is 138.3MB
INFO Execution took 697.971514ms
$ echo $?
0 |
Coming back to this, I have set up a trivial demonstration of the problem(s): https://github.com/thockin/ruleguard-multi-modules There are errors in both $ golangci-lint run
subdir/file.go:6:2: ruleguard: prefer mynet.ParseIPSloppy() (gocritic)
net.ParseIP("foobar")
^ but $ golangci-lint run ./submod/
ERRO [linters context] typechecking error: main module (example.com/root) does not contain package example.com/root/submod I know this is a problem with Go's own handling of multi-repo. Try the usual workaround: $ cd submod/; golangci-lint run; cd - >/dev/null No output. $ cd submod/; golangci-lint -v run; cd - >/dev/null
INFO [config_reader] Config search paths: [./ /home/thockin/src/go/src/github.com/thockin/ruleguard-multi-modules/submod /home/thockin/src/go/src/github.com/thockin/ruleguard-multi-modules /home/thockin/src/go/src/github.com/thockin /home/thockin/src/go/src/github.com /home/thockin/src/go/src /home/thockin/src/go /home/thockin/src /home/thockin /home /]
INFO [config_reader] Used config file ../.golangci.yaml
INFO [lintersdb] Active 1 linters: [gocritic]
INFO [loader] Go packages loading at mode 575 (compiled_files|files|name|deps|exports_file|imports|types_sizes) took 70.889764ms
INFO [runner/filename_unadjuster] Pre-built 0 adjustments in 94.267µs
INFO [linters context/goanalysis] analyzers took 0s with no stages
INFO [runner] processing took 3.34µs with stages: max_same_issues: 551ns, nolint: 523ns, skip_dirs: 257ns, cgo: 241ns, skip_files: 217ns, max_from_linter: 217ns, filename_unadjuster: 212ns, diff: 143ns, path_prettifier: 135ns, identifier_marker: 131ns, uniq_by_line: 130ns, autogenerated_exclude: 129ns, exclude: 124ns, max_per_file_from_linter: 53ns, path_shortener: 51ns, source_code: 50ns, sort_results: 49ns, severity-rules: 44ns, exclude-rules: 42ns, path_prefixer: 41ns
INFO [runner] linters took 16.305039ms with stages: gocritic: 16.238387ms
INFO File cache stats: 0 entries of total size 0B
INFO Memory: 2 samples, avg is 71.7MB, max is 71.8MB
INFO Execution took 92.837517ms It found the golangi-lint config in the parent dir, but not the rules file. But it didn't complain in any way, making me thing it actually passed, when it didn't. |
Is this reproducible with the |
I tested the 2 use cases and the problem are fixed by #2041 $ ./golangci-lint run
WARN [runner] Can't run linter gocritic: gocritic: ruleguard init error: no file matching 'no-such-file.go' $ ./golangci-lint run
subdir/file.go:6:2: ruleguard: prefer mynet.ParseIPSloppy() (gocritic)
net.ParseIP("foobar")
^ |
Excellent news! Can we get a new tag on this repo? Thanks. |
confirmed thanks! |
@thockin Excuse me, how can you fix the problem that executes
I add the golnagci-lint plugin in Goland, and every time I save the go file, it will show the above the error thx :) |
cd submod; golangci-lint run . or use go workspaces |
Welcome
Description of the problem
It seems that ruleguard demands
github.com/quasilyte/go-ruleguard/dsl
be available locally but when it's not, there's no error from golangci-lint. Running gocritic itself tells me:golangci-lint (either by hand or run under docker) says nothing at all, making me BELIEVE my rules all pass.
Version of golangci-lint
Configuration file
Go environment
Verbose output of running
Code example or link to a public repository
// add your code here
The text was updated successfully, but these errors were encountered: