Skip to content
This repository has been archived by the owner on Mar 5, 2023. It is now read-only.

Checkstyle: enforce separators' placement in line wraps #319 #368

Merged
merged 1 commit into from Apr 14, 2017
Merged

Checkstyle: enforce separators' placement in line wraps #319 #368

merged 1 commit into from Apr 14, 2017

Conversation

eugenepeh
Copy link
Member

@eugenepeh eugenepeh commented Mar 28, 2017

Addition to #319

@mention-bot
Copy link

@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.

@eugenepeh eugenepeh changed the title Checkstyle: add SeparatorWrap rules Checkstyle: add SeparatorWrap rules #319 Mar 28, 2017
@CanIHasReview-bot
Copy link

v1

@eugenepeh submitted v1 for review.

(📚 Archive)

Checkout this PR version locally
git fetch https://github.com/se-edu/addressbook-level4.git refs/pr/368/1/head:BRANCHNAME

where BRANCHNAME is the name of the local branch you want to fetch this PR to.

Copy link
Contributor

@PierceAndy PierceAndy left a 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.

Copy link
Contributor

@chao1995 chao1995 left a 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.

@eugenepeh
Copy link
Member Author

eugenepeh commented Mar 29, 2017

Thanks for pointing that out @chao1995, I have missed out some of it.
The operators though, it seems like from checkstyle documentation
(http://checkstyle.sourceforge.net/config_whitespace.html#SeparatorWrap),
doesn't seems available yet in token list.

Should we still proceed with what we can do first, while submitting a ticket to checkstyle,
and hope that it will be implemented in future?

@PierceAndy
Copy link
Contributor

PierceAndy commented Mar 29, 2017

@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.

@CanIHasReview-bot
Copy link

v2

@eugenepeh submitted v2 for review.

(📚 Archive) (📈 Interdiff between v1 and v2)

Checkout this PR version locally
git fetch https://github.com/se-edu/addressbook-level4.git refs/pr/368/2/head:BRANCHNAME

where BRANCHNAME is the name of the local branch you want to fetch this PR to.

@chao1995
Copy link
Contributor

chao1995 commented Mar 29, 2017

@eugenepeh

The operators though, it seems like from checkstyle documentation
(http://checkstyle.sourceforge.net/config_whitespace.html#SeparatorWrap),
doesn't seems available yet in token list.

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. A method or constructor name stays attached to the open parenthesis ( that follows it. (checkstyle LPAREN), we should add that to this PR.

<property name="tokens" value="ELLIPSIS"/>
<property name="tokens" value="SEMI"/>
<property name="tokens" value="LPAREN"/>
<property name="option" value="EOL"/>
Copy link
Contributor

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.

<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"/>
Copy link
Contributor

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"/>

@CanIHasReview-bot
Copy link

v3

@eugenepeh submitted v3 for review.

(📚 Archive) (📈 Interdiff between v2 and v3)

Checkout this PR version locally
git fetch https://github.com/se-edu/addressbook-level4.git refs/pr/368/3/head:BRANCHNAME

where BRANCHNAME is the name of the local branch you want to fetch this PR to.

Copy link
Contributor

@PierceAndy PierceAndy left a 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"/>
Copy link
Contributor

@chao1995 chao1995 Mar 30, 2017

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.

Copy link
Member Author

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?

Copy link
Contributor

@PierceAndy PierceAndy Mar 30, 2017

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.

Copy link
Contributor

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.

Copy link
Contributor

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=

Copy link
Contributor

@PierceAndy PierceAndy Mar 30, 2017

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

Copy link
Contributor

@chao1995 chao1995 Mar 30, 2017

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".

Copy link
Contributor

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"/>
Copy link
Contributor

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.

Copy link
Member Author

@eugenepeh eugenepeh Mar 30, 2017

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

Copy link
Contributor

@PierceAndy PierceAndy Mar 30, 2017

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?

Copy link
Contributor

@chao1995 chao1995 Mar 30, 2017

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.

Copy link
Member Author

@eugenepeh eugenepeh Mar 30, 2017

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 ?

Copy link
Contributor

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));
Copy link
Contributor

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
Copy link
Contributor

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()));

