-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Add lambda support to indentation check #1548
Conversation
Thanks for the great update, just couple of things:
|
Thanks for the feedback. Addressed your comments. Only thing remaining is a cobertura coverage error. |
Current coverage is
|
The coverage is now fixed by removing an apparently superfluous branch :) I ran this against infinispan and it didn't crash (it had a zillion warnings/errors though). Let me know if there is anything else that is blocking this from going in. |
Hi folks, |
Most likely at the end of September, we will not have time to review and test till end of August |
@mkordas , can you finish code-review for this PR? |
@pietern , sorry for delay , please rebase your PR over latest code we are about to start reviewing your code. |
import com.puppycrawl.tools.checkstyle.api.DetailAST; | ||
|
||
/** | ||
* Handler for lambda statements. |
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.
more common is to say lambda expressions
instead of lambda statements
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.
You're right, I started out with a copy of one of the other handlers.
Thank you for reviewing. Addressing the comments in a new commit. |
x.run(); //indent:10 exp:10 | ||
}); //indent:8 exp:8 | ||
|
||
SomeInterface i1 = (LongTypeName //indent:4 exp:4 |
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 don't see any declaration of SomeInterface
- please make input compilable in Java 8.
Please use src/test/resources-noncompilable/com/puppycrawl/tools/checkstyle/coding/InputReturnCountLambda.java as a source of ideas for some more complicated lambdas. For example these are valid lambdas: Supplier<Supplier<Integer>> lambdas() {
return (
)
->
(
)
->
1
; |
@pietern, did you have time to work on this PR? |
@mkordas I incorporated your comments, added some more test cases where the lambda's argument list or the lambda token itself needs to be indented, and rebased on top of master. |
Thanks @pietern, I'll look into it shortly. |
@pietern |
Working on the infinispan test cases. |
One thing we should clearly understand: I am completely ok to merge and release non complete lambda support, but I am NOT ok if we introduce violations on code that does not have lambda at all (majority of projects still use jdk6, jdk7). incomplete Lambda support:
So lets focus on non-lambda false positives ! lets test project that do not have lambda at all, and if reports(before/after) are the same we are ok to merge. |
@romani Sounds good to me :) Still looking why the infinispan method def modifier triggers a warning. The others can be attributed to inconsistent line continuation indenting in that repository; sometimes they use 6, other times they use 8. I used 6 in my configuration, so this triggers a warning for 8. Notice that since this is a new check, it will always produce new warnings of this type (lambda arguments). I pushed a new change with the inspections fixed. |
@romani With the latest change we should be good on not breaking existing code. I expanded the set of allowed indentations for children to include line wrapping (which is what was originally intended, over basic indenting, it looks like) and line wrapping based on the parent's suggested level if the right paren is the first on the line. Both additions are tested in the lambda test input files (because it seems the lambda is one of the few that checks the indentation of the arguments, which applies in method call arguments as well). This addresses some of the lambda false positives that @mkordas mentioned for protonpack. For the method call handler diff, see: 2224d1e#diff-77dfb9ce50cfab374af2799f71e68cfb I pushed the new reports and this is the summarized result:
|
Regarding the infinispan method def warning: these were caused by restricting the set of allowed indentations for children in the method call handler. I updated this to allow more than it allowed before, so it shouldn't happen anymore. |
@pietern , please generate reports(before/after) on projects that do not have lambda's (hibernate, jdk7, spring) and confirm that there are no difference in reports. @mkordas , please confirm that violations for RxJava and protonpack are valid. I will review 'infinispan'. As all of us confirm that results are good - I will merge this PR (I can even trigger release 6.11.1 as to speed up testing of this by community). All false positives in Lambda that we still have should be posted as comments to issue, issue is not going to be closed for now. |
@romani Sounds good. Is the broadened set of acceptable indentations acceptable to you? I expect this to be the only material difference in the reports before/after this change, since it applies to all method calls. |
Please give me example, i do not understand you |
@romani I confirm that both protonpack and RxJava reports look really well. I haven't noticed anything suspicious. All changes are expected and beneficial for the check. |
I updated my #1548 (comment) with list of false-positives at Lambda support. I did not noticed any other serious changes that could block merge. @pietern , please confirm your part of validation. |
@romani Re: the broadened set of acceptable indentations: that Some more results for this change:
The fewer number of warnings in spring is caused by a few of lambdas in the code base that are now correctly checked. I checked the diff for hibernate and the warnings are identical. The only difference is that there is one method call with indented arguments where more indentation levels are acceptable, if you look at the diff of |
@romani I reviewed the false positives you listed for infinispan, but the first three of them are actually real positives; the code base has mixed use of 6 and 8 characters for line continuation. I ran the test with 6 (given that the basic offset is 3), which explains a few of the false positives for cases where 8 is used. |
@pietern , please copy paste each false-positive and by trailing comments describe how much spaces code have and what is expected and what is configuration. Any general talk about indentation will never succeeded. |
Configuration for infinispan: http://pietern.github.io/checkstyle-reports/lambda-1548/check_infinispan.xml
|
merged as FF |
not finished discussion is moved to #281 |
Great news, thanks @romani ! |
Changes Unknown when pulling 2224d1e on pietern:lambdas into ** on checkstyle:master**. |
This is a first pass for lambda support in the indentation check. All unit and integration tests pass. The test case is based on the test case in this branch: master...pirat9600q:IndentationCheck_issue281. Not all cases will be covered in this commit, but at least it's a start. I ran checkstyle against a codebase I'm working on and all the lambda related warnings disappear with this commit.
Also see #281.