SONARPY-186 Rule: Cognitive Complexity of functions should not be too high#74
SONARPY-186 Rule: Cognitive Complexity of functions should not be too high#74ivandalbosco merged 6 commits intomasterSonarSource/sonar-python:masterfrom
Conversation
7137009 to
3b1e0bb
Compare
3b1e0bb to
2857ae7
Compare
There was a problem hiding this comment.
@vilchik-elena com.sonar.sslr.impl.ast.AstWalker is not part of the public API of SSLR. However, I'm not sure that there's another way to have "secondary" visitors.
There was a problem hiding this comment.
@vilchik-elena I would prefer to have a dedicated test file for the default threshold where we have one function exactly on the "max value" and one function which is the almost the same but has "max value + 1".
There was a problem hiding this comment.
@vilchik-elena I'm not sure it would work but another approach would seem more natural to me. Instead of nestingLevelByNode, I would have a nestingLevel field which is incremented when entering a SUITE and decremented when leaving the SUITE (but not in try: SUITE).
41b0da4 to
6b97599
Compare
6b97599 to
25eda06
Compare
| except SomeError1: # +1 (nesting level +1) | ||
| if condition: # +2 | ||
| pass | ||
| except SomeError2: # +1 (nesting level +1) |
There was a problem hiding this comment.
@vilchik-elena How about explicitly testing multiple exceptions, as in
except (SomeError2, SomeError3): #+1
| return "+1"; | ||
|
|
||
| } else{ | ||
| return String.format("+%s (incl %s for nesting)", complexity, complexity - 1); |
There was a problem hiding this comment.
@vilchik-elena Can we test this secondary message? It is currently not done in the test file
There was a problem hiding this comment.
@ivandalbosco No, it's not implemented in python, I've tested line numbers only
No description provided.