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

Ruby 3.0's Regexp and Range literals will be frozen #9282

Merged
merged 1 commit into from
Dec 23, 2020

Conversation

koic
Copy link
Member

@koic koic commented Dec 23, 2020

This PR makes Style/RedundantFreeze and Style/MutableConstant cops aware of frozen regexp and range literals when using Ruby 3.0.

% ruby -ve 'p(/regexp/.frozen?); p (0..42).frozen?'
ruby 3.0.0dev (2020-12-23T03:25:41Z master 02233ed024) [x86_64-darwin19]
true
true
% ruby -ve 'p(/regexp/.frozen?); p (0..42).frozen?'
ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-darwin19]
false
false

Before submitting the PR make sure the following are checked:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Ran bundle exec rake default. It executes all tests and runs RuboCop on its own code.
  • Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.

This PR makes `Style/RedundantFreeze` and `Style/MutableConstant` cops aware of
frozen regexp and range literals when using Ruby 3.0.

- https://bugs.ruby-lang.org/issues/15504
- https://bugs.ruby-lang.org/issues/16377

```console
% ruby -ve 'p(/regexp/.frozen?); p (0..42).frozen?'
ruby 3.0.0dev (2020-12-23T03:25:41Z master 02233ed024) [x86_64-darwin19]
true
true
```

```console
% ruby -ve 'p(/regexp/.frozen?); p (0..42).frozen?'
ruby 2.7.2p137 (2020-10-01 revision 5445e04352) [x86_64-darwin19]
false
false
```
@koic koic force-pushed the frozen_ragexp_and_range_literals branch from 90ca872 to c7a1a65 Compare December 23, 2020 07:51
@koic
Copy link
Member Author

koic commented Dec 23, 2020

Thanks for the reviews! I updated this PR.

@bbatsov bbatsov merged commit db095f9 into rubocop:master Dec 23, 2020
@bbatsov
Copy link
Collaborator

bbatsov commented Dec 23, 2020

Thanks! 🙇‍♂️

@koic koic deleted the frozen_ragexp_and_range_literals branch December 23, 2020 09:16
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.

3 participants