Skip to content

Instantly share code, notes, and snippets.

@rxgx
Created July 31, 2019 21:02
Show Gist options
  • Save rxgx/6587ee8d24b34b92cd248c37e49e9627 to your computer and use it in GitHub Desktop.
Save rxgx/6587ee8d24b34b92cd248c37e49e9627 to your computer and use it in GitHub Desktop.
Rename JS to JSX with ESLint JSON output
// 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'));
});
});
@danielberndt
Copy link

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.

@cg-tester
Copy link

@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