@CanIHasReview-bot
Copy link

v4

@eugenepeh submitted v4 for review.

(📚 Archive) (📈 Interdiff between v3 and v4)

Checkout this PR version locally
git fetch https://github.com/se-edu/addressbook-level4.git refs/pr/368/4/head:BRANCHNAME

where BRANCHNAME is the name of the local branch you want to fetch this PR to.

&& this.text.equals(((TestFxmlObject) other).getText()));
return other == this // short circuit if same object
|| (other instanceof TestFxmlObject
&& this.text.equals(((TestFxmlObject) other).getText()));
Copy link
Contributor

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));
Copy link
Contributor

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.

@CanIHasReview-bot
Copy link

v5

@eugenepeh submitted v5 for review.

(📚 Archive) (📈 Interdiff between v4 and v5)

Checkout this PR version locally
git fetch https://github.com/se-edu/addressbook-level4.git refs/pr/368/5/head:BRANCHNAME

where BRANCHNAME is the name of the local branch you want to fetch this PR to.

@@ -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"/>
Copy link
Contributor

@chao1995 chao1995 Apr 4, 2017

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"/>

Copy link
Contributor

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.

Copy link
Contributor

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.

Copy link
Contributor

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.

@chao1995
Copy link
Contributor

chao1995 commented Apr 4, 2017

Some suggestions to the commit message

Our coding standard for Java requires that line wrappings that
involves separator to follow a specific format, such as having the
comma (,) stay attached to the token that precedes it and having the
dot (.) follow the symbol in next line. This rule is not enforced by
checkstyle.

requires that line wrappings
involve separators
a specific format to specific rules
the comma
the dot (.) follow the symbol in next line to dot (.) in a new line
This rule is to These rules are.

A code example would be like this
s
.isEmpty();
foo(i,
s);

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.

Let's fix this by adding SeparatorWrap rules to ensure that our line
wrappings, that involve separators, are standardized and consistent.

are standardized and consistent to are consistent with our coding standard.

@CanIHasReview-bot
Copy link

v6

@eugenepeh submitted v6 for review.

(📚 Archive) (📈 Interdiff between v5 and v6)

Checkout this PR version locally
git fetch https://github.com/se-edu/addressbook-level4.git refs/pr/368/6/head:BRANCHNAME

where BRANCHNAME is the name of the local branch you want to fetch this PR to.

Copy link
Contributor

@PierceAndy PierceAndy left a 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.

@@ -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. -->
Copy link
Contributor

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" -> "@"

@CanIHasReview-bot
Copy link

v7

@eugenepeh submitted v7 for review.

(📚 Archive) (📈 Interdiff between v6 and v7)

Checkout this PR version locally
git fetch https://github.com/se-edu/addressbook-level4.git refs/pr/368/7/head:BRANCHNAME

where BRANCHNAME is the name of the local branch you want to fetch this PR to.

@eugenepeh eugenepeh changed the title Checkstyle: add SeparatorWrap rules #319 Checkstyle: enforce separators consistency in line wraps Apr 8, 2017
@eugenepeh eugenepeh changed the title Checkstyle: enforce separators consistency in line wraps Checkstyle: enforce separators consistency in line wraps #319 Apr 8, 2017
@eugenepeh eugenepeh changed the title Checkstyle: enforce separators consistency in line wraps #319 Checkstyle: enforce separators' placement in line wraps #319 Apr 11, 2017
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.
@CanIHasReview-bot
Copy link

v8

@eugenepeh submitted v8 for review.

(📚 Archive) (📈 Interdiff between v7 and v8)

Checkout this PR version locally
git fetch https://github.com/se-edu/addressbook-level4.git refs/pr/368/8/head:BRANCHNAME

where BRANCHNAME is the name of the local branch you want to fetch this PR to.

@damithc damithc merged commit dc9fe96 into se-edu:master Apr 14, 2017
@eugenepeh eugenepeh deleted the 319-add-SeparatorWrap branch April 14, 2017 16:20
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants