Created
July 31, 2019 21:02
-
-
Save rxgx/6587ee8d24b34b92cd248c37e49e9627 to your computer and use it in GitHub Desktop.
Rename JS to JSX with ESLint JSON output
This file contains 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
// Run eslint with the rule 'react/jsx-filename-extension' as 'error' | |
// eslint -o json > files.json | |
const fs = require('fs'); | |
const json = require('./files.json') | |
console.log('run...', json.length); | |
json | |
.filter(entry => entry.messages.length) | |
.map(entry => { | |
entry.rules = entry.messages.map(item => item.ruleId); | |
return entry; | |
}) | |
.filter(entry => entry.rules.includes('react/jsx-filename-extension')) | |
.forEach((entry) => { | |
fs.rename(entry.filePath, entry.filePath.replace('.js', '.jsx'), (err) => { | |
if (err) throw err; | |
console.log(entry.filePath); | |
console.log(entry.filePath.replace('.js', '.jsx')); | |
}); | |
}); |
Thanks @vishalvisd this worked great!
I've modified the grep part to grep -l "</\|/>" $0
such that files which only contain <Comp/>
are matched as well.
@vishalvisd
I want to try your recommendation, but I have met "File not found - *.js"
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How about this, work fine for general use:
find ./src -type f -name '*.js' -not -name '*.jsx' -not -name '*.ejs' -exec bash -c 'grep -l "</" $0' {} \; -exec bash -c 'mv "$0" "${0%.js}.jsx"' {} \;