Skip to content

Instantly share code, notes, and snippets.

@dhlavaty
Last active May 24, 2016 10:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dhlavaty/dc8480b4af3446a9d11202a16f913edd to your computer and use it in GitHub Desktop.
Save dhlavaty/dc8480b4af3446a9d11202a16f913edd to your computer and use it in GitHub Desktop.
Very naive Atom script to convert string concatenation to EcmaScript 6 template literals - for fixing ESLint 'prefer-template' rules
function toLiteral() {
var t = atom.workspace.getActiveTextEditor().getSelectedText();
t = t.replace(/\' \+ /g, "${");
t = t.replace(/ \+ \'/g, "}");
if (t.indexOf("'") == 0) {
t = t.substring(1);
} else {
t = "${" + t;
}
if (t.substr(t.length - 1, 1) == "'") {
t = t.substr(0, t.length - 1);
} else {
t = t + "}";
}
atom.workspace.getActiveTextEditor().insertText("`" + t + "`");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment