-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
[Fix #12271] Fix a false positive for Lint/RedundantSafeNavigation
#12272
[Fix #12271] Fix a false positive for Lint/RedundantSafeNavigation
#12272
Conversation
f3bd8b8
to
864c14e
Compare
# Use cases where a constant is `nil` are rare and an offense is detected | ||
# when the receiver is a constant. | ||
# Use cases where a constant, named in camel case for classes and modules is `nil` are rare, | ||
# and an offense is detected when the receiver is a snake case constant. |
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 you meant to write "is not detected" here.
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.
Ah, you mean to target just SCREAMING_SNAKE_CASE
. I see.
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.
Oops! I've updated the text.
Frankly, I'm not sure what's the best course of action here, as I don't understand why anyone would have a |
P.S. Probably we need some cop about assigning |
864c14e
to
a974a5a
Compare
Hm, naming for magic literal, like magic number? 🤔 While I also don't have the use case for assigning |
@@ -14,6 +14,12 @@ | |||
RUBY | |||
end | |||
|
|||
it 'does not register an offense and corrects when `&.` is used for snake case const receiver' do | |||
expect_no_offenses(<<~RUBY) | |||
FOO&.do_something |
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.
Btw, I guess there's a small change that a class name will be one word, all caps - e.g. URL
, URI
, etc. I guess we can leave it as is, but are test cases for CONST_NAME
and Const_name
, so it's clearer what we are testing for exactly.
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.
Sure! I've updated the test cases.
…ation` Fixes rubocop#12271. This PR fixes a false positive for `Lint/RedundantSafeNavigation` when using snake case constant receiver. Camel case is used for naming classes and modules, while snake case is used for all other constants. This naming conforms with `Naming/ConstantName` cop. Since constants that turn into classes or modules are normally not `nil`, they will continue to be detected. However, this PR will update to allow safe navigation for constants in snake case. This change resolves both issue rubocop/rubocop-rails#1104 and rubocop#12271.
a974a5a
to
2c1ee21
Compare
Thanks! |
Fixes #12271.
This PR fixes a false positive for
Lint/RedundantSafeNavigation
when using snake case constant receiver.Camel case is used for naming classes and modules, while snake case is used for all other constants. This naming conforms with
Naming/ConstantName
cop.Since constants that turn into classes or modules are normally not
nil
, they will continue to be detected.However, this PR will update to allow safe navigation for constants in snake case.
This change resolves both issue rubocop/rubocop-rails#1104 and #12271.
Before submitting the PR make sure the following are checked:
[Fix #issue-number]
(if the related issue exists).master
(if not - rebase it).bundle exec rake default
. It executes all tests and runs RuboCop on its own code.{change_type}_{change_description}.md
if the new code introduces user-observable changes. See changelog entry format for details.