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 #454] Fix false positives for Performance/BigDecimalWithNumericArgument #463

Conversation

koic
Copy link
Member

@koic koic commented Sep 6, 2024

Fixes #454.

This PR fixes false positives for Performance/BigDecimalWithNumericArgument when using BigDecimal 3.1+.

The bad and good examples for this cop are reversed between BigDecimal 3.0 and 3.1.

Since BigDecimal 3.1 is the default gem in Ruby 3.1, this PR reverses the bad and good examples when targeting Ruby 3.1+. So, the goal of this PR is to address many cases where the meaning was entirely reversed.

To avoid introducing excessive complexity related to version dependencies, detection is disabled for Ruby 3.0 and below.

Ideally, a solution that prioritizes the BigDecimal version would be best in the future, but this PR does not take that into account.


Before submitting the PR make sure the following are checked:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • 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.
  • Ran bundle exec rake default. It executes all tests and runs RuboCop on its own code.
  • Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.

…NumericArgument`

Fixes rubocop#454.

This PR fixes false positives for `Performance/BigDecimalWithNumericArgument` when using BigDecimal 3.1+.

The bad and good examples for this cop are reversed between BigDecimal 3.0 and 3.1.

Since BigDecimal 3.1 is the default gem in Ruby 3.1, this PR reverses the bad and good examples when targeting Ruby 3.1+.
So, the goal of this PR is to address many cases where the meaning was entirely reversed.

To avoid introducing excessive complexity related to version dependencies, detection is disabled for Ruby 3.0 and below.

Ideally, a solution that prioritizes the BigDecimal version would be best in the future, but this PR does not take that into account.
class BigDecimalWithNumericArgument < Base
extend AutoCorrector
extend TargetRubyVersion

minimum_target_ruby_version 3.1
Copy link
Contributor

@Earlopain Earlopain Sep 6, 2024

Choose a reason for hiding this comment

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

Can you use requires_gem API here? bigdecimal is becoming a bundled gem so many already have it in their lockfile and the ruby version is barely relevant anymore. This would stop this cop from doing something if the user doesn't use bundler, or for those who somehow don't have it in their lockfile yet but I think this is the way to go

Copy link
Member Author

Choose a reason for hiding this comment

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

Ideally, a solution that prioritizes the BigDecimal version would be best in the future, but this PR does not take that into account.

As the testing methodology for that approach doesn't seem to be established, it is not included in this PR. The focus is currently on resolving the more common cases.

Copy link
Contributor

Choose a reason for hiding this comment

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

Ah, right. You already meant requires_gem wit with that

@koic koic merged commit 0f401f7 into rubocop:master Sep 7, 2024
14 checks passed
@koic koic deleted the fix_false_positives_for_performance_big_decimal_with_numeric_argument branch September 7, 2024 19:53
koic added a commit that referenced this pull request Sep 7, 2024
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.

Correcting Performance/BigDecimalWithNumericArgument offences leads to slower code
2 participants