LINTING LEGACY CODE
INTEGRATING LINTERS INTO OUR WORKFLOW
Ivan Tse, Paperless Post
Twitter: @ivan_tse
GitHub: @ivantsepp
Slide 2
Slide 2 text
OUTLINE
What are linters?
Why should we use them?
The challenges
Possible approaches
Slide 3
Slide 3 text
A linter is a tool that analyzes code to flag suspicious
behavior
Slide 4
Slide 4 text
No content
Slide 5
Slide 5 text
WHY SHOULD WE USE LINTERS
Can catch bugs or mistakes
Enforceable style guides
Slide 6
Slide 6 text
“Programs are meant to be read by
humans and only incidentally for
computers to execute.”
— H. Abelson and G. Sussman
Slide 7
Slide 7 text
No content
Slide 8
Slide 8 text
No content
Slide 9
Slide 9 text
“Any styleguide will become more valuable as more of its
enforcement becomes more automated.”
http://davidtheclark.com/scss-lint-styleguide/
Slide 10
Slide 10 text
LINTERS ARE AUTOMATED CODE REVIEWS
Slide 11
Slide 11 text
No content
Slide 12
Slide 12 text
AVAILABLE LINTERS:
Ruby: Rubocop (there are rules for Rails and even Rspec)
Haml: haml-lint
Scss: Scss-lint
Javascript: JSLint, JSHint, ESLint
React: ESLint-plugin-React
Chef: Foodcritic
Slide 13
Slide 13 text
CHALLENGES FOR INTRODUCING LINTERS
Legacy codebase
False positives
Very opinionated
Integration
Slide 14
Slide 14 text
HOUND
Hound comments on style violations in GitHub pull
requests, allowing you and your team to better review and
maintain a clean codebase.
Slide 15
Slide 15 text
CODE CLIMATE
The Code Climate Platform is the first open, extensible
platform for all types of static analysis.
Slide 16
Slide 16 text
THE "LEGACY CODEBASE" PROBLEM
LINT INCREMENTALLY
Slide 17
Slide 17 text
HOW TO LINT CHANGES
Slide 18
Slide 18 text
No content
Slide 19
Slide 19 text
No content
Slide 20
Slide 20 text
Run the linter on the file before and after the changes.
Report any new warnings
Slide 21
Slide 21 text
No content
Slide 22
Slide 22 text
File is eventually left in an inconsistent state
Slide 23
Slide 23 text
No content
Slide 24
Slide 24 text
No content
Slide 25
Slide 25 text
No content
Slide 26
Slide 26 text
THE "VERY OPINIONATED"
PROBLEM
STYLE GUIDE REPOSITORY
Slide 27
Slide 27 text
No content
Slide 28
Slide 28 text
THE "INTEGRATION" PROBLEM
Run multiple linters including custom rules
(ex. `named_scope`)
Pass/Fail CI builds
Slide 29
Slide 29 text
THE "FALSE POSITIVE" PROBLEM
Ignore rules
Slide 30
Slide 30 text
RESULTS
Slide 31
Slide 31 text
No content
Slide 32
Slide 32 text
Missing semicolon. (semi)
`0px` should be written without units as `0`
Properties should be ordered ...