-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
gocritic: invalid ruleguard rules do not cause a warning or error #4421
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
Comments
Hello, you comparing with which version of ruleguard/go-critic? |
It's because your configuration is invalid: linters:
disable-all: true
enable:
- gocritic
linters-settings: ## <-- this line is missing inside your configuration
gocritic:
enabled-checks:
- ruleguard
settings:
ruleguard:
rules: "${configDir}/gorules/*.go"
With $ git clone [email protected]:autarch/golangci-lint-ruleguard-issue.git
Cloning into 'golangci-lint-ruleguard-issue'...
remote: Enumerating objects: 11, done.
remote: Counting objects: 100% (11/11), done.
remote: Compressing objects: 100% (9/9), done.
remote: Total 11 (delta 0), reused 8 (delta 0), pack-reused 0
Receiving objects: 100% (11/11), done.
$ cd golangci-lint-ruleguard-issue
$ vim .golangci.yml
$ go mod tidy
$ golangci-lint run
gorules/rule.go:1:1: ruleguard: execution error: used Run() with an empty rule set; forgot to call Load() first? (gocritic)
package gorules
^
main.go:1:1: ruleguard: execution error: used Run() with an empty rule set; forgot to call Load() first? (gocritic)
package main
^ Don't forget to clean to cache: |
@ldez, hi |
I used the standalone
I installed it with |
This is not the same version as golangci-lint: Line 175 in 58a724a
The latest version of ruleguard is v0.4.2, I don't know the difference. As you can see in the can you try with go-critic? |
I tried with go-critic: $ gocritic check -enable ruleguard [email protected] gorules/rule.go main.go
ruleguard init error, skip gorules/rule.go: irconv error: gorules/rule.go:7: Where() can't be repeated
./main.go:1:1: ruleguard: execution error: used Run() with an empty rule set; forgot to call Load() first? |
The first line is a log: The second line is a report. golangci-lint doesn't allow linters to log, it just displays the report. This is what I see in my test: #4421 (comment) |
It's a log, and it uses the global std logger (no wrapper, no dedicated instance, etc.) so we cannot catch it. But you can use the linters:
disable-all: true
enable:
- gocritic
linters-settings:
gocritic:
enabled-checks:
- ruleguard
settings:
ruleguard:
rules: "${configDir}/gorules/rule.go"
failOn: dsl You will have this error: $ golangci-lint run
WARN [runner] Can't run linter goanalysis_metalinter: gocritic: ruleguard init error: irconv error: /home/ldez/sources/go/src/github.com/golangci/sandbox/gorules/rule.go:7: Where() can't be repeated
ERRO Running error: can't run linter goanalysis_metalinter
gocritic: ruleguard init error: irconv error: /home/ldez/sources/go/src/github.com/golangci/sandbox/gorules/rule.go:7: Where() can't be repeated |
Welcome
Description of the problem
If a ruleguard rule is invalid (but syntactically correct), it seems like
golangci-lint
does not error out. Here's an example rule:If this is run against
ruleguard
directly, it will complain:ruleguard: load rules: parse rules file: irconv error: ./gorules/rule.go:7: Where() can't be repeated
However, if run via
golangci-lint run
, there is no error and the process exits 0.Note that this is not the same as #1565, which is about syntax errors in the rules. In this case, the rules are valid Go but the use of the
dsl
API is not valid.Version of golangci-lint
Configuration
Go environment
Verbose output of running
A minimal reproducible example or link to a public repository
https://github.com/autarch/golangci-lint-ruleguard-issue
Validation
The text was updated successfully, but these errors were encountered: