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

Ignore ENV.update calls in Rails/SaveBang #248

Merged
merged 1 commit into from
May 25, 2020
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

* [#12](https://github.com/rubocop-hq/rubocop-rails/issues/12): Fix a false positive for `Rails/SkipsModelValidations` when passing a boolean literal to `touch`. ([@eugeneius][])
* [#238](https://github.com/rubocop-hq/rubocop-rails/issues/238): Fix auto correction for `Rails/IndexBy` when the `.to_h` invocation is separated in multiple lines. ([@diogoosorio][])
* [#248](https://github.com/rubocop-hq/rubocop-rails/pull/248): Fix a false positive for `Rails/SaveBang` when `update` is called on `ENV`. ([@eugeneius][])

### Changes

Expand Down
1 change: 1 addition & 0 deletions lib/rubocop/cop/rails/save_bang.rb
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ def checked_immediately?(node)

def allowed_receiver?(node)
return false unless node.receiver
return true if node.receiver.const_name == 'ENV'
return false unless cop_config['AllowedReceivers']

cop_config['AllowedReceivers'].any? do |allowed_receiver|
Expand Down
4 changes: 4 additions & 0 deletions spec/rubocop/cop/rails/save_bang_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -607,4 +607,8 @@ def find_or_create(**opts)
it 'properly ignores lvasign without right hand side' do
expect_no_offenses('variable += 1')
end

it 'ignores update when called on ENV' do
expect_no_offenses('ENV.update("DISABLE_SPRING" => "1")')
end
end