-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Checkstyle: enforce operators' placement in line wraps #319 #382
Conversation
@eugenepeh, thanks for your PR! By analyzing the history of the files in this pull request, we identified @yl-coder, @damithc and @m133225 to be potential reviewers. |
@eugenepeh Sorry was the PR supposed to be ready? The PR does not have a |
@yamgent so sorry was a little busy with finals. |
v1@eugenepeh submitted v1 for review. Checkout this PR version locallygit fetch https://github.com/se-edu/addressbook-level4.git refs/pr/382/1/head:BRANCHNAME where |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't get this to work on my side. The following errors appear. The errors disappear when I deleted the lines that you added:
Executing external tasks 'checkstyleMain checkstyleTest'...
:compileJava UP-TO-DATE
:processResources UP-TO-DATE
:classes UP-TO-DATE
:checkstyleMain FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':checkstyleMain'.
> Unable to create a Checker: configLocation {/home/wangleng/github/yamgent/addressbook-level4/config/checkstyle/checkstyle.xml}, classpath {/home/wangleng/github/yamgent/addressbook-level4/build/classes/main:/home/wangleng/github/yamgent/addressbook-level4/build/resources/main}.
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 0.866 secs
The content of element type "module" must match "(module|property|metadata|message)*".
8:24:19 AM: External tasks execution finished 'checkstyleMain checkstyleTest'.
config/checkstyle/checkstyle.xml
Outdated
</module> | ||
<module name="OperatorWrap"> | ||
<!-- Checks that assign type operator is at the previous end of line in a line wrap. | ||
This include "=", "/=", "+=", "-=", "*=", "%=", ">>=", ">>>=", "<<=", "^=", "&=". |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unless we are using default values (i.e. not specifying the value
property manually), the constants ASSIGN
, DIV_ASSIGN
, etc... seems to be self explanatory. Not sure whether we need to repeat it in the comments in such cases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh... I added them in comments because some values can be hard to understand without referring to the checkstyle documentation. Also, it would be weird to add just some of them, so I added them all. Might need more opinions on this.
P.S
Thanks for testing it on your side because I been trying to resolve this weird error.
@@ -42,7 +42,7 @@ allprojects { | |||
junitVersion = '4.12' | |||
testFxVersion = '4.0.5-alpha' | |||
monocleVersion = '1.8.0_20' | |||
checkstyleVersion = '7.1.2' | |||
checkstyleVersion = '7.2' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Discovered that the METHOD_REF token needs checkstyle 7.2 to work,
http://checkstyle.sourceforge.net/releasenotes.html#Release_7.2
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent, it works now. 👍
v2@eugenepeh submitted v2 for review. (📚 Archive) (📈 Interdiff between v1 and v2) Checkout this PR version locallygit fetch https://github.com/se-edu/addressbook-level4.git refs/pr/382/2/head:BRANCHNAME where |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, just minor nit about the spellings in the comments.
config/checkstyle/checkstyle.xml
Outdated
@@ -322,6 +322,28 @@ | |||
<property name="message" value="Trailing whitespace"/> | |||
</module> | |||
|
|||
<module name="OperatorWrap"> | |||
<!-- Checks that non-assign type operator is at the next line in a line wrap. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assign
-> assignment
?
config/checkstyle/checkstyle.xml
Outdated
<!-- Checks that non-assign type operator is at the next line in a line wrap. | ||
This include "?", ":", "==", "!=", "/", "+", "-", "*", "%", ">>", ">>>", | ||
">=", ">", "<<", "<=", "<", "^", "|", "||", "&", "&&", "instanceof", | ||
"&" when used in a generic upper or lower bounds constrain, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
constrain
-> constraints
?
v3@eugenepeh submitted v3 for review. (📚 Archive) (📈 Interdiff between v2 and v3) Checkout this PR version locallygit fetch https://github.com/se-edu/addressbook-level4.git refs/pr/382/3/head:BRANCHNAME where |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wraps to follow specific rules, such as having assign operator (=)
The commit message still has the old spelling :P
Should be:
...such as having the assignment operator (=)
config/checkstyle/checkstyle.xml
Outdated
@@ -322,6 +322,28 @@ | |||
<property name="message" value="Trailing whitespace"/> | |||
</module> | |||
|
|||
<module name="OperatorWrap"> | |||
<!-- Checks that non-assignment type operator is at the next line in a line wrap. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor grammar nit:
Checks that the non-assignment...
config/checkstyle/checkstyle.xml
Outdated
@@ -322,6 +322,28 @@ | |||
<property name="message" value="Trailing whitespace"/> | |||
</module> | |||
|
|||
<module name="OperatorWrap"> | |||
<!-- Checks that non-assignment type operator is at the next line in a line wrap. | |||
This include "?", ":", "==", "!=", "/", "+", "-", "*", "%", ">>", ">>>", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor grammar nit:
This includes ...
config/checkstyle/checkstyle.xml
Outdated
</module> | ||
<module name="OperatorWrap"> | ||
<!-- Checks that assignment type operator is at the previous end of line in a line wrap. | ||
This include "=", "/=", "+=", "-=", "*=", "%=", ">>=", ">>>=", "<<=", "^=", "&=". |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The grammar nit comments can also be applied here.
Our coding standard for Java requires operators' placement in line wraps to follow specific rules, such as having assignment operator (=) stay attached to the token that precedes it and having the arithmetric operator (+) in a new line. These rules are not enforced by checkstyle. Let's teach Checkstyle to be stricter about line wrapping around more symbols by adding the relevant OperatorWrap rules.
v4@eugenepeh submitted v4 for review. (📚 Archive) (📈 Interdiff between v3 and v4) Checkout this PR version locallygit fetch https://github.com/se-edu/addressbook-level4.git refs/pr/382/4/head:BRANCHNAME where |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good!
Addition to #319
Enhance #368