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
Add a Strict mode to Style/MutableConstants #6126
Conversation
2221cac
to
c73d470
Compare
bf73414
to
38e0ca6
Compare
@bbatsov this is ready for review. |
38e0ca6
to
bdfcae5
Compare
@rrosenblum Sorry about the slow-turnaround here. Overall it seems like a good change to me, but I've added a few inline comments. |
Thanks for the feedback. I'll try to setup some rules for the comments that you made. |
42cac6d
to
89c8f93
Compare
94cb6ae
to
cb4f184
Compare
7953c19
to
de484d8
Compare
99b40b5
to
abdd447
Compare
abdd447
to
cb5b68d
Compare
@rrosenblum Looking good. If we can fix the false positive for heredocs, I think this is good enough to merge as an experimental feature. 🙂 |
cb5b68d
to
d307042
Compare
59dbdb3
to
6febf1a
Compare
I removed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’m okay with this, with some small nits. Letting @koic make the final call. 🚀
end | ||
|
||
def requires_parentheses?(node) | ||
node.irange_type? || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there is a good case for adding Node#range_type?
, but that could be considered out of scope for this change. 🙂
@@ -23,6 +23,11 @@ | |||
it_behaves_like 'immutable objects', '1.5' | |||
it_behaves_like 'immutable objects', ':sym' | |||
it_behaves_like 'immutable objects', ':""' | |||
it_behaves_like 'immutable objects', "ENV['foo']" | |||
it_behaves_like 'immutable objects', "'foo'.count" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
String
object does not have count
method, does this mean String#size
or String#length
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
String
does support count
. Without arguments it works like size
and length
. It can take a parameter of a pattern to count.
Several reviews by @Drenmi are left, but dc3631d in other points looks good to me 🌟 |
6febf1a
to
845b570
Compare
845b570
to
b1bcd44
Compare
b1bcd44
to
5508fd1
Compare
This looks good! Thanks @rrosenblum. |
Follow up of rubocop#6126 (comment). This PR adds `range_type?` method which means both `irange_type?` method and `erange_type?` method.
This has been something that I have wanted to do for a while. Right now, we only freeze literals that are assigned to constants. This leaves many constants unfrozen and therefore potentially unsafe.
I consider this to be experimental functionality. I'm not sure how many other people would be interested in this feature. I think I have all of the main use cases covered. I am trying to account for any edge cases now.
Something interesting that I learned from this is that concatenating frozen strings produces an unfrozen string.