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

[Fix #165] Fix a false positive for Performance/Sum #166

Merged
merged 1 commit into from Sep 5, 2020

Conversation

koic
Copy link
Member

@koic koic commented Sep 5, 2020

Fixes #165.

This PR fixes a false positive for Performance/Sum when using initial value argument is a variable.


Before submitting the PR make sure the following are checked:

  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Added an entry to the Changelog if the new code introduces user-observable changes. See changelog entry format.
  • The PR relates to only one subject with a clear title
    and description in grammatically correct, complete sentences.
  • Run bundle exec rake default. It executes all tests and RuboCop for itself, and generates the documentation.

@@ -98,7 +98,7 @@ def build_good_method(init)

unless init.empty?
init = init.first
good_method += "(#{init.source})" if init.source.to_i != 0
good_method += "(#{init.source})" unless init.int_type? && init.source.to_i.zero?
Copy link
Contributor

Choose a reason for hiding this comment

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

init.source.to_i.zero? => init.value.zero?

Copy link
Member Author

Choose a reason for hiding this comment

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

It's definitely simple. Thank you for your review!

Fixes rubocop#165.

This PR fixes a false positive for `Performance/Sum`
when using initial value argument is a variable.
@koic koic force-pushed the fix_false_positive_for_performance_sum branch from 9a6654a to 61578d9 Compare September 5, 2020 19:07
@koic koic merged commit a117b59 into rubocop:master Sep 5, 2020
@koic koic deleted the fix_false_positive_for_performance_sum branch September 5, 2020 19:19
@mvz
Copy link
Contributor

mvz commented Sep 6, 2020

Thanks, @koic!

@koic
Copy link
Member Author

koic commented Sep 6, 2020

@mvz You are welcome. Thank you for your feedback!

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.

Autocorrect for Performance/Sum drops initial value if it is not a number literal
3 participants