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

Make Style/RedundantFreeze aware of methods that will produce frozen objects #6784

Merged
merged 2 commits into from
Mar 17, 2019

Conversation

rrosenblum
Copy link
Contributor

This was extract out of the PR to add strict mode to Style/MutableConstants, #6126. This isn't an exhaustive list of methods that return immutable values, but it is at least a start.

@rrosenblum rrosenblum force-pushed the redundant_freeze_immutable_methods branch from 8488665 to 35514db Compare February 20, 2019 20:45
config/default.yml Outdated Show resolved Hide resolved
@rrosenblum rrosenblum force-pushed the redundant_freeze_immutable_methods branch 3 times, most recently from a8d4461 to 01fea6b Compare February 26, 2019 14:53
@rrosenblum rrosenblum force-pushed the redundant_freeze_immutable_methods branch 2 times, most recently from 47fe73e to d4d5835 Compare March 8, 2019 19:11
CHANGELOG.md Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
@rrosenblum rrosenblum force-pushed the redundant_freeze_immutable_methods branch 2 times, most recently from 4c1efb1 to 639e255 Compare March 11, 2019 13:34
@rrosenblum rrosenblum force-pushed the redundant_freeze_immutable_methods branch from 639e255 to a15269b Compare March 11, 2019 13:35
@bbatsov bbatsov merged commit 0161216 into rubocop:master Mar 17, 2019
@rrosenblum rrosenblum deleted the redundant_freeze_immutable_methods branch March 18, 2019 23:54
casperisfine pushed a commit to casperisfine/rubocop that referenced this pull request Sep 22, 2021
Ref: rubocop#6784

`ENV["foo"]` returns a mutable string.

```ruby
>> ENV["PATH"].frozen?
=> true
>> ENV["PATH"].object_id
=> 260
>> ENV["PATH"].object_id
=> 280
```

As such it's perfectly legitimate to freeze them in a pattern such as:

```ruby
PATH = ENV["PATH"].freeze
```
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.

None yet

3 participants