Skip to content
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

Issue #464: Check for trailing commas on enums #722

Closed

Conversation

kariem
Copy link
Contributor

@kariem kariem commented Oct 25, 2018

Addresses #464, supersedes #465, #474, and #709

This Check assures that the last enum constant definition in a multi-line enum ends in a comma:

enum E1 {
    ONE,
    TWO,
    THREE,
}

Usage examples are in the Javadoc of EnumTrailingCommaCheck. This check follows the concept of ArrayTrailingComma, hence the similar name.

It also checks that the "trailing" comma after the last enum constant definition is not followed by a semicolon, because this would miss the point of the check: clean diff and easy manipulation.

Copy link
Member

@romani romani left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when I review code I read Check goals and code .... that is why I see bunch of mismatches in goals and code/implementation. Lets clarify goals of Check.

I need more details on expected behavior:

@@ -183,6 +183,9 @@ EitherLogOrThrowCheck.loggingMethodNames = Logging method names separated with c
WhitespaceBeforeArrayInitializerCheck.name = Whitespace Before Array Initializer
WhitespaceBeforeArrayInitializerCheck.desc = This checks enforces whitespace before array initializer.

EnumTrailingCommaCheck.name = Enum Trailing Comma
EnumTrailingCommaCheck.desc = This checks enforces a trailing comma at the end of a line in an enum constant definition.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://docs.oracle.com/javase/specs/jls/se8/html/jls-8.html#jls-8.9.1

please remove "line" , this Check looks like care only about "coma after Enum Constant List" only.
If this is not true, than logic need to be changed.

import com.puppycrawl.tools.checkstyle.api.TokenTypes;

/**
* Checks if enum constant contains an optional trailing comma.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let make it absolutely clear that Check do no not validate all trailing commas, it demand presence of only one comma that is after enum constant list. Please make a link to jdk specification
https://docs.oracle.com/javase/specs/jls/se8/html/jls-8.html#jls-8.9.1

/**
* Checks if enum constant contains an optional trailing comma.
*
* <p>Rationale: Putting this comma in makes is easier to change the order of the elements or add
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there should be mentioned that Rationale is applicable only for cases when enum is formatted to have enum constant separate on line.
if Enum is single line - there is no benefit of this check.

Should this Check skip single line enums ? in other case what is a benefit of this Check on code like:
enum COLOR { RED, BLACK } ?
It might be ok to demand come here too, but Rationale need to be updated. I am not sure how to update it. Please suggest something, as you are author of this idea, you might know more use cases.

*
* @author <a href="kariem.hussein@gmail.com">Kariem Hussein</a>
*/
public class EnumTrailingCommaCheck extends AbstractCheck {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it depends probably on your replies above, but looks like, name of Check should be EnumConstantListTrailingCommaCheck , no need change right now, lets wait for clarification on Check behavior and rationale

@romani
Copy link
Member

romani commented Dec 30, 2018

@kariem , ping.

@romani
Copy link
Member

romani commented May 19, 2019

It is really sad that such a huge amount of work did not come to end.

we lost connection to Author of this code, I am closing PR .... if author or any other person ready to continue, we can reopen PR or start it from scratch.

As I see from comments, only minor items (naming/doc) are left to be done.

@romani romani closed this May 19, 2019
@kariem
Copy link
Contributor Author

kariem commented May 19, 2019

@romani I think you are right with the proposed changes.

I hope you can understand that after the huge amount of work invested in all the previous PRs (#465, #474, #709), it is difficult for me to make yet another change and then wait calmly for more requests for changes from your side.

Could you please check, if there is anything else left?

If I implement the changes requested in #722 (review) how many more changes can I expect to have to go through to have this PR merged?

@romani romani reopened this May 19, 2019
@romani
Copy link
Member

romani commented May 19, 2019

I hope you can understand that after the huge amount of work invested in all the previous PRs

I know this for sure.
But after many many years of Checks support and maintenance, I know how much it cost a design mistake that populate to all plugins and embedding systems.

Could you please check, if there is anything else left?

PR is reopened. I will review.

how many more changes can I expect to have to go through to have this PR merged?

I am not sure. Check need to pass CI, regression testing report (slightly manual), 2 human reviews.

@romani romani closed this May 26, 2019
@kariem
Copy link
Contributor Author

kariem commented May 26, 2019

@romani You said, you would review and then you close it? Did I misunderstand you?

I would like to finish the work here.

@romani
Copy link
Member

romani commented May 26, 2019

I do not see changes, please push them and reply to each review point as done or ...
PR should stay closed while my points are not addressed. We do not need long-hanging PR in our PRs list, to easy management of them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants