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
80
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
47
Goodbye jsdom/happy-dom, hello Vitest Browser Mode!
silvenon
0
35
Introduction to Remix
silvenon
0
180
Cypress vs. Playwright
silvenon
0
190
Studying Strapi: an open source head headless CMS
silvenon
0
67
CSS Specificity
silvenon
0
75
Make your JavaScript projects more accessible to newcomers
silvenon
0
100
React Hooks
silvenon
0
100
PostCSS
silvenon
0
72
Other Decks in Programming
See All in Programming
パズルゲームの作り方 / how to make puzzle games
kaityo256
PRO
2
280
UnityでSystem.Net.WebSocketsなWebSocketサーバが動かないのでUnity Monoのコードを覗いてみた / about implementing websocket server with unity mono
drumath2237
1
570
自サークルのIdPからログアウトできるようになるまで
taiseiue
1
130
AWSに止められる覚悟してますか?
morizo_1984
2
520
気持ちぃ〜角丸 Squircle
ryu1013
0
160
すこし踏み込む CancellationToken
htkym
2
1.7k
Agents on Rails - Rails at Scale 2026
irinanazarova
0
520
AI時代のコードレビューは人に向けるな、仕組みに向けろ
texmeijin
5
3.6k
Java 27新機能 / Java 27 new features
kishida
2
210
Workers Cache を知る
syumai
0
350
IBM Bob Dojo #1 仕様駆動開発入門
oniak3ibm
PRO
0
360
Augmenting AI with the Power of Jakarta EE
ivargrimstad
0
520
Featured
See All Featured
The Cost Of JavaScript in 2023
addyosmani
55
10k
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
610
How to build a perfect <img>
jonoalderson
1
6.1k
Noah Learner - AI + Me: how we built a GSC Bulk Export data pipeline
techseoconnect
PRO
0
450
The innovator’s Mindset - Leading Through an Era of Exponential Change - McGill University 2025
jdejongh
PRO
1
370
The Invisible Side of Design
smashingmag
301
52k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.9k
Ten Tips & Tricks for a 🌱 transition
stuffmc
1
260
Testing 201, or: Great Expectations
jmmastey
46
8.3k
[RailsConf 2023] Rails as a piece of cake
palkan
59
7.1k
What’s in a name? Adding method to the madness
productmarketing
PRO
24
4.2k
Become a Pro
speakerdeck
PRO
31
6.3k
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