Analysing code quality
Linters and Static Analysis
Hello!
Weverton Timoteo
@wevtimoteo
“
Any fool can write code that a
computer can understand.
Good programmers write code that
humans can understand.
– Martin Fowler
How Do You Define
“Good Code” ?
maintainability?
Efficiency Modularity Elegance
What's the first thing that comes to your
mind?
Proper design
decision
Error rate
Comprehensibility
Reviewability
- Code Complete, Steve McConnelDebugging
External quality
Modifiability
Development time
You write readable code because it helps
other people to read your code
“
Simplicity
is it about the number of lines?
Readability
comments, conventions, naming
Modularity
its all about reusability
Layering
attention to the boundaries of each layer
Design
plan before build
Efficiency
too many connections?
Elegance
solve problems with proper solutions
Clarity
do you really know what you have to do?
Balance
is a tool that analyzes source code to flag
programming errors, bugs, stylistic errors,
and suspicious constructs
- Wikipedia
What is a linter?
“
● gofmt - Must have for every project
● goimports - Additionally to gofmt, checks unused imports
● unindent - Report code that is unnecessarily indented
Code Formatting
gofmt -s (Simplify)
goimports
● abcgo - ABC metrics for Go source code.
● gocyclo - Computes and checks the cyclomatic
complexity of functions.
● splint - It finds any functions that are too long or have too
many parameters or results.
Code Complexity
ABC Metrics - Calculate Score
● Assignment count when:
=, *=, /=, %=, +=, <<=, >>=,
&=, ^=
++, --
● Branch count when:
Function call
● Condition count when:
<, >, <=, >=, ==, !=
else, case
ABC Metrics (abcgo)
● GoLint - Golint is a linter for Go source code
● go-namecheck - helps you to maintain variable/field
naming conventions inside your project
● revive - Drop-in replacement of golint
● lll - Line length linter, used to enforce line length in files
Style and Patterns Checking
golint
Revive
● govet - checks correctness
● badtime - Badtime is a Golang linter that detects
inappropriate usage of the time.Time struct.
● safesql - Static analysis tool for Golang that protects
against SQL injections.
Bugs
govet
curiosity “time”
Mon Jan 2 15:04:05 MST 2006
which is Unix time 1136239445 and Since MST is GMT-0700
01/02 03:04:05PM '06 -0700
1234567
● Performance
● Unused code
● Reports
● Outdated packages
● Code without tests (no coverage)
● Magic number detector
What else?
Thanks!Any questions?
Which linters are you using?
Tell me! @wevtimoteo
<we’re hiring>
References
● Code Complete: A Practical Handbook of Software Construction
● Effective Go
● golang/lint Repository
● Ebert: the code review assistant for your organization
● Awesome Go Linters

Floripa Gophers - Analysing Code Quality (Linters and Static Analysis)