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 #7023] Added auto-correction for Lint/NumberConversion #7054

Merged
merged 1 commit into from
May 17, 2019
Merged

[Fix #7023] Added auto-correction for Lint/NumberConversion #7054

merged 1 commit into from
May 17, 2019

Conversation

Bhacaz
Copy link
Contributor

@Bhacaz Bhacaz commented May 16, 2019

Fix #7023, Added auto-correction for Lint/NumberConversion


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.

Copy link
Member

@Darhazer Darhazer left a comment

Choose a reason for hiding this comment

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

Thank you for your contribution. I've left a few minor comments

@@ -108,4 +108,55 @@
RUBY
end
end

context 'autoccorrection' do
Copy link
Member

Choose a reason for hiding this comment

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

you can add expect_correction() to the existing offending examples

Copy link
Contributor Author

@Bhacaz Bhacaz May 17, 2019

Choose a reason for hiding this comment

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

It's indeed more elegant.

@@ -1463,6 +1463,7 @@ Lint/NumberConversion:
Description: 'Checks unsafe usage of number conversion methods.'
Enabled: false
VersionAdded: '0.53'
SafeAutoCorrect: false
Copy link
Member

Choose a reason for hiding this comment

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

You need to set the VersionChanged on the cop

lambda do |corrector|
to_method(node) do |receiver, _to_method|
corrector.replace(node.loc.expression,
correct_method(node, receiver))
Copy link
Member

Choose a reason for hiding this comment

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

you can just use node.receiver and skip the to_method matching, but I'm fine with your approach as well

@@ -1463,6 +1463,8 @@ Lint/NumberConversion:
Description: 'Checks unsafe usage of number conversion methods.'
Enabled: false
VersionAdded: '0.53'
VersionChanged: '0.69'
Copy link
Member

Choose a reason for hiding this comment

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

it would be 0.70 the actual release

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My bad.

@bbatsov bbatsov merged commit 7cf638c into rubocop:master May 17, 2019
@bbatsov
Copy link
Collaborator

bbatsov commented May 17, 2019

Thanks!

@Bhacaz Bhacaz deleted the autocorrect_lint_number_conversion branch May 17, 2019 16:22
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.

Autocorrection for Lint/NumberConversion
3 participants