Last active
May 23, 2023 14:29
-
-
Save 8Observer8/608d4264094c5cc6c13649fa7d9be949 to your computer and use it in GitHub Desktop.
Format files recursively with js-beautify
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
const jsBeautify = require('js-beautify')['js_beautify']; | |
const fs = require('fs'); | |
const glob = require('glob'); | |
const options = { | |
indent_size: 4, | |
indent_char: ' ', | |
indent_with_tabs: false, | |
eol: '\n', | |
end_with_newline: true, | |
indent_level: 0, | |
preserve_newlines: true, | |
max_preserve_newlines: 10, | |
space_in_paren: false, | |
space_in_empty_paren: false, | |
jslint_happy: false, | |
space_after_anon_function: false, | |
brace_style: 'collapse, preserve-inline', | |
break_chained_methods: false, | |
keep_array_indentation: false, | |
unescape_strings: false, | |
wrap_line_length: 0, | |
e4x: false, | |
comma_first: false, | |
operator_position: 'before-newline' | |
}; | |
glob('**/!(node_modules)/**/*.js', { | |
absolute: true | |
}, (er, files) => { | |
files.forEach(file => { | |
console.log(`js-beautify ${file}`); | |
const data = fs.readFileSync(file, 'utf8'); | |
const nextData = jsBeautify(data, options); | |
fs.writeFileSync(file, nextData, 'utf8'); | |
}); | |
}); |
Author
8Observer8
commented
May 23, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment