Repository navigation
[java] Cognitive Complexity Metric - #3293
Merged
oowekyala merged 25 commits intoMay 28, 2021
Merged
Conversation
borovikovd
force-pushed
the
java-cognitive-complexity-rule
branch
3 times, most recently
from
May 23, 2021 18:59
5ab2f0f to
1e3c4a3
Compare
oowekyala
self-requested a review
May 23, 2021 18:59
borovikovd
force-pushed
the
java-cognitive-complexity-rule
branch
from
May 23, 2021 19:00
1e3c4a3 to
3de7481
Compare
oowekyala
reviewed
May 24, 2021
oowekyala
left a comment
Member
There was a problem hiding this comment.
Hi, thanks for your contribution! The metric looks fine, however, it should also have tests and documentation.
For tests:
- create a test rule on the model of eg LocTestRule
- register it in the test ruleset and the test class
- Create a test file in this directory, eg you can start with the test file for your rule
For documentation, please add a section to this file
oowekyala
reviewed
May 24, 2021
oowekyala
reviewed
May 26, 2021
Generated by 🚫 Danger |
oowekyala
reviewed
May 26, 2021
oowekyala
reviewed
May 26, 2021
Contributor
Author
|
@oowekyala any more comments?:) |
Member
|
@borovikovd No I think this looks fine. Thanks for your diligence on this! If @adangel doesn't have any objections, I'll fix the outstanding conversation and merge this tomorrow, to include it in pmd 6.35.0. |
adangel
approved these changes
May 27, 2021
adangel
left a comment
Member
There was a problem hiding this comment.
@borovikovd Thanks for working on this, looks great!
Co-authored-by: Andreas Dangel <[email protected]>
Co-authored-by: Andreas Dangel <[email protected]>
Co-authored-by: Andreas Dangel <[email protected]>
oowekyala
added a commit
that referenced
this pull request
May 28, 2021
oowekyala
added a commit
that referenced
this pull request
May 28, 2021
oowekyala
added a commit
that referenced
this pull request
May 28, 2021
Member
|
merged, thanks again @borovikovd |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Describe the PR
This PR implements a Cognitive Complexity metric for Java. The work is based on a similar metric for Apex language: https://pmd.github.io/pmd/pmd_rules_apex_design.html#cognitivecomplexity. Tests and implementation have been ported + some additional modification have been done:
Accordingly to the spec, we should increase nesting level for such structures but structural complexity should stay the same (see
state.increaseNestingLevelWithoutStructuralComplexitymethod).Notes
ASTIfStatementhandling seems to be a bit convoluted but it's due to the way how java AST parser handleselse if- it's both one of the blocks of the parentifand a newASTIfStatementat the same time.Also, a method call handling is a bit tricky since there is no separate java node for this case and I had to do a bunch of checks in
ASTPrimaryPrefixcallback.I hope this PR can be integrated quickly since we really want to start using this metric in our Java projects on regular basis :)
Related issues
Ready?
./mvnw clean verifypasses (checked automatically by github actions)