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
Writing Codemods with jscodeshift
Search
Matija Marohnić
February 21, 2018
Programming
61
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Writing Codemods with jscodeshift
Matija Marohnić
February 21, 2018
More Decks by Matija Marohnić
See All by Matija Marohnić
oxlint & oxfmt: linting and formatting from the future
silvenon
0
30
Goodbye jsdom/happy-dom, hello Vitest Browser Mode!
silvenon
0
23
Introduction to Remix
silvenon
0
160
Cypress vs. Playwright
silvenon
0
170
Studying Strapi: an open source head headless CMS
silvenon
0
57
CSS Specificity
silvenon
0
64
Make your JavaScript projects more accessible to newcomers
silvenon
0
92
React Hooks
silvenon
0
95
PostCSS
silvenon
0
65
Other Decks in Programming
See All in Programming
Honoでのサプライチェーン侵害対策 〜 3つのライブラリに学ぶ
yusukebe
7
1.4k
Language Server 使ってる? 〜VSCode と Zed の場合〜 / Are you using a Language Server? ~For VS Code and Zed~
handlename
0
800
Skillsは効率化、Agentsは"自分の拡張"——Builder時代のエージェント編成(CC Night 2026)
wemra
1
160
AI 輔助遺留系統現代化的經驗分享
jame2408
1
970
Lemonade + Foundry Toolkit でお手軽アプリ開発
seosoft
1
370
並列実装の現場、2ヶ月間実務でAIを使い倒したAIもPCも私も限界が近い
ming_ayami
0
130
Creating Composable Callables in Contemporary C++
rollbear
0
160
jQueryをバージョンアップする前に使いたいjQuery Migrate
matsuo_atsushi
0
580
フロントエンドとバックエンドで「1文字」を揃えよう
youkidearitai
PRO
0
740
AIで効率化できた業務・日常
ochtum
0
140
Dataformのリポジトリを立ち上げるときにまずやること / dataform-day0-2026
snhryt
0
180
なぜ型を書くのか? TSKaigi2026で改めて考える #tskaigi_smarthr
kajitack
0
140
Featured
See All Featured
The AI Search Optimization Roadmap by Aleyda Solis
aleyda
1
5.9k
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
340
実際に使うSQLの書き方 徹底解説 / pgcon21j-tutorial
soudai
PRO
201
75k
Building AI with AI
inesmontani
PRO
1
1.1k
For a Future-Friendly Web
brad_frost
183
10k
Mind Mapping
helmedeiros
PRO
1
260
Joys of Absence: A Defence of Solitary Play
codingconduct
1
400
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
1
240
Deep Space Network (abreviated)
tonyrice
0
210
HDC tutorial
michielstock
2
720
Bioeconomy Workshop: Dr. Julius Ecuru, Opportunities for a Bioeconomy in West Africa
akademiya2063
PRO
1
150
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
Transcript
Writing Codemods with jscodeshift
Matija Marohnić @silvenon
Refactoring • changing dependencies • improving the codebase
› npm outdated A New Project
autoprefixer 6.7.7 6.7.7 8.0.0 your-project babel-eslint 8.0.0 8.2.1 8.2.1 your-project
css-loader 0.26.4 0.26.4 0.28.9 your-project dotenv 4.0.0 4.0.0 5.0.0 your-project eslint-plugin-react 7.4.0 7.6.1 7.6.1 your-project Day One
autoprefixer 6.7.7 6.7.7 8.0.0 your-project babel-eslint 8.0.0 8.2.1 8.2.1 your-project
css-loader 0.26.4 0.26.4 0.28.9 your-project dotenv 4.0.0 4.0.0 5.0.0 your-project eslint-plugin-react 7.4.0 7.6.1 7.6.1 your-project file-loader 0.10.1 0.10.1 1.1.6 your-project flow-bin 0.61.0 0.61.0 0.65.0 your-project flow-typed 2.2.3 2.3.0 2.3.0 your-project jest 22.0.1 22.3.0 22.3.0 your-project lodash 4.17.4 4.17.5 4.17.5 your-project nock 9.1.5 9.1.6 9.1.6 your-project node-sass 4.5.3 4.7.2 4.7.2 your-project nodemon 1.14.11 1.14.12 1.14.12 your-project postcss-loader 1.3.3 1.3.3 2.1.0 your-project query-string 4.3.4 4.3.4 5.1.0 your-project react-dates 16.2.1 16.3.0 16.3.0 your-project react-draggable 3.0.3 3.0.5 3.0.5 your-project react-router 3.0.5 3.2.0 4.2.0 your-project react-virtualized 9.12.0 9.18.5 9.18.5 your-project redux-form 7.0.4 7.2.3 7.2.3 your-project style-loader 0.13.2 0.13.2 0.20.1 your-project url-loader 0.5.9 0.5.9 0.6.2 your-project Day Three
Let's just say that we update things a lot!
const styleSheet = () => ({ toolbar: { margin: [10,
"auto"] } }) Example
const styleSheet = () => ({ toolbar: { margin: "10px
auto" } }) Example
const styleSheet = theme => ({ toolbar: { margin: [10,
theme.spacing.unit] } }) Example
const styleSheet = theme => ({ toolbar: { margin: `10px
${theme.spacing.unit}px` } }) Example
Search & Replace /!/g It needs to understand the syntax
AST • Abstract Syntax Tree • represents code structure •
source vs desired result
Codemods • scripts for refactoring • use AST • easily
testable
Codemods › jscodeshift -t codemod.js <target> <target> can be a
file or folder
Pros • faster iterations of ideas • up-to-date with dependencies
• work on multiple codebases
cpojer/js-codemod • collection of codemods to transform code to next
generation JS
cpojer/js-codemod •arrow-function.js •no-vars.js •template-literals.js
reactjs/react-codemod • collection of codemods that help update React APIs
reactjs/react-codemod •pure-component.js •error-boundaries.js •findDOMNode.js
Let's See a Codemod for our styleSheet Example "
Cons • many AST variations • lacking documentation • big
learning curve
Photo by Alex Boyd on Unsplash Be Patient, Go to
Sleep and Try Again Tomorrow