annotate content/Eclipse/formatting-sources.md @ 112:cf31bf5fce72 default tip

Author of the blog post as mail header for efficient spam filtering
author Dirk Olmes <dirk.olmes@codedo.de>
date Tue, 06 Sep 2022 07:04:11 +0200
parents e19bc3042ec9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
90
e19bc3042ec9 draft for formatting eclipse sources using a batch tool
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
1 Title: Formatting Java sources with Eclipse
e19bc3042ec9 draft for formatting eclipse sources using a batch tool
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
2 Date: 2017-08-04
e19bc3042ec9 draft for formatting eclipse sources using a batch tool
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
3 Lang: en
e19bc3042ec9 draft for formatting eclipse sources using a batch tool
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
4 Status: draft
e19bc3042ec9 draft for formatting eclipse sources using a batch tool
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
5
e19bc3042ec9 draft for formatting eclipse sources using a batch tool
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
6 All books on good code style suggest formatting your sources consistently. I found that it does not matter too much if you're in the *curly braces at the end of the line* or in the *curly braces on a new line* camp. Clean code is readable in any formatting.
e19bc3042ec9 draft for formatting eclipse sources using a batch tool
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
7
e19bc3042ec9 draft for formatting eclipse sources using a batch tool
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
8 At [exentra](http://www.exentra.de) we follow this rule and since we all use Eclipse it's fairly easy: configure Eclipse's formatter, have a save action format all code on save and the basic source formatting is covered.
e19bc3042ec9 draft for formatting eclipse sources using a batch tool
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
9
e19bc3042ec9 draft for formatting eclipse sources using a batch tool
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
10 But what if you don't want or cannot use Eclipse? There are stand alone code formatters out there but why learn another tool when Eclipse already does the job fairly well? It would be nice if Eclipse's code formatter could be run from the command line. As [it turns out](http://www.peterfriese.de/formatting-your-code-using-the-eclipse-code-formatter/) it's possible. And it's even [documented in the Eclipse help](https://help.eclipse.org/oxygen/index.jsp?topic=%2Forg.eclipse.jdt.doc.user%2Ftasks%2Ftasks-231.htm).
e19bc3042ec9 draft for formatting eclipse sources using a batch tool
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
11
e19bc3042ec9 draft for formatting eclipse sources using a batch tool
Dirk Olmes <dirk@xanthippe.ping.de>
parents:
diff changeset
12 The approaches I have cited above only work on a desktop machine, though as they require a full Eclipse installation. But what if you want your code formatted on e.g. a CI machine? There must be a way to strip down the dependencies to run the source formatter to a bare minimum. It turns out that [someone took up the task already](http://franke.ms/#/eclipse-formatter-commandline.wiki). Stefan's latest update is based on Eclipse Neon but I want one based on Eclipse Oxygen of course.