I want to auto-indent a full javascript project. How can I do that using WebStorm or another tool?
Asked
Active
Viewed 1,814 times
4
-
What have you tried so far? Is it multiple files? Is the javascript in HTML files or separate files, etc? – Soviut Nov 14 '16 at 15:42
-
I know ^ + alt + I, but it just does the selection. I want something for the full project (javascript). Not just one file – Alexis Benoist Nov 14 '16 at 15:44
3 Answers
3
- Select your project root folder/source root folder in the Project tool window on the left
- From main menu choose Code | Reformat Code (or hit
Ctrl+Alt+L
)

lena
- 90,154
- 11
- 145
- 150
0
This project called js-beautify could help you. It exists as an npm or python package.
You can then use find to iterate over all the js files in your directory :
find . -name '*.js' -exec js-beautify -r {} \;
Warning : it will indent all the js files, and will overwrite the original files. Be sure to have commited those files to svn/git before you try the above command.

Eric Duminil
- 52,989
- 9
- 71
- 124
0
Create file in your project root: .editorconfig with content
# http://editorconfig.org
root = true
[*]
charset = utf-8
indent_style = space
indent_size = 2
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
Adjust ident_size for yourself.
Restart WebStorm, accept that WebStrom should use editor config file.
Click: ctrl+alt+L
Or: Code > Reformat code

Vlado Tesanovic
- 6,369
- 2
- 20
- 31