Skip to content

Instantly share code, notes, and snippets.

View perjansson's full-sized avatar

Per Jansson perjansson

View GitHub Profile
var message = 'The best car is ' + randomCar
// becomes
var message = `The best car is ${randomCar}`
var state = Object.assign({}, state.history, selectedCar.id)
// becomes
var state = { ...state.history, ...selectedCar.id }
var state = { selectedCar: selectedCar }
// becomes
var state = { selectedCar }
cars: [
'Volvo',
'BMW',
'Tesla',
'Lada'
]
// becomes
cars: [
var CarList = React.createClass({
getInitialState: function() { }
setSelectedCar: function(selectedCar) { }
...
// becomes
class CarList extends React.Component {
state = { }
setSelectedCar = selectedCar => { }
const transformer = (file, api) => {
/* get the jscodeshift helper */
const j = api.jscodeshift;
/* create a js object representation of your source code */
const root = j(file.source);
return root
.find(/* grab the code you want to update */)
.forEach(/* do something to it */)
const transformer = (file, api) => {
const j = api.jscodeshift;
const root = j(file.source);
const multiLineArrays = path => {
const { loc } = path.node;
return loc.start.line < loc.end.line;
}
return root