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

Rails/CompactBlank cop gets triggered by reject that calls blank? on unrelated object #626

Closed
chrkau opened this issue Jan 12, 2022 · 0 comments · Fixed by #627
Closed
Labels
bug Something isn't working

Comments

@chrkau
Copy link

chrkau commented Jan 12, 2022

Consider the following code snippet:

def foo(bar = nil)
  [1].reject { |_| bar.blank? }
end

As far as I can see reject cannot be replaced with compact_blank here as the rejection condition relates to a different object (bar).


Expected behavior

This should not trigger the Rails/CompactBlank cop.

Actual behavior

It does trigger the Rails/CompactBlank cop.

Steps to reproduce the problem

See provided code snippet.

RuboCop version

1.24.1 (using Parser 3.1.0.0, rubocop-ast 1.15.1, running on ruby 3.0.3 x86_64-darwin19)
  - rubocop-rails 2.13.1
  - rubocop-rspec 2.7.0
@koic koic added the bug Something isn't working label Jan 12, 2022
koic added a commit to koic/rubocop-rails that referenced this issue Jan 12, 2022
Fixes rubocop#626.

Fix a false positive for `Rails/CompactBlank` when using the receiver
of `blank?` is not a block variable.
koic added a commit to koic/rubocop-rails that referenced this issue Jan 12, 2022
Fixes rubocop#626.

Fix a false positive for `Rails/CompactBlank` when using the receiver
of `blank?` is not a block variable.
@koic koic closed this as completed in #627 Jan 12, 2022
koic added a commit that referenced this issue Jan 12, 2022
…t_blank

[Fix #626] Fix a false positive for `Rails/CompactBlank`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants