Skip to content
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

skip experimental tag by default for user defined rules #1217

Merged
merged 1 commit into from Apr 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions checkers/ruleguard_checker.go
Expand Up @@ -159,6 +159,10 @@ func newRuleguardChecker(info *linter.CheckerInfo, ctx *linter.CheckerContext) (
enabledGroups[g] = true
}
}

if !enabledTags["experimental"] {
disabledTags["experimental"] = true
}
ruleguardDebug := os.Getenv("GOCRITIC_RULEGUARD_DEBUG") != ""

inEnabledTags := func(g *ruleguard.GoRuleGroup) bool {
Expand Down
8 changes: 6 additions & 2 deletions checkers/testdata/_integration/ruleguard/f1.go
@@ -1,12 +1,16 @@
package foo

import "fmt"
import (
"fmt"
"regexp"
)

type myError error

func _() {
var s1, s2 string
var _ = fmt.Sprintf("%s%s", s1, s2)
r, _ := regexp.MatchString(`^\s`, fmt.Sprintf("%s%s", s1, s2))
println(r)
}

func _() {
Expand Down
6 changes: 3 additions & 3 deletions checkers/testdata/_integration/ruleguard/linttest.golden
@@ -1,4 +1,4 @@
exit status 1
./f1.go:5:1: ruleguard: error as an underlying type is probably a mistake
./f1.go:9:10: ruleguard: suggestion: s1+s2
./f1.go:25:6: ruleguard: use errors.New(k()) or fmt.Errorf("%s", k()) instead
./f1.go:8:1: ruleguard: error as an underlying type is probably a mistake
./f1.go:12:36: ruleguard: suggestion: s1+s2
./f1.go:29:6: ruleguard: use errors.New(k()) or fmt.Errorf("%s", k()) instead
2 changes: 1 addition & 1 deletion checkers/testdata/_integration/ruleguard/linttest.golden2
@@ -1,2 +1,2 @@
exit status 1
./f1.go:25:6: ruleguard: use errors.New(k()) or fmt.Errorf("%s", k()) instead
./f1.go:29:6: ruleguard: use errors.New(k()) or fmt.Errorf("%s", k()) instead
5 changes: 3 additions & 2 deletions checkers/testdata/_integration/ruleguard/linttest.golden3
@@ -1,3 +1,4 @@
exit status 1
./f1.go:14:2: ruleguard: may be simplified to one if
./f1.go:25:6: ruleguard: use errors.New(k()) or fmt.Errorf("%s", k()) instead
./f1.go:18:2: ruleguard: may be simplified to one if
./f1.go:12:10: ruleguard: regexp compilation should be avoided on the hot paths
./f1.go:29:6: ruleguard: use errors.New(k()) or fmt.Errorf("%s", k()) instead
5 changes: 5 additions & 0 deletions checkers/testdata/_integration/ruleguard/linttest.golden4
@@ -0,0 +1,5 @@
exit status 1
./f1.go:8:1: ruleguard: error as an underlying type is probably a mistake
./f1.go:18:2: ruleguard: may be simplified to one if
./f1.go:12:36: ruleguard: suggestion: s1+s2
./f1.go:29:6: ruleguard: use errors.New(k()) or fmt.Errorf("%s", k()) instead
3 changes: 2 additions & 1 deletion checkers/testdata/_integration/ruleguard/linttest.params
@@ -1,3 +1,4 @@
check -@ruleguard.rules ./rules.go -enable ruleguard -@ruleguard.disable=#test ./... | linttest.golden
check -@ruleguard.rules ./rules.go -enable ruleguard -@ruleguard.enable=#style -@ruleguard.disable=#test ./... | linttest.golden2
check -@ruleguard.rules ./rules.go -enable ruleguard -@ruleguard.enable=#style,#test ./... | linttest.golden3
check -@ruleguard.rules ./rules.go -enable ruleguard -@ruleguard.enable=#style,#test,#experimental ./... | linttest.golden3
check -@ruleguard.rules ./rules.go -enable ruleguard ./... | linttest.golden4
8 changes: 8 additions & 0 deletions checkers/testdata/_integration/ruleguard/rules.go
Expand Up @@ -29,3 +29,11 @@ func dynamicFmtString(m dsl.Matcher) {
Suggest("errors.New($f($args))").
Report(`use errors.New($f($args)) or fmt.Errorf("%s", $f($args)) instead`)
}

//doc:tags experimental
func regexpCompile(m dsl.Matcher) {
m.Match(`regexp.Match($*_)`,
`regexp.MatchString($*_)`,
`regexp.MatchReader($*_)`,
).Report(`regexp compilation should be avoided on the hot paths`)
}