Skip to content

Instantly share code, notes, and snippets.

@mickdekkers
Last active June 27, 2020 15:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mickdekkers/d42518248abc28c2e8c8aee84fa42e80 to your computer and use it in GitHub Desktop.
Save mickdekkers/d42518248abc28c2e8c8aee84fa42e80 to your computer and use it in GitHub Desktop.
Clean JS snippets using lebab and prettier
function clean-js () {
local transforms='arrow,for-of,for-each,arg-rest,arg-spread,obj-method,obj-shorthand,no-strict,exponent,multi-var,let,class,commonjs,template,default-param,destruct-param,includes'
lebab --transform $transforms | prettier --no-semi --single-quote
}

You'll need to have lebab and prettier installed. Keep in mind some of lebab's transforms are unsafe, so don't use the resulting code in production without first testing it.

Output cleaned contents to stdout:

cat somefile.js | clean-js

Write cleaned contents to file:

cat somefile.js | clean-js > someotherfile.js

Replace file with cleaned contents:

cat somefile.js | clean-js | tee somefile.js

And so on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment