choco-solver icon indicating copy to clipboard operation
choco-solver copied to clipboard

Should provide code formatting rules

Open chocotrust opened this issue 8 years ago • 21 comments

Like with Checkstyle

chocotrust avatar Sep 14 '16 16:09 chocotrust

I evaluated Checktyle default rules, it detects 23604 items in 570 files (almost all of them). A little configuration is necessary.

chocotrust avatar Sep 14 '16 16:09 chocotrust

I think that by default, it uses Sun recommendation while Intellij uses its own. My advice is “uses something that matches what you do since 10 years :D”

Le 14 sept. 2016 à 18:01, Choco Team [email protected] a écrit :

Like with Checkstyle

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or mute the thread.


Fabien Hermenier Associate Professor SCALE Project, University Nice Sophia Antipolis http://fhermeni.github.io

fhermeni avatar Sep 14 '16 21:09 fhermeni

That's what I had in mind ;)

cprudhom avatar Sep 15 '16 07:09 cprudhom

Beside checkstyle, you could also provide custom formatter for Eclipse and IntellijIdea. However, I hope that it is doable (see here).

arnaud-m avatar Sep 15 '16 09:09 arnaud-m

It is maybe not as difficult as it was (see this post).

arnaud-m avatar Sep 15 '16 09:09 arnaud-m

maven can be configured with a formatter plugin. this plugin needs to have a project specifically to import the formatter.xml into the other projects too, which is bad IMO ( http://code.revelc.net/formatter-maven-plugin/formatter-maven-plugin/examples.html#Multimodule_Configuration ) Once this plugin is installed, every time you compile your code will be formatted. The plugin memorizes the hashes of the java file before formatting them again.

glelouet avatar Nov 10 '16 10:11 glelouet

I'll play around with the plugin on a private branch to test it.

cprudhom avatar Nov 14 '16 09:11 cprudhom

I played with formatter-maven-plugin and was not entirely satisfied with the process. I read that it is better to give rules (for instance, checkstyle-based ones) instead of auto-formatting code. So, I will provide a check style-checker XML file and an IntelliJ IDEA code style scheme that auto format code (one may want to provide the same file for Eclipse). These files will then updated until we reach a fix point since some rules can be discussed.

cprudhom avatar Nov 14 '16 12:11 cprudhom

Here is a few related links :

  • https://github.com/HPI-Information-Systems/Metanome/wiki/Installing-the-google-styleguide-settings-in-intellij-and-eclipse
  • https://github.com/krasa/EclipseCodeFormatter
  • https://blog.jetbrains.com/idea/2014/10/intellij-idea-14-will-detect-code-styles-on-the-fly/
  • https://plugins.jetbrains.com/plugin/6546

Good luck !

arnaud-m avatar Nov 14 '16 12:11 arnaud-m

Luck is the right word

cprudhom avatar Nov 14 '16 12:11 cprudhom

Well, I finally succeed to make formatter-maven-plugin works (@glelouet: thank you) and started a formatter file. That is not enough, but that is a good start. I will now try to configure a Checkstyle.xml file to share too.

cprudhom avatar Nov 14 '16 15:11 cprudhom

What about using google-java-format ?

cprudhom avatar Nov 16 '16 10:11 cprudhom

I believe that it is a good idea if you like their code style. The first link of my previous post show that their style can be easily integrated within intellij and eclipse.

arnaud-m avatar Nov 16 '16 10:11 arnaud-m

That would be a good point if we are able to override some of the rules easily

cprudhom avatar Nov 16 '16 10:11 cprudhom

I like the last one since it seems to be an active projet from google

cprudhom avatar Nov 16 '16 10:11 cprudhom

I tested their maven plugin and since:

  • the projet is active,
  • the google code style is wide spread,
  • the google code style is not far away from what we've done since (i.e., few modifications), and
  • I don't feel like designing our own rules, I vote for this solution.

I suggest to update pom.xml just before the next release.

cprudhom avatar Nov 16 '16 11:11 cprudhom

Let's go for the google code style ! I will give you feedback after the eclipse integration.

arnaud-m avatar Nov 16 '16 12:11 arnaud-m

Strangely, the maven plugin does not modified files like google-java-format, even though it seems based on it. So, a first step would be to simply use the maven plugin and wait for any updates.

cprudhom avatar Nov 16 '16 13:11 cprudhom

FYI: following these steps I imported intellij-java-google-style.xml in IntelliJ IDEA (configuration files for other IDE can be found here).

cprudhom avatar Nov 17 '16 13:11 cprudhom

I looked at google java format and found that indentation of only 2 spaces instead ordinary 4 spaces is used. I have warn you that 2 spaces are not good, my experience with a lot of levels in foreign code is very bad for readability.

gregy4 avatar Jan 20 '17 15:01 gregy4

Thank you for your feedbacks. Actually, I'm still not convinced by tools I found so far, so I probably wait for a maven-like tool, customizable.

cprudhom avatar Jan 20 '17 16:01 cprudhom