Skip to content
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

Tweaks to Metrics/PerceivedComplexity #8204

Merged
merged 3 commits into from Jul 30, 2020

Conversation

marcandre
Copy link
Contributor

Metrics/PerceivedComplexity currently ignores else branches in case statement which seems like a clear bug, considering the weight if gives to else in if statements:

if foo
  bar
else
  baz
end
# counts for more than the equivalent:
case
when foo
  bar
else
  baz
end

For the rest, there's no clear definition of what PerceivedComplexity is supposed to do, but it sounds like it's the same thing as CyclomaticComplexity with a twist for case and if with else.

This PR fixes the else issue and makes the same changes that #8149 made for CyclomaticComplexity (||=, iterating methods, etc.) Default bumped also from 7 to 8. 3 new todos all of which are already CyclomaticComplexity todos.

If we're ok with these fixes, it would be best for v1 as it is breaking.

@marcandre marcandre added this to the 1.0.0 milestone Jun 23, 2020
CHANGELOG.md Outdated Show resolved Hide resolved
@marcandre
Copy link
Contributor Author

@jonas054 what do you think of this?

@bbatsov bbatsov requested a review from jonas054 July 6, 2020 05:26
Copy link
Collaborator

@jonas054 jonas054 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Sorry for the late reply.

@bbatsov
Copy link
Collaborator

bbatsov commented Jul 18, 2020

@marcandre Go ahead and merge this at your discretion.

@marcandre marcandre merged commit fab0e6d into rubocop:master Jul 30, 2020
@marcandre marcandre deleted the perceptioniseverything branch July 30, 2020 20:49
koic added a commit to rubocop/rubocop-rails that referenced this pull request Jul 30, 2020
Follow rubocop/rubocop#8204.

This commit suppresses the following RuboCop's offense.

```console
% bundle exec rubocop
(snip)

Offenses:

lib/rubocop/cop/rails/save_bang.rb:141:57: W:
Lint/RedundantCopDisableDirective: Unnecessary disabling of
Metrics/PerceivedComplexity.
        # rubocop:disable Metrics/CyclomaticComplexity,
        Metrics/PerceivedComplexity
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^

181 files inspected, 1 offense detected
RuboCop failed!
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants