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 #6914] Fix an error for Rails/RedundantAllowNil when with interpolations #6916

Merged
merged 1 commit into from Apr 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,10 @@

## master (unreleased)

### Bug fixes

* [#6914](https://github.com/rubocop-hq/rubocop/issues/6914): [Fix #6914] Fix an error for `Rails/RedundantAllowNil` when with interpolations. ([@Blue-Pix][])

### Changes

* [#5977](https://github.com/rubocop-hq/rubocop/issues/5977): Remove Performance cops. ([@koic][])
Expand Down Expand Up @@ -3929,3 +3933,4 @@
[@anuja-joshi]: https://github.com/anuja-joshi
[@XrXr]: https://github.com/XrXr
[@thomthom]: https://github.com/thomthom
[@Blue-Pix]: https://github.com/Blue-Pix
6 changes: 3 additions & 3 deletions lib/rubocop/cop/rails/redundant_allow_nil.rb
Expand Up @@ -79,10 +79,10 @@ def find_allow_nil_and_allow_blank(node)
node.each_descendant do |descendant|
next unless descendant.pair_type?

key = descendant.children.first.value
key = descendant.children.first.source

allow_nil = descendant if key == :allow_nil
allow_blank = descendant if key == :allow_blank
allow_nil = descendant if key == 'allow_nil'
allow_blank = descendant if key == 'allow_blank'

break if allow_nil && allow_blank
end
Expand Down
8 changes: 8 additions & 0 deletions spec/rubocop/cop/rails/redundant_allow_nil_spec.rb
Expand Up @@ -73,4 +73,12 @@
RUBY
end
end

context 'when using string interpolation' do
it 'registers no offense' do
expect_no_offenses(<<-'RUBY'.strip_indent)
validates :details, "path_to_dynamic_validation/#{with_interpolation}": true
RUBY
end
end
end