Upgrade to Pro — share decks privately, control downloads, hide ads and more …

go-critic

Oleg Kovalov
September 25, 2018

 go-critic

Oleg Kovalov

September 25, 2018
Tweet

More Decks by Oleg Kovalov

Other Decks in Programming

Transcript

  1. Go-critic
    Static analysis in Go
    by Oleg Kovalov

    View Slide

  2. Why static analysis?
    - Better code
    - Human friendly
    - Optimal code
    Good examples:
    - golint
    - go vet
    - gometalinter
    - golangci-lint
    - go-critic

    View Slide

  3. Project status
    - 58 checks implemented + 54 in current todo
    - Optimistic merging (10+ contributors)

    View Slide

  4. Types of analysis
    - Diagnostics
    - Suspicious code
    - Code style
    - Can be more readable
    - Performance
    - Can be faster

    View Slide

  5. Diagnostic check: nilValReturn

    View Slide

  6. Code style check: namedConst

    View Slide

  7. Performance check: indexAlloc

    View Slide

  8. 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 AST
    Clickable link: github.com/go-toolsmith

    View Slide

  9. Demo: problem description
    - strings.Index("", "i")
    vs
    - strings.IndexByte("", 'i')
    BenchmarkIndex-4 100000000 19.3 ns/op
    BenchmarkIndexByte-4 100000000 16.4 ns/op

    View Slide

  10. Make a new rule
    - go get go-critic
    - make new
    - adding code examples (positive & negative)
    - copy-pasting coding
    - adding docs
    - git push
    - ....
    - PROFIT
    Code: https://bit.ly/2NDbOtV

    View Slide

  11. Trophies
    Our trophies collection:
    go-critic.github.io/trophies.html

    View Slide

  12. Thank you
    - github.com/go-critic/go-critic
    - github.com/go-toolsmith
    - twitter.com/oleg_kovalov
    - github.com/cristaloleg

    View Slide