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
Please add option to ignore safe navigation in Metrics/CyclomaticComplexity #8276
Comments
I'm sorry the multiple adjustments to this metric is causing you issues. Could please you update your example to reflect better your usecase? In particular, your example has 5 times the same key definitely not what you intended, which makes it difficult to know if you actually intended the 5 repetitions of the same |
Sorry, done. |
Thanks, so much better 😄 I feel that if you used a local variable One interesting point is the successive I'll quote @jonas054 :
The fact that you have these I don't know what others think about this... |
True. But going from 11 to 8 is still going to make the cop fail 😉
Yes, in our app that's how we distinguish people who have not been given any special permission (instead of an "empty" role).
That would be nicer, indeed. |
Yes. Based on your detailed explanation, @marcandre, that makes a lot of sense. |
Great. Now I wonder: setting on or off by default? |
I think that without a setting it is ok to count |
Implemented 🎉 I'm very satisfied with this solution. It requires no config, provides a justifiable discount for repeated In the example above, it discounts 6 of the 7 uses of @fsateler : thank you for opening this issue and providing your real-life example! This will improve the CyclomaticComplexity metric, as well as PreceivedComplexity and AbcSize. |
Now counts correctly ||=, &&=, multiple assignments, for, yield, iterating blocks. All &. count as a condition, unless it's on a repeated and unchanged lvar [see rubocop#8276]
Now counts correctly ||=, &&=, multiple assignments, for, yield, iterating blocks. All &. count as a condition, unless it's on a repeated and unchanged lvar [see #8276]
…ted uses of &. on same lvar receiver
Is your feature request related to a problem? Please describe.
With rubocop 0.86, CyclomaticComplexity now considers the safe navigation operator. Unfortunately, this makes some mapper code particularly prone to hitting the limit:
This method has a cyclomatic complexity of 11, where previously it was 0.
Describe the solution you'd like
An option that when set, restores the pre-0.86 behavior of not considering the safe navigation.
Describe alternatives you've considered
Disabling the cop altogether is not optimal, because it sets limits for how var can methods grow.
The text was updated successfully, but these errors were encountered: