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

Check for trailing commas on enums #465

Closed
wants to merge 6 commits into from

Conversation

kariem
Copy link
Contributor

@kariem kariem commented Jul 29, 2016

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

enum E1 {
    ONE,
    TWO,
    THREE,
}

Addresses #464

@romani
Copy link
Member

romani commented Jul 29, 2016

from CI:

[ERROR] Jul 29, 2016 1:25:05 PM net.sourceforge.cobertura.coveragedata.CoverageDataFileHandler loadCoverageData

INFO: Cobertura: Loaded information on 68 classes.

com.github.sevntu.checkstyle.checks.coding.EnumTrailingCommaCheck failed check. Branch coverage rate of 73.3% is below 100.0%

should be fixed.

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

    enum E1 {
        ONE,
        TWO,
        THREE,
    }

Addresses sevntu-checkstyle#464
@coveralls
Copy link

coveralls commented Aug 1, 2016

Coverage Status

Coverage increased (+0.01%) to 98.228% when pulling af7482f on kariem:enum-trailing-commas into e4f878a on sevntu-checkstyle:master.

@kariem
Copy link
Contributor Author

kariem commented Aug 1, 2016

I thought the trivial changes did not ask for a separate commit, so I pushed an amend to the original. Please tell me if there is anything else that needs to be done.

@romani
Copy link
Member

romani commented Aug 4, 2016

@kariem ,

please extend your javadoc with examples of usages, as it will be the only source for documentation on how to use your Check. You have two violation messages so you definitely need to explain all cases (right now you have nothing about second validating case).
Example: http://sevntu-checkstyle.github.io/sevntu.checkstyle/apidocs/com/github/sevntu/checkstyle/checks/coding/AvoidModifiersForTypesCheck.html

Please put reference to issue number to git commit message for future investigations.

default:

that is not good, please throw IllegalStateException there , most likely you did this code due tu demand for 100% coverage, so please make a test to launch a Check on bad tree structure to make this exception happen.

InputEnumTrailingComma

as your Check does not have any properties, please update input file to have "//violation" trailing comment on line there violation is going to happen
Example:

+    enum E2 {
+        ONE,
+        TWO,
+        THREE //violation
+    }

Provide examples for the check and extend the rationale behind it.

Addresses sevntu-checkstyle#464
The default branch on the previous switch did not do anything and should not have raised an exception, which would be invalid for single-line enums.

Addresses sevntu-checkstyle#464
@kariem
Copy link
Contributor Author

kariem commented Aug 5, 2016

@romani, thank you very much for looking over the code!

  1. [Javadoc]

Done: 67870e9

There is some not-so-nice formatting in the line with the reference to the Java Language Specification. The checkstyle rule for javadoc should be changed: it limits line length to 100 characters, which prevents adding URLs. I could not deactivate a single line in Javadoc with CHECKSTYLE:OFF.

  1. Please put reference to issue number to git commit message for future investigations.

It's there on the first commit and all the subsequence commits, always on the last line. If you mean, putting the issue number on the first (summary) line, I don't think it's a good idea (1, 2). However, I can put it on line 3 (after the blank line), if you prefer that.

  1. [empty default in switch]

Yes, I agree: this is not good. However, the IllegalStateException would be invalid, because types that are not handled should really just be ignored. I don't think the check for trailing enums should at the same time try to check the syntax of the whole enum definition.

Done: 29b4c08

  1. ["//violation" trailing comment in InputEnumTrailingComma]

Done: 2211b55

@romani
Copy link
Member

romani commented Aug 5, 2016

Please squash all commits in one to ease review of final state of the code

@coveralls
Copy link

coveralls commented Aug 5, 2016

Coverage Status

Coverage increased (+0.01%) to 98.228% when pulling 2211b55 on kariem:enum-trailing-commas into c06c066 on sevntu-checkstyle:master.

@mkordas
Copy link
Contributor

mkordas commented Aug 5, 2016

@romani have you considered creating option here to prohibit such trailing commas if someone considers them as unnecessary code?

@romani
Copy link
Member

romani commented Aug 5, 2016

not yet, I do not see whole design of Check yet, we are in a progress ....
If author is ok, and you see it beneficial - please ask him to make it happen.

@kariem
Copy link
Contributor Author

kariem commented Aug 13, 2016

@romani @mkordas the design is similar to ArrayTrailingComma. In the initial commit (af7482f), even the javadoc and logic were similar, but changes to this were requested, as can be seen in the history of this PR.

@kariem
Copy link
Contributor Author

kariem commented Aug 13, 2016

Please squash all commits in one to ease review of final state of the code

@romani This would change the history and the whole discussion we've had in this PR. We would lose quite a bit of information. I don't see the point of this.

For the review of all changes or the final state of the code, use the files tab. After reviewing, you should be able to just merge all commits everything squashed into a single commit, following the instructions here.

@kariem
Copy link
Contributor Author

kariem commented Aug 25, 2016

What's missing here? Any indication on when we can get this done?

@romani
Copy link
Member

romani commented Aug 26, 2016

Sorry for delay, i will try to process your code as soon as i have time. Please pin me in a week if no feedback provided

@kariem
Copy link
Contributor Author

kariem commented Aug 26, 2016

It's ok - don't worry. Just wanted to make sure nothing is missing on my side. Thank you very much!

@romani
Copy link
Member

romani commented Aug 26, 2016

@kariem ,

This would change the history and the whole discussion we've had in this PR. We would lose quite a bit of information. I don't see the point of this.

history of discussion is minor in comparison to history of git and well written issue description.
please do squash. I need to see whole Check as single change to evaluate it.

For the review of all changes or the final state of the code,

yes I know this, but this is error prone in my experience, if you disagree please treat it as rule of this project.
Please add reference to original issue to git commit "Issue #XXXX: ........."
Btw, all Checks need to be applied to our sevntu-checkstyle and checkstyle code, so that should be done in separate commits (to prove that Check do work on our own code and we do follow that rules).

@romani
Copy link
Member

romani commented Aug 26, 2016

The following is a valid enum type declaration

"valid" , we use such words for marking violations in code, please change your word to "usual" or smth else.

I have some concerns about validation for "semicolon" , it is not clear from Check name that it will do that validation. .... let me think about this.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.01%) to 98.228% when pulling e238658 on kariem:enum-trailing-commas into c06c066 on sevntu-checkstyle:master.

@kariem
Copy link
Contributor Author

kariem commented Aug 26, 2016

[history and squashing commits]

I understand the point you are making: the git history is the "only truth".

GitHub has a good way to only have one commit (per pull request) in the commit history without altering the discussion in the pull request. Please follow the instructions here to do a Squash and Merge as soon as you think this is ready. I have already linked this previously.

Alternatively, as soon as there are no changes from your side, I can open another pull request with only one commit, if you prefer that.

Please add reference to original issue to git commit "Issue #XXXX: ........."

It's in every commit on the last line - do you want it at the start of the commit message in the summary? I am asking, because it somehow contradicts the importance of the history in git you have mentioned. If the reference to the issue is this prominent, the remaining summary text has to be shortened to 12 characters less than without that prefix.

  1. "valid" , we use such words for marking violations in code, please change your word to "usual" or smth else.

I have just adapted the wording in e238658. You can also use line comments to make the process of finding the issues you want to correct easier for me.

  1. I have some concerns about validation for "semicolon" , it is not clear from Check name that it will do that validation. .... let me think about this.

The idea of the check is to have easy manipulation of enums and clean diffs. If you have a semicolon on the line of the last enum constant, it won't work. I believe this check has to include this.

@romani
Copy link
Member

romani commented Aug 27, 2016

@kariem ,

Please follow the instructions

thanks a lot, but all of that is already adjusted and I use it when it necessary.
I need one commit to simplify my review, and be sure that I do not miss anything. I already tried all methods in github and I know way that work for me with minimum mistakes.
I do not care about our history of our discussion in PR.
Lets stop this discussion and please follow my recommendations to quickly accept your work.

Alternatively, as soon as there are no changes from your side, I can open another pull request with only one commit, if you prefer that.

no need in new PR, please do git changes and just do "git push --force" to your topic branch , PR will be refreshed and show your latest code.

It's in every commit on the last line

Sorry my bad, please do single line commit message. Prefix with ref to issue that I mentioned is required.

The idea of the check is to have easy manipulation of enums and clean diffs.

