Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Writing Codemods with jscodeshift
Search
Matija Marohnić
February 21, 2018
Programming
76
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
41
Goodbye jsdom/happy-dom, hello Vitest Browser Mode!
silvenon
0
32
Introduction to Remix
silvenon
0
170
Cypress vs. Playwright
silvenon
0
190
Studying Strapi: an open source head headless CMS
silvenon
0
63
CSS Specificity
silvenon
0
72
Make your JavaScript projects more accessible to newcomers
silvenon
0
99
React Hooks
silvenon
0
100
PostCSS
silvenon
0
67
Other Decks in Programming
See All in Programming
SREの越境 / SRE Collaboration
y0hgi
2
230
大喜利で理解するLLM as a Judge / Understanding LLM-as-a-Judge through Ogiri
rockname
0
130
Heart of Swift Concurrency
koher
0
890
wkhtmltopdfの次どうするか問題2026
willnet
2
1.4k
選挙速報を多くのユーザーへ 届ける Live Activities 設計
hamayokokuririn
0
150
仕様駆動開発による爆速プロダクト開発 / Bakusoku Spec Driven Development
kobakei
0
120
モジュールの視点からSwiftを読み解く #iosdc
s_shimotori
0
180
WebMCP Challenge に星空観察アプリで参加した話
okajun35
0
180
『寄り添うラジオ』をAIで作る 体験価値から逆算した、会話しないUXと品質設計
theoriatec2024
3
180
数年滞っていたダークモード対応をおよそ2週間で完了させる
chigichan24
0
720
AIエージェント時代のコードレビューを設計する
nogu66
6
2.7k
新卒PdEのリアル
ryu1013
1
500
Featured
See All Featured
End of SEO as We Know It (SMX Advanced Version)
ipullrank
3
4.4k
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
69
65k
The State of eCommerce SEO: How to Win in Today's Products SERPs - #SEOweek
aleyda
2
12k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.9k
It's Worth the Effort
3n
188
29k
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
280
Taking LLMs out of the black box: A practical guide to human-in-the-loop distillation
inesmontani
PRO
3
2.4k
For a Future-Friendly Web
brad_frost
183
10k
コードの90%をAIが書く世界で何が待っているのか / What awaits us in a world where 90% of the code is written by AI
rkaga
63
46k
Deep Space Network (abreviated)
tonyrice
0
310
Navigating Team Friction
lara
192
16k
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