Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Speaker Deck
PRO
Sign in
Sign up for free
Make Linting Great Again (Long version)
Andrey Okonetchnikov
January 25, 2018
Programming
0
29
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
120
A Common Design Language
okonet
2
930
Modular CSS v2 (CSS-in-JS edition)
okonet
3
760
Make Linting Great Again
okonet
0
140
Modular CSS — Agent Conf '17 Edition
okonet
3
280
Modular CSS
okonet
3
230
JavaScript для насыщенных пользовательских интерфейсов
okonet
0
60
Профессия "Front-end архитектор"
okonet
0
81
Other Decks in Programming
See All in Programming
10歳の minne から、これから長く続くプロダクトを作るすべての人へ
tsumichan
9
3.7k
Git操作編
smt7174
2
250
How to start contributing to Kubernetes Projects
ydfu
0
140
回帰分析ではlm()ではなくestimatr::lm_robust()を使おう / TokyoR100
dropout009
0
4.5k
アジャイルで不確実性に向き合うための開発タスクの切り方
tanden
4
1.1k
Untangling Coroutine Testing (Droidcon Berlin 2022)
zsmb
2
490
Edge Side Frontend という新領域
mizchi
23
10k
リーダブルテストコード / #vstat
jnchito
48
36k
フロントエンドエンジニアが変える現場のモデリング意識/modeling-awareness-changed-by-front-end-engineers
uggds
32
13k
Lookerとdbtの共存
ttccddtoki
0
640
ExplainableAIの概要とAmazon SageMaker Clarifyでの実装例
hacarus
0
100
Computer Vision Seminar 1/コンピュータビジョンセミナーvol.1 OpenCV活用
fixstars
0
170
Featured
See All Featured
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
316
19k
Stop Working from a Prison Cell
hatefulcrawdad
262
17k
Ruby is Unlike a Banana
tanoku
91
9.3k
Code Reviewing Like a Champion
maltzj
506
37k
Making Projects Easy
brettharned
98
4.4k
What the flash - Photography Introduction
edds
62
10k
What’s in a name? Adding method to the madness
productmarketing
11
1.6k
Put a Button on it: Removing Barriers to Going Fast.
kastner
56
2.3k
Documentation Writing (for coders)
carmenintech
48
2.6k
Adopting Sorbet at Scale
ufuk
63
7.6k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
7
1.1k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
236
1.1M
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