So we need to change a name of it.
If you name it EnumTrailingComma - it should care only about comma
if you name it XXXXXXCleanDif - it could demand from enum all to be for clean diff (single item per line, traling comma, no extra '';", ..... )

Checks if enum constant contains an optional trailing comma.

In brief description there should be short description of whole validation rule.
As we decide on Check name , there should be clear and brief explanation of it.

semicolon should be placed on a line by itself.

please make an example in javadoc of what is right format of enum.

@kariem
Copy link
Contributor Author

kariem commented Aug 29, 2016

[squash]

I understand and I will squash as soon as everything is accepted, so that you can merge with minimum mistakes. Until then, to view all changes, please click on the Files Changed Tab.

I hope you can see that it does not make sense for me to go through this on every commit. I perfectly understand that, as you say, you do not care about our history of discussion in the PR. In the end everything will just be as you prefer. Please also respect my time and efforts as I respect yours.

[Issue in commit message] Sorry my bad, please do single line commit message. Prefix with ref to issue that I mentioned is required.

Ok, I understand that. I will certainly do so on the squash.

So we need to change a name of it.
If you name it EnumTrailingComma - it should care only about comma
if you name it XXXXXXCleanDif - it could demand from enum all to be for clean diff (single item per line, traling comma, no extra '';", ..... )

The check cares about the comma and it should be the last element on the line. If there is a semicolon after the comma, the comma is not a trailing comma. Whatever the benefit of the check, we are checking the trailing comma, not a clean diff or an easy manipulation of the enum constants. Naming the check after potential benefits might be very difficult in the future and people might want to include indentation or even newline checks (both reasonable on a check named clean diff), which should not be part of this check.

On the other side, I strongly believe in consistent naming. The name is chosen based on the same functionality in ArrayTrailingComma (I have already referred to this in a previous comment). There cannot be any semicolons in an array, so every comparison at the level of "The ArrayTrailingComma check does not check for semicolons" is not helpful.

I want this change to eventually get to the Checkstyle project (see checkstyle/checkstyle#3161). We would then need to rename ArrayTrailingComma to ArrayCleanDiff and I will follow suite with renaming EnumTrailingComma. Also I would write "diff" (with double "f"), because this the more widely used word.

I will follow suite with items 3 (brief description of the whole validation rule) and 4 (example on semicolon placement) as soon as we agree on the above. It does not make sense to do something here the way I think is correct, if you don't agree.

@romani
Copy link
Member

romani commented Sep 1, 2016

I understand and I will squash as soon as everything is accepted, so that you can merge with minimum mistakes.

please squash it now.

I hope you can see that it does not make sense for me to go through this on every commit.

for you may be, but I need this to simplify my workflow, I have to do number of code review per day in project, I need help from you, to accept your code quicker.

Also I would write "diff" (with double "f"), because this the more widely used word.

sorry, it was my typo.

On the other side, I strongly believe in consistent naming.

hmm, let me review one more time in comparison with other Checks. Consistent naming is good but self-descriptive naming is better.

@romani
Copy link
Member

romani commented Sep 1, 2016

https://github.com/checkstyle/checkstyle/blob/master/src/main/java/com/puppycrawl/tools/checkstyle/checks/coding/ArrayTrailingCommaCheck.java this Check does not care about ";" , so for consistency of names and behavior please remove validation for ";" . If you need this validation , please create just another Check.

@romani
Copy link
Member

romani commented Sep 8, 2016

@kariem , is there any other thoughts , disagreements ?

@romani
Copy link
Member

romani commented Oct 19, 2016

@kariem , is there a chance to continue work on PR.
If no reply from you in next month, I will close this PR.

@romani
Copy link
Member

romani commented Oct 19, 2016

please squash all commits and update initial description and let me review (summary of all point) : request for changes and implementation one more time.
It will cost you 5 min. I do not remember all details of our discussion.

@kariem
Copy link
Contributor Author

kariem commented Oct 19, 2016

@romani Thank you for the quick reply. However, I don't think you are in a position to estimate how much time it takes me to do this: you have no information about how much time it took me to get here. On the other side, it seems you ignore the fact that everything we have discussed up to this point is in this pull request and it is not necessary for anyone to remember anything.

I will provide one commit and a clear description as soon as I can.

@romani
Copy link
Member

romani commented Oct 19, 2016

it seems you ignore the fact that everything we have discussed up to this point is in this pull request and it is not necessary for anyone to remember anything.

I see a problem that issue/pr is not done/merged. I see long history of conversations and points. We could keep it like this(in state of nobody want to read and ..... ) or we could start discussion from the begging with all our evidences of sense summed up.
You can always make a ref to this PR discussion in your new PR/Issue.

If you do not have time to continue, lets close PR , somebody else will find time to make it happen.

@kariem
Copy link
Contributor Author

kariem commented Oct 19, 2016

Good idea! I also thought, it might be better for everyone involved to create a new PR. I'll try to come around this later tonight.

kariem added a commit to kariem/sevntu.checkstyle that referenced this pull request Oct 20, 2016
This Check assures that the last enum constant definition in a multi-line enum ends in a comma:

    enum E1 {
        ONE,
        TWO,
        THREE,
    }

Original PR: sevntu-checkstyle#465

2016-07-29 -- 2016-08-26
@kariem
Copy link
Contributor Author

kariem commented Oct 20, 2016

@romani I've opened #474 and will close this. I have also checked Allow edits from maintainers in case there is something trivial you see needs changes.

I will also close this here, because everything is in one commit on the other PR.

@kariem kariem closed this Oct 20, 2016
kariem added a commit to kariem/sevntu.checkstyle that referenced this pull request Dec 4, 2016
This Check assures that the last enum constant definition in a multi-line enum ends in a comma:

    enum E1 {
        ONE,
        TWO,
        THREE,
    }

Original PR: sevntu-checkstyle#465

2016-07-29 -- 2016-08-26
kariem added a commit to kariem/sevntu.checkstyle that referenced this pull request Dec 4, 2016
This Check assures that the last enum constant definition in a multi-line enum ends in a comma:

    enum E1 {
        ONE,
        TWO,
        THREE,
    }

Original PR: sevntu-checkstyle#465

2016-07-29 -- 2016-08-26
kariem added a commit to kariem/sevntu.checkstyle that referenced this pull request Dec 4, 2016
kariem added a commit to kariem/sevntu.checkstyle that referenced this pull request Jul 26, 2018
kariem added a commit to kariem/sevntu.checkstyle that referenced this pull request Aug 2, 2018
kariem added a commit to kariem/sevntu.checkstyle that referenced this pull request Aug 2, 2018
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

4 participants