-
Notifications
You must be signed in to change notification settings - Fork 17
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
Extend allowed with some std funcs and external via funcopts #69
Conversation
- encoding/csv - encoding/json - mime/multipart
Thanks! This is really cool to have :) Do you already have thought about how adding custom allowed errors/functions would work in practice? Most people use errorlint as part of golangci-lint I think. Did you benchmark the map performance improvement? |
I'm trying to add errorlint at company monorepo, and we use here custom analyzer instead of golangci-lint for PRs stylecheck. So there will be at least ~500 (go dev) users of custom allowed errors/functions :) Benchmarks (I'll push commit with it in few minutes, it seems better to have it): Code
func Benchmark_isAllowedErrAndFunc(b *testing.B) {
var benchCases = []struct {
desc string
err string
fun string
}{
{
desc: "empty",
err: "",
fun: "",
},
{
desc: "short",
err: "x",
fun: "x",
},
{
desc: "long not existed",
// should pass strings.HasPrefix length check, 30 symbols here
err: "xxxx_xxxx_yyyy_yyyy_zzzz_zzzz_",
fun: "xxxx_xxxx_yyyy_yyyy_zzzz_zzzz_",
},
{
desc: "existed, not wildcard",
err: "io.EOF",
fun: "(io.Reader).Read",
},
{
desc: "existed, wildcard",
err: "golang.org/x/sys/unix.Exx",
fun: "golang.org/x/sys/unix.xxx",
},
}
for _, bb := range benchCases {
b.Run(bb.desc, func(b *testing.B) {
err, fun := bb.err, bb.fun
b.ResetTimer()
for i := 0; i < b.N; i++ {
isAllowedErrAndFunc(err, fun)
}
})
}
} Old
New
I've reorder exact match and wildcards checks and old order with map seems run faster, but i'm not sure that wildcard pairs list will not raise
|
Awesome, nice work! |
Add some missed stdlib functions
Speed up allowed check using maps
Extend NewAnalyzer with funcopts to add custom allowed func-err pairs