-
Notifications
You must be signed in to change notification settings - Fork 165
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Investigate formatter-maven-plugin for CI builds #822
Comments
In particular, what are peoples thoughts on exporting the formatter configuration as an artifact to Maven Central and putting it on a different build number (similar to some parent pom systems where they only use 1/2/3/4/etc.) so it can be consistently used and tracked separate to the rest of RDF4J? That is the recommended method for using the formatter-maven-plugin with multi module projects: |
Related to #790 |
Fwiw I have previoulsy briefly looked at using the maven checkstyle plugin for this purpose, but got mixed results. It's easy enough to set up but I had a hard time getting it to play nice with the Eclipse built-in code formatter. This plugin looks interesting though, and more immediately suited to our purpose. Link to github repo: https://github.com/revelc/formatter-maven-plugin |
I had a bit of a play with this formatter and I really like it. Easy to integrate in our build process, and also plays nice with Eclipse's internal formatter. |
Updated code conventions and formatter plugin
@jeenbroekstra I tested the formatter on fluent APIs like .stream() and it's a bit aggressive:
Gets converted to a single line, because it's shorter than 120 characters! I strongly prefer the multiline version of fluent apis, unless there is a particular need for using a one-liner (eg. in an IF condition). |
The problem with that is that that's not a distinction the formatter can make. I can configure it to forcible always turn qualified invocations like this into multiline statements (even if < 120 chars) but I can't make an exception for "when it is part of an IF-condition". The upshot is that if I change this, we also get this:
instead of:
|
I believe your particular example is an edge case: it's a fluent call that is just under 120 chars. If you feel that having it as a oneliner is less readable, you of course always have the option to use slightly longer variable names. Not only will that improve general readability, but it will also push it past the line length limit, so it will automatically get reformatted. |
Is there not a way to make it one-way. >120 always become multi line but <120 are ignored? |
So that if I make it multiline for readability, then it stays multiline. |
I'll do one tweak though: the current settings would reformat as follows:
I'll change it so it becomes:
(ignore the slightly too large indentation, that's a copy/paste issue) |
Shame it can’t handle that edge case. Using longer variable names is quite the hack to bypass the auto formatted. |
Afraid not. Or, well, there is, but enabling that would mean that the formatter never joins up two lines anymore. Which rather defeats the purpose. This kind of thing is always a compromise. |
I don't really see it as a hack. If you are aiming for increased readability of your code, longer variable names are exactly a means to that end. And for what it's worth, I actually think that
still reads just fine. |
Ah, I'm afraid I can't make the change I promised above either - it results in some rather weird side effects, for example:
becomes:
|
That’s fine. |
formatter no longer joins lines back up if deliberately split
* develop: temporary switch back to old inferencer to avoid test failure fix compilation failure due to merge issues one-time pass of formatter with line-rejoining enabled one-time pass with line-rejoining enabled Update Jackson dependency formatter no longer joins lines back up if deliberately split Revert "GH-1240 formatted with eclipse conventions" Revert "fixed overlooked file formatting" fixed overlooked file formatting GH-1240 GH-822 updated readme and contributing guidelines GH-1240 formatted with eclipse conventions GH-822 configured formatter plugin with new code conventions Signed-off-by: Håvard Ottestad <hmottestad@gmail.com> # Conflicts: # inferencer/src/main/java/org/eclipse/rdf4j/sail/inferencer/fc/SchemaCachingRDFSInferencer.java # inferencer/src/main/java/org/eclipse/rdf4j/sail/inferencer/fc/SchemaCachingRDFSInferencerConnection.java # sail-base/src/main/java/org/eclipse/rdf4j/sail/base/SailSourceBranch.java # sail-spin/src/main/java/org/eclipse/rdf4j/sail/spin/SpinSail.java # sail-spin/src/main/java/org/eclipse/rdf4j/sail/spin/SpinSailConnection.java # sail-spin/src/test/java/org/eclipse/rdf4j/sail/spin/benchmarks/BasicBenchmarks.java
Investigate adding formatter-maven-plugin to CI builds to validate formatting and fail CI builds (after compile/tests complete) if it has not been applied:
http://code.revelc.net/formatter-maven-plugin/formatter-maven-plugin/plugin-info.html
This will help with issues where the user has accidentally forgot to apply the formatting before submitting their pull request.
The text was updated successfully, but these errors were encountered: