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

Support filter in Rails/CompactBlank #1359

Conversation

masato-bkn
Copy link
Contributor

This PR modifies Rails/CompactBlank to support filter.
Since filter is an alias for select in both Array and Hash, I think it can be handled in the same way as select.


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.

@masato-bkn masato-bkn force-pushed the support-select-alias-methods-for-rails-compact-blank branch from 8622e08 to 12894ef Compare September 9, 2024 12:27
Comment on lines 125 to 129
if %i[reject select filter].include?(node.method_name)
'compact_blank'
else
'compact_blank!'
end
Copy link
Member

Choose a reason for hiding this comment

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

Can you make this a constant?

Suggested change
if %i[reject select filter].include?(node.method_name)
'compact_blank'
else
'compact_blank!'
end
DESTRUCTIVE_METHODS.include?(node.method_name) ? 'compact_blank!' : 'compact_blank'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for your feedback. I've fixed it!

@@ -44,7 +46,7 @@ class CompactBlank < Base
extend TargetRailsVersion

MSG = 'Use `%<preferred_method>s` instead.'
RESTRICT_ON_SEND = %i[reject delete_if select keep_if].freeze
RESTRICT_ON_SEND = %i[reject delete_if select filter keep_if].freeze
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
RESTRICT_ON_SEND = %i[reject delete_if select filter keep_if].freeze
RESTRICT_ON_SEND = %i[reject delete_if select filter keep_if].freeze
DESTRUCTIVE_METHODS = %i[delete_if keep_if].freeze

@masato-bkn masato-bkn force-pushed the support-select-alias-methods-for-rails-compact-blank branch from 12894ef to 9980211 Compare September 9, 2024 15:04
@koic koic merged commit 5fbb05d into rubocop:master Sep 9, 2024
14 checks passed
@koic
Copy link
Member

koic commented Sep 9, 2024

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.

2 participants