Eclipse JavaScript Code Formatter profile based on Google's Style Guide.
This was created by first importing Google's C++ profile and applying minor fixes to bring it closer to their JavaScript guide (some of the C++ settings weren't correctly imported).
I appreciate the role Eclipse played in the history of open-source development, but I no longer use it and I can't ever see myself returning. This project never perfectly mapped Google's style to Eclipse rules, and I haven't worked on this for 3 years.
- open Eclipse IDE
- open the Preferences window
- drill down: JavaScript -> Code Style -> Formatter
- click Import and select the provided XML file
- done!
Google's JavaScript Style Guide states that when wrapping long lines with binary (e.g. +) and ternary operations (e.g. ? :), "Always put the operator on the preceding line, so that you don't have to think about implicit semi-colon insertion issues. Otherwise, line breaks and indentation follow the same rules as in other Google style guides."
blah ?
blah :
blah;
blah
? blah
: blah;
There doesn't seem to be an Eclipse setting to enforce this, so it is probably good practice to try and keep these lines short if you don't want Eclipse to break the rules.