Created
January 16, 2018 11:07
-
-
Save WebReflection/78f1832e97978d4db7aae44b653e4f61 to your computer and use it in GitHub Desktop.
fix allman style with brackets losing initial padding
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
function fixEslintAllman(code) { | |
return code.replace(/^{/mg, function ($0, $1) { | |
var newLine = code.lastIndexOf('\n', $1 - 2); | |
var spaces = code.slice(newLine + 1, $1 - 1).match(/^(\s*)/)[1]; | |
return spaces + '{'; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I ended up calling this file eslint-fix-allman and making it an executable hooked to Run on Save extension.