This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 */) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var CarList = React.createClass({ | |
| getInitialState: function() { } | |
| setSelectedCar: function(selectedCar) { } | |
| ... | |
| // becomes | |
| class CarList extends React.Component { | |
| state = { } | |
| setSelectedCar = selectedCar => { } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| cars: [ | |
| 'Volvo', | |
| 'BMW', | |
| 'Tesla', | |
| 'Lada' | |
| ] | |
| // becomes | |
| cars: [ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var state = { selectedCar: selectedCar } | |
| // becomes | |
| var state = { selectedCar } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var state = Object.assign({}, state.history, selectedCar.id) | |
| // becomes | |
| var state = { ...state.history, ...selectedCar.id } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var message = 'The best car is ' + randomCar | |
| // becomes | |
| var message = `The best car is ${randomCar}` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| onClick={function(e) { | |
| this.setSelectedCar(e.target.value) | |
| }.bind(this)} | |
| // becomes | |
| onClick={e => this.setSelectedCar(e.target.value)} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var cars = this.cars.map(car => ... | |
| var message = 'No cars' | |
| if (cars.length) { | |
| var randomCar = null | |
| message = `The best car is ${randomCar}` | |
| ... | |
| // becomes | |
| const cars = this.cars.map(car => ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class ProgressiveImage extends Component { | |
| state = { | |
| currentImage: this.props.preview, | |
| loading: true, | |
| } | |
| componentDidMount() { | |
| this.fetchImage(this.props.image) | |
| } |
OlderNewer