Skip to content

Commit

Permalink
Merge pull request #248 from eugeneius/save_bang_env
Browse files Browse the repository at this point in the history
Ignore ENV.update calls in Rails/SaveBang
  • Loading branch information
koic authored May 25, 2020
2 parents 56014ca + 63b94e5 commit bd44759
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
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

0 comments on commit bd44759

Please sign in to comment.