-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Fixes Metrics/CyclomaticComplexity #8149
Conversation
I was about to merge this and noticed that while this was counting # cop/style/empty_case_condition.rb
def on_case(case_node)
return if case_node.condition
return if case_node.when_branches.any? do |when_branch|
when_branch.each_descendant.any?(&:return_type?)
end
if (else_branch = case_node.else_branch)
return if else_branch.return_type? ||
else_branch.each_descendant.any?(&:return_type?)
end
add_offense(case_node, location: :keyword)
end I'm ok with this being counted as "complex". I couldn't help it and refactored it 😅. tangential: maybe |
670024f
to
ec5aa21
Compare
Howdy guys, you've recently introduced "pending" cops to reduce the risk of breaking pipelines and however you're updating the cyclo calculation that's my humor. 😄 I don't want to criticize the decision about the new default value (and how it's be fallen), but although it introduces "only" 5 changes for you guys, we have dozens of pipelines failing due to that change. And increasing the value even further to have less work is no option for us. |
I guess the problem here is that the changes were considered a bug-fixes, not a behaviour change (although they do change the behaviour). The new default itself is not a problem in itself, as it was actually relaxed, so for me the problem is how to communicate better bug-fixes that would probably result in broken pipelines. Sometimes we're aware that a breakage is likely to occur (e.g. in this case), but some things would be a surprise even to us. I'm not sure what's the best course of action here. |
@tonobo: Really sorry it's causing you trouble. I understand it can be frustrating to have code that previously was ok to now be causing offenses. I had hoped that this change would land in v1. Are you aware that Heads up: |
This PR fixes CyclomaticComplexity for
||=
,&&=
,&.
Blocks are tricky as some blocks clearly add to the complexity
Other builtin methods don't actually add to the cyclomatic
complexity, like
tap
,yield_self
,class_eval
, ...As @jonas054 pointed out, others methods in general can not be known.
This PR takes the conservative approach and counts only known iterating/conditional methods and ignores the rest.
If the default for CyclomaticComplexity remains at 6, there would be 34 new todos in the main gem.
If we bump it at 7, there are 5 new todos, 2 can be removed.
Bumping to 8 would have 1 new todo and 4 that would be removed.
I'm proposing to bump it to 7.