Skip to content

Instantly share code, notes, and snippets.

@maxlath
Last active November 10, 2019 21:37
Show Gist options
  • Save maxlath/c7c3a3809a0ac22c3ca315887570e20f to your computer and use it in GitHub Desktop.
Save maxlath/c7c3a3809a0ac22c3ca315887570e20f to your computer and use it in GitHub Desktop.
completing bulk-decaffeinate and eslint --fix
#!/usr/bin/env node
// To be run after bulk-decaffeinate is done
// bulk-decaffeinate convert --num-workers 8 --config ~/bulk-decaffeinate.config.js
// cleanup(){
// decaffeinate_cleanup.js "$@" && npm run lint-fix "$@"
// }
//
// cleanup **/*.js
const path = require('path')
const fs = require('fs')
const cleanupLine = line => {
return line
.replace(/^(\s+(?!(if|for))\w+) (\(.*\)) \{/g, '$1: $3 => {')
.replace(/= function (\(.*\)) {/g, '= $1 => {')
.replace(/=> function (\(.*\)) {/g, '=> $1 => {')
.replace(/(^\s+if) (\(.*\)) { return\s?(.*) }/g, '$1 $2 return $3')
.replace(/(^\s+if) (\(.*\)) { throw\s?(.*) }/g, '$1 $2 throw $3')
.replace(/(^\s+else) { return\s?(.*) }/g, '$1 return $2')
.replace(/(^\s+else) { throw\s?(.*) }/g, '$1 throw $2')
.replace(/return done\(\)/, 'done()')
.replace(/return it\(/, 'it(')
}
const update = file => {
const current = fs.readFileSync(file).toString()
const updated = current
.split('\n')
.map(cleanupLine)
.join('\n')
if (current !== updated) fs.writeFileSync(file, updated)
}
process.argv.slice(2)
.map(file => path.resolve(file))
.forEach(update)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment