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

No correction for errors.details[:n] << v #741

Conversation

BrianHawley
Copy link
Contributor

@BrianHawley BrianHawley commented Jul 6, 2022

Fixes for Rails/DeprecatedActiveModelErrorsMethods:

  • Fixed a bad autocorrection of errors.details[:name] << value.
    There isn't really a correct replacement for this one.
  • Did some refactors prompted by rubocop complaints.
  • Fixed a misspelling of autocorrectable.
  • Added missing correction assertions to test cases.

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.
  • If this is a new cop, consider making a corresponding update to the Rails Style Guide.

@BrianHawley BrianHawley force-pushed the fix_rails_deprecated_active_model_errors_methods_20220706_2 branch from a5fa36d to cf2c8a5 Compare July 6, 2022 17:12
@BrianHawley
Copy link
Contributor Author

You can do errors.add(:name, value) as a replacement for errors.messages[:name] << value but there's no equivalent action for errors.details[:name] << value without including the message, so it seemed safer to not correct it.

Maybe we should add an example of a correction using errors.add to replace both changing the messages and details?

This can be done as a later doc PR, if need be.

@BrianHawley
Copy link
Contributor Author

@koic as requested.

@koic
Copy link
Member

koic commented Jul 8, 2022

@BrianHawley Can you rebase with the latest master branch?

@BrianHawley BrianHawley force-pushed the fix_rails_deprecated_active_model_errors_methods_20220706_2 branch from cf2c8a5 to c77b27b Compare July 8, 2022 16:16
@BrianHawley
Copy link
Contributor Author

@koic rebased.

Comment on lines 122 to 125
receiver = node.receiver.receiver
!AUTOCORRECTABLE_METHODS.include?(node.method_name) || (
receiver&.send_type? && receiver&.method?(:details) && node.method?(:<<)
)
Copy link
Member

Choose a reason for hiding this comment

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

That just my two cents. Can you tweak it?

Suggested change
receiver = node.receiver.receiver
!AUTOCORRECTABLE_METHODS.include?(node.method_name) || (
receiver&.send_type? && receiver&.method?(:details) && node.method?(:<<)
)
return true unless AUTOCORRECTABLE_METHODS.include?(node.method_name)
return false unless (receiver = node.receiver.receiver)
receiver.send_type? && receiver.method?(:details) && node.method?(:<<)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@koic sure, done.

Fixes for Rails/DeprecatedActiveModelErrorsMethods:
- Fixed a bad autocorrection of `errors.details[:name] << value`.
  There isn't really a correct replacement for this one.
- Did some refactors prompted by rubocop complaints.
- Fixed a misspelling of autocorrectable.
- Added missing correction assertions to test cases.
@BrianHawley BrianHawley force-pushed the fix_rails_deprecated_active_model_errors_methods_20220706_2 branch from c77b27b to d0a12a6 Compare July 9, 2022 14:44
@koic koic merged commit f44d616 into rubocop:master Jul 9, 2022
@koic
Copy link
Member

koic commented Jul 9, 2022

Thanks!

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

2 participants