Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Make Linting Great Again (Long version)
Search
Andrey Okonetchnikov
January 25, 2018
Programming
0
66
Make Linting Great Again (Long version)
Presented at Agent Conf 2018
Andrey Okonetchnikov
January 25, 2018
Tweet
Share
More Decks by Andrey Okonetchnikov
See All by Andrey Okonetchnikov
Component-Driven Design Systems Workshop
okonet
0
200
A Common Design Language
okonet
2
1.5k
Modular CSS v2 (CSS-in-JS edition)
okonet
3
1k
Make Linting Great Again
okonet
0
160
Modular CSS — Agent Conf '17 Edition
okonet
3
330
Modular CSS
okonet
3
260
JavaScript для насыщенных пользовательских интерфейсов
okonet
0
80
Профессия "Front-end архитектор"
okonet
0
130
Other Decks in Programming
See All in Programming
Cloudflare MCP ServerでClaude Desktop からWeb APIを構築
kutakutat
1
550
rails statsで大解剖 🔍 “B/43流” のRailsの育て方を歴史とともに振り返ります
shoheimitani
2
940
Keeping it Ruby: Why Your Product Needs a Ruby SDK - RubyWorld 2024
envek
0
190
モバイルアプリにおける自動テストの導入戦略
ostk0069
0
110
コンテナをたくさん詰め込んだシステムとランタイムの変化
makihiro
1
140
快速入門可觀測性
blueswen
0
380
テストコード文化を0から作り、変化し続けた組織
kazatohiei
2
1.5k
毎日13時間もかかるバッチ処理をたった3日で60%短縮するためにやったこと
sho_ssk_
1
180
責務を分離するための例外設計 - PHPカンファレンス 2024
kajitack
6
1.5k
クリエイティブコーディングとRuby学習 / Creative Coding and Learning Ruby
chobishiba
0
3.9k
短期間での新規プロダクト開発における「コスパの良い」Goのテスト戦略」 / kamakura.go
n3xem
2
170
[JAWS-UG横浜 #76] イケてるアップデートを宇宙いち早く紹介するよ!
maroon1st
0
480
Featured
See All Featured
Mobile First: as difficult as doing things right
swwweet
222
9k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
132
33k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
32
2.7k
Building Adaptive Systems
keathley
38
2.3k
Into the Great Unknown - MozCon
thekraken
33
1.5k
Making the Leap to Tech Lead
cromwellryan
133
9k
Code Reviewing Like a Champion
maltzj
520
39k
Site-Speed That Sticks
csswizardry
2
190
Gamification - CAS2011
davidbonilla
80
5.1k
The Myth of the Modular Monolith - Day 2 Keynote - Rails World 2024
eileencodes
17
2.3k
Code Review Best Practice
trishagee
65
17k
Intergalactic Javascript Robots from Outer Space
tanoku
270
27k
Transcript
Make Linting Great Again with @okonetchnikov
None
https://reason-conf.com
What the #$&% is lint?!
–Wikipedia “lint or a linter is any tool that flags
suspicious usage in software written in any computer language.”
–me “linter is a tool that finds stupid bugs.”
None
These things here :(
None
None
None
How to fix that?
Lint all the things!
Stylelint JSON Lint
Why lint?
– http://www.prweb.com/releases/2013/1/prweb10298185.htm “On average, software developers spend 50% of their
time finding and fixing bugs.”
– http://www.prweb.com/releases/2013/1/prweb10298185.htm “…this inefficiency is estimated to cost the global
economy $312 billion per year.”
None
In reality, though…
– http://www.prweb.com/releases/2013/1/prweb10298185.htm “On average, software developers spend 50% of their
time finding and fixing bugs.”
– me “On average, software developers spend 50% of their
time discussing code style.”
None
You don’t need to uglify your code if it’s already
ugly!
How to fix that?
One code style to rule them all!
None
None
Using linters & formatters leads to 1. Fewer (stupid) bugs
2. Better readability => less time in code reviews 3. But it can slow you down… :(
—Slow down?! —We’re not doing that then!
My typical day…
None
None
10 minutes later…
None
None
None
None
None
None
None
None
None
Raise your hand if this sound familiar to you ✋
None
None
None
428.689
None
2.844.799
– Everyone “I wish I could lint before committing the
changes to the repository”
git hooks
None
git hooks are 1. Hard to setup 2. Hard to
manage 3. Hard to share across the team
npm install -D husky yarn add --dev husky
{ "scripts": { "precommit": "eslint ." } }
None
None
Thanks husky! 1. Hard to setup 2. Hard to manage
3. Hard to share across the team
…but linting the whole project 1. Can be quite slow
2. Will display irrelevant results
None
What if we could run linters only on files we’re
about to commit?
Meet lint-staged!
npm install -D lint-staged yarn add --dev lint-staged
{ "scripts": { "precommit": "lint-staged" } }
{ "scripts": { "precommit": "lint-staged" }, "lint-staged": { "*.js": "eslint"
} }
None
git hooks are 1. Hard to setup 2. Hard to
manage 3. Hard to share across the team 4. Very slow 5. Displaying irrelevant results A WES OME!
There is more!
Automatically fix lint errors
{ "lint-staged": { "*.js": "eslint" } }
{ "lint-staged": { "*.js": [ "eslint --fix", "git add" ]
} }
Automatically reformat your code
None
{ "lint-staged": { "*.js": [ "eslint --fix", "git add" ]
} }
{ "lint-staged": { "*.js": [ "prettier --write", "git add" ]
} }
None
lint-staged and prettier being used in create-react-app
lint-staged and prettier being used in Babel!
How does it work?
#!/bin/bash executable=$(npm bin)/staged-files linter_name="eslint" linter_path=$(npm bin)/eslint lint_extensions="**/*.@(js|jsx)" if [[ -f
"${linter_path}" ]]; then echo "Running ${linter_name} on git staged files: $ {lint_extensions}" ${executable} "${lint_extensions}" -- ${linter_path} else echo "Could not find ${linter_name} at $ {linter_path}. Is it installed?" echo "" echo "Try running:" echo "npm install --save-dev ${linter_name}" fi
None
#!/bin/bash executable=$(npm bin)/staged-files linter_name="stylelint" linter_path=$(npm bin)/stylelint lint_extensions="**/*.@(css|scss|less|styl)" if [[ -f
"${linter_path}" ]]; then echo "Running ${linter_name} on git staged files: $ {lint_extensions}" ${executable} "${lint_extensions}" -- ${linter_path} else echo "Could not find ${linter_name} at $ {linter_path}. Is it installed?" echo "" echo "Try running:" echo "npm install --save-dev ${linter_name}" fi
#!/bin/bash executable=$(npm bin)/staged-files linter_name="flow" linter_path=$(npm bin)/flow lint_extensions="**/*.@(js|jsx)" if [[ -f
"${linter_path}" ]]; then echo "Running ${linter_name} on git staged files: $ {lint_extensions}" ${executable} "${lint_extensions}" -- ${linter_path} else echo "Could not find ${linter_name} at $ {linter_path}. Is it installed?" echo "" echo "Try running:" echo "npm install ${linter_name}-bin" fi
#!/bin/bash executable=$(npm bin)/staged-files linter_name="jscs" linter_path=$(npm bin)/jscs lint_extensions="**/*.@(js|jsx)" if [[ -f
"${linter_path}" ]]; then echo "Running ${linter_name} on git staged files: $ {lint_extensions}" ${executable} "${lint_extensions}" -- ${linter_path} else echo "Could not find ${linter_name} at $ {linter_path}. Is it installed?" echo "" echo "Try running:" echo "npm install --save-dev ${linter_name}" fi
DRY
Present
lint-staged is a tool that • Can run any task
• Easy to install via npm • Easy to distribute across the team (.lintstagedrc) • Easy to use (DX!)
Future?
None
None
None
None
None
None
Open Source = ❤
https://github.com/okonet/lint-staged
Maintainers ❤
None
Recap
None
Please solve real problems!
Thank You!
Andrey Okonetchnikov @okonetchnikov http://okonet.ru https://github.com/okonet