-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Checkstyle: enforce separators' placement in line wraps #319 #368
Conversation
@eugenepeh, thanks for your PR! By analyzing the history of the files in this pull request, we identified @yl-coder, @m133225 and @chao1995 to be potential reviewers. |
v1@eugenepeh submitted v1 for review.
Checkout this PR version locallygit fetch https://github.com/se-edu/addressbook-level4.git refs/pr/368/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.
[v1 1/1] Commit message:
Thus it should be consistent and follow
having the comma (,) stay
having the dot (.) follow
It will ensure
- Lines are wrapping at inconsistent and odd positions.
- While your commit messages are generally quite good, minor nits remain (e.g. the first paragraph should be about the current situation). Please refer to our most up-to-date guidelines on commit messages. I understand that you might have missed these updated guidelines as they are still in its final stages of PR reviewing.
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.
According to our coding standard on line wrapping (item 3 under Files), we also require rules like Break before an operator
. Thus I think checkstyle's separatorWrap rule looks like a better fit. But I think we still need to tinker with it.
Thanks for pointing that out @chao1995, I have missed out some of it. Should we still proceed with what we can do first, while submitting a ticket to checkstyle, |
@chao1995 Did you mean OperatorWrap? @eugenepeh This would warrant its own PR + updates to #319. This PR can proceed as they deal with different sets of characters. |
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/368/2/head:BRANCHNAME where |
The one you manage to find actually is OperatorWrap as pointed out by @PierceAndy, which should be done in a separate PR. Sorry for the bad example. But if there are some other checks supported by separatorWrapRule, which happens to also be our line wrapping rule, e.g. |
config/checkstyle/checkstyle.xml
Outdated
<property name="tokens" value="ELLIPSIS"/> | ||
<property name="tokens" value="SEMI"/> | ||
<property name="tokens" value="LPAREN"/> | ||
<property name="option" value="EOL"/> |
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.
Default value. Can be omitted.
config/checkstyle/checkstyle.xml
Outdated
<module name="SeparatorWrap"> | ||
<!-- Checks that the ".", "at" is at the next line in a line wrap. --> | ||
<property name="tokens" value="DOT"/> | ||
<property name="tokens" value="AT"/> |
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 believe that you can list all tokens
property values in a single tokens
property by using commas:
<property name="tokens" value="DOT, AT"/>
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/368/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.
LGTM
</module> | ||
<module name="SeparatorWrap"> | ||
<!-- Checks that the ",", "]", "[", "...", ";", "(" is at the previous end of line in a line wrap. --> | ||
<property name="tokens" value="COMMA, RBRACK, ARRAY_DECLARATOR, ELLIPSIS, SEMI, LPAREN"/> |
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.
even though eol
is the default value for option, let's still put it there for clarity reason, since it's not an obvious default.
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.
@PierceAndy, does this conflict with issue #370?
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 option property tag isn't necessary as the comment clarifies the policy on how to wrap lines.
We could argue that we should include properties with default values, and not use comments. However to be consistent, we would have to include all properties for all checkstyle modules, as every property has default values. This would unnecessarily add a lot of lines without necessarily enhancing readability, when compared to using comments.
This is a problem of standardization for checkstyle.xml
, as we still don't have one.
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 think it's better to be consistent with the configuration provided by checkstyle, if there is no strong reason not to do so.
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.
also, value
means one value, for multiple values, I would use values=
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.
About the omitting of properties with default values, the configuration provided does so as well.
See: configuration by checkstyle
See: checkstyle docs with all properties
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.
This is the option we are talking about.
Note that there are two separator rules in the config file. And I feel it's strange to have one separator rule has an option "nl", but the other has no option. It's not obvious the option is actually "eol".
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.
Yes, if using the same module multiple times, it seems better to not omit properties with default values if these properties are different across modules with the same name.
</module> | ||
<module name="SeparatorWrap"> | ||
<!-- Checks that the ",", "]", "[", "...", ";", "(" is at the previous end of line in a line wrap. --> | ||
<property name="tokens" value="COMMA, RBRACK, ARRAY_DECLARATOR, ELLIPSIS, SEMI, LPAREN"/> |
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 would prefer not to use "," to separate them. Let's follow checkstyle's style, use multiple properties.
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.
This, however, will result in non-standardization though, since all other rules in checkstyle config file have their tokens all in single line.
Is there any guideline regarding this?
Issue oss-generic/process#84 Typo**, @PierceAndy
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.
#84 is not an issue. Typo?
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.
Is there any guideline regarding this?
I think it's better to be consistent with the configuration provided by checkstyle, if there is no strong reason not to do so.
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 personally thinks that excessive long modules (similar to methods) do affects readability though, especially module such as OperatorWrap which we should take into consideration as well if we were to implement that in our checkstyle configuration too.
Your thoughts on this, @PierceAndy ?
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.
Yes, it seems it would be better to have a single value per property.
&& this.internalList.equals( | ||
((UniqueTagList) other).internalList)); | ||
&& this.internalList.equals(((UniqueTagList) other) | ||
.internalList)); |
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 like we don't need a line wrap here.
@@ -27,8 +27,7 @@ public void setText(String text) { | |||
|
|||
@Override | |||
public boolean equals(Object other) { | |||
return other == this || | |||
(other instanceof TestFxmlObject | |||
return other == this || (other instanceof TestFxmlObject |
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.
can format similar to UniqueTagList.java
above, which is slightly easier to read i.e.
return other == this // short circuit if same object
|| (other instanceof TestFxmlObject
&& this.text.equals(((TestFxmlObject) other).getText()));
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/368/4/head:BRANCHNAME where |
&& this.text.equals(((TestFxmlObject) other).getText())); | ||
return other == this // short circuit if same object | ||
|| (other instanceof TestFxmlObject | ||
&& this.text.equals(((TestFxmlObject) other).getText())); |
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.
This however is misleading: ||
and &&
are operating at different levels in the expression while this line wrapping gives the impression they are at the same level.
Does the code below violate any of our rules/standards? I remember we decided not to have custom indentation levels but we may have to make an exception for expressions.
return other == this // short circuit if same object
|| (other instanceof TestFxmlObject
&& this.text.equals(((TestFxmlObject) other).getText()));
@@ -103,8 +103,7 @@ public void setPersons(List<? extends ReadOnlyPerson> persons) throws DuplicateP | |||
public boolean equals(Object other) { | |||
return other == this // short circuit if same object | |||
|| (other instanceof UniquePersonList // instanceof handles nulls | |||
&& this.internalList.equals( | |||
((UniquePersonList) other).internalList)); | |||
&& this.internalList.equals(((UniquePersonList) other).internalList)); |
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.
Please indent this line as well.
v5@eugenepeh submitted v5 for review.
(📚 Archive) (📈 Interdiff between v4 and v5) Checkout this PR version locallygit fetch https://github.com/se-edu/addressbook-level4.git refs/pr/368/5/head:BRANCHNAME where |
config/checkstyle/checkstyle.xml
Outdated
@@ -306,6 +306,17 @@ | |||
<property name="message" value="Trailing whitespace"/> | |||
</module> | |||
|
|||
<module name="SeparatorWrap"> | |||
<!-- Checks that the ".", "at" is at the next line in a line wrap. --> | |||
<property name="tokens" value="DOT, AT"/> |
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.
@damithc Prof, what is your thought of using a "," to separate values rather than using multiple properties with each line having one single value, like this:
<property name="tokens" value="DOT"/>
<property name="tokens" value="AT"/>
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.
Our previous discussion here.
We came to the consensus that for readability purposes, it would be better to have one value per property tag.
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.
While I'm ok with one value per line, it looks a bit odd when the same property is being assigned multiple times, especially when the property is supposed to be multi-valued. It looks almost like the value is being overwritten multiple times.
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.
It looks almost like the value is being overwritten multiple times.
@eugenepeh Prof @damithc pointed out something I didn't think of before. Indeed it can be misleading, so I'm fine with the current changes.
Some suggestions to the commit message
These texts are not very nicely formatted. Since we have explained this example in the previous paragraph, I think we can leave the example out.
|
v6@eugenepeh submitted v6 for review.
(📚 Archive) (📈 Interdiff between v5 and v6) Checkout this PR version locallygit fetch https://github.com/se-edu/addressbook-level4.git refs/pr/368/6/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.
Just one last minor thing.
config/checkstyle/checkstyle.xml
Outdated
@@ -306,6 +306,17 @@ | |||
<property name="message" value="Trailing whitespace"/> | |||
</module> | |||
|
|||
<module name="SeparatorWrap"> | |||
<!-- Checks that the ".", "at" 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.
To be consistent with the others:
"at"
-> "@"
v7@eugenepeh submitted v7 for review.
(📚 Archive) (📈 Interdiff between v6 and v7) Checkout this PR version locallygit fetch https://github.com/se-edu/addressbook-level4.git refs/pr/368/7/head:BRANCHNAME where |
Our coding standard for Java requires separators' placement in line wraps to follow specific rules, such as having comma (,) stay attached to the token that precedes it and having the dot (.) in a new line. These rules are not enforced by checkstyle. Let's teach Checkstyle to enforce the coding standard above by adding the SeparatorWrap rules.
v8@eugenepeh submitted v8 for review. (📚 Archive) (📈 Interdiff between v7 and v8) Checkout this PR version locallygit fetch https://github.com/se-edu/addressbook-level4.git refs/pr/368/8/head:BRANCHNAME where |
Addition to #319