Code Formatting
Formatting Files for IDEs
IntelliJ IDEA
The code style xml file contains formatting for Java, XML, JSP(X), Freemarker, HTML, CSS, LessCSS, Sass, SCSS, Stylus, Javascript, Coffeescript, Typescript and JSON.
To install it go through the following steps:
-
Copy the settings XML file to the code styles directory. Its location is platform dependent, and is listed below. Please note that you need to replace <product-name> with the name and version of IDEA you use.
-
Mac OS X:
~/Library/Preferences/<product-name>/codestyles/
-
Linux:
~/.<product-name>/config/codeStyles/
-
Windows:
<User home>\.<product-name>\config\codeStyles\
-
-
Start IntelliJ
-
In the Preferences go to "Editor" - "Code Style" - "Scheme" and choose the previously imported style from the drop-down box
-
Optionally apply the style to one project only by clicking on "Copy to Project" and selecting "Use per project settings" afterwards
-
In Idea >= 10, use File -> Export/Import settings. This will allow you to select/deselect from many categories of settings (including code style).
Eclipse
-
Important: you still need to configure to use spaces instead of tabs.
-
Important: Eclipse formatting rules don't incorporate package import order or when wildcard importing should be used. See imports section below how it should be configured manually.
-
The Eclipse formatting file is not actively maintained and may not be up-to-date.
Formatting for Specific Languages
- Java Code Formatting
- JSP Code Formatting
- XML Code Formatting
- For all front-end languages (Javascript, CSS, Less, Sass, etc.) use 2 spaces indentation (no tabs).