Go-criticStatic analysis in Goby Oleg Kovalov
View Slide
Why static analysis?- Better code- Human friendly- Optimal codeGood examples:- golint- go vet- gometalinter- golangci-lint- go-critic
Project status- 58 checks implemented + 54 in current todo- Optimistic merging (10+ contributors)
Types of analysis- Diagnostics- Suspicious code- Code style- Can be more readable- Performance- Can be faster
Diagnostic check: nilValReturn
Code style check: namedConst
Performance check: indexAlloc
Go-toolsmith- astfmt - Print ast.Node with %s- astp - Predicates for AST nodes- astcopy - Deep copy for AST nodes- astequal - Deep equal for AST nodes- astinfo - Useful AST information- strparse - Parse string to ASTClickable link: github.com/go-toolsmith
Demo: problem description- strings.Index("", "i")vs- strings.IndexByte("", 'i')BenchmarkIndex-4 100000000 19.3 ns/opBenchmarkIndexByte-4 100000000 16.4 ns/op
Make a new rule- go get go-critic- make new - adding code examples (positive & negative)- copy-pasting coding- adding docs- git push- ....- PROFITCode: https://bit.ly/2NDbOtV
TrophiesOur trophies collection:go-critic.github.io/trophies.html
Thank you- github.com/go-critic/go-critic- github.com/go-toolsmith- twitter.com/oleg_kovalov- github.com/cristaloleg