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

Add new Lint/BigDecimalNew cop #5248

Merged
merged 1 commit into from
Dec 28, 2017

Conversation

koic
Copy link
Member

@koic koic commented Dec 14, 2017

Feature

BigDecimal.new() is deprecated since BigDecimal 1.3.3 for Ruby 2.5.
This cop identifies places where BigDecimal.new() can be replaced by BigDecimal().

% cat /tmp/example.rb
# frozen_string_literal: true

BigDecimal.new(123.456, 3)
% rubocop /tmp/example.rb
Inspecting 1 file
W

Offenses:

/tmp/example.rb:3:12: W: Lint/BigDecimalNew: BigDecimal.new() is deprecated. Use BigDecimal() instead.
BigDecimal.new(123.456, 3)
           ^^^

1 file inspected, 1 offense detected

I have verified that these methods can be replaced using the lowest
Ruby version 2.1 supported by RuboCop.

% ruby -v
ruby 2.1.10p492 (2016-04-01 revision 54464) [x86_64-darwin13.0]
% gem list | grep bigdecimal
bigdecimal (default: 1.2.4)
% ruby -rbigdecimal -e 'p BigDecimal(123.456, 3) == BigDecimal.new(123.456, 3)'
true

Other Information

The following is a change of BigDecimal 1.3.3 for Ruby 2.5 related to this PR.


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 rake default or rake parallel. It executes all tests and RuboCop for itself, and generates the documentation.

@koic koic force-pushed the add_new_lint_big_decimal_new_cop branch from ef70133 to 31ec733 Compare December 14, 2017 07:13
@koic
Copy link
Member Author

koic commented Dec 14, 2017

I saw this change at rails/rails#31435.

@pocke
Copy link
Collaborator

pocke commented Dec 14, 2017

BTW, I think we should ship v0.52.1, that is a bug fix release. And the release should not contain any new features. So we need to wait merging this pull-request until we ship the release.
What do you think? @bbatsov

@garettarrowood
Copy link
Contributor

This looks like it'd be a good check to add to Lint/DeprecatedClassMethods, perhaps instead of adding a new cop.

@koic
Copy link
Member Author

koic commented Dec 15, 2017

Thanks for the review. I have worries. BigDecimal is not a standard library, it is a default gems managed by ruby/bigdecimal repo.

% gem list | grep default
bigdecimal (default: 1.3.2)
(snip)

I don't know whether it is preferable to change configuration in the same lifecycle as Lint/DeprecatedClassMethods cop.

Of course, as a practical use case, I think that there is no need to make an independent configuration change, so adding it to Lint/DeprecatedClassMethods is an approach.

@bbatsov
Copy link
Collaborator

bbatsov commented Dec 15, 2017

BTW, I think we should ship v0.52.1, that is a bug fix release. And the release should not contain any new features. So we need to wait merging this pull-request until we ship the release.
What do you think? @bbatsov

I agree. That was my plan as well - do a bugfix release over the weekend or early next week. Unfortunately I'll be super busy until Tuesday.

@koic koic force-pushed the add_new_lint_big_decimal_new_cop branch 2 times, most recently from a7634a0 to d02b60b Compare December 15, 2017 12:55
@pocke pocke mentioned this pull request Dec 27, 2017
8 tasks
@bbatsov
Copy link
Collaborator

bbatsov commented Dec 27, 2017

Please, rebase on top of the current master.

@koic koic force-pushed the add_new_lint_big_decimal_new_cop branch from d02b60b to 17aeedc Compare December 28, 2017 05:38
@koic
Copy link
Member Author

koic commented Dec 28, 2017

Thanks. I did rebase.

## Feature

`BigDecimal.new()` is deprecated since BigDecimal 1.3.3 for Ruby 2.5.
This cop identifies places where `BigDecimal.new()` can be replaced by `BigDecimal()`.

```console
% cat /tmp/example.rb
# frozen_string_literal: true

BigDecimal.new(123.456, 3)
```

```console
% rubocop /tmp/example.rb
Inspecting 1 file
W

Offenses:

/tmp/example.rb:3:12: W: Lint/BigDecimalNew: BigDecimal.new() is deprecated. Use BigDecimal() instead.
BigDecimal.new(123.456, 3)
           ^^^

1 file inspected, 1 offense detected
```

I have verified that these methods can be replaced using the lowest
Ruby version 2.1 supported by RuboCop.

```console
% ruby -v
ruby 2.1.10p492 (2016-04-01 revision 54464) [x86_64-darwin13.0]
% gem list | grep bigdecimal
bigdecimal (default: 1.2.4)
% ruby -rbigdecimal -e 'p BigDecimal(123.456, 3) == BigDecimal.new(123.456, 3)'
true
```

## Other Information

The following is a change of BigDecimal 1.3.3 for Ruby 2.5 related to this PR.

- ruby/bigdecimal@5337373
- ruby/bigdecimal@16738ad
This was referenced Mar 21, 2018
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.

4 participants