-
Notifications
You must be signed in to change notification settings - Fork 21.9k
Introduce new cops from newer rubocop #39527
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
Conversation
This pull request has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. |
@fatkodima Do you think we can bump to |
There were a lot of new cops introduced between |
Sounds good 👍. |
b31a84d
to
c7d1d5b
Compare
a58d6c2
to
6186a9c
Compare
Made an additional commit with updating |
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.
Thank you for working on this @fatkodima! 🙌
actionpack/test/controller/parameters/parameters_permit_test.rb
Outdated
Show resolved
Hide resolved
actionpack/test/controller/parameters/parameters_permit_test.rb
Outdated
Show resolved
Hide resolved
fragment = ActionText::AttachmentGallery.fragment_by_canonicalizing_attachment_galleries(fragment) | ||
fragment |
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 not sure, but this might be an intentional stylistic choice.
@@ -527,7 +527,7 @@ def test_indifferent_hash_with_array_of_hashes | |||
hash = { "urls" => { "url" => [ { "address" => "1" }, { "address" => "2" } ] } }.with_indifferent_access | |||
assert_equal "1", hash[:urls][:url].first[:address] | |||
|
|||
hash = hash.to_hash | |||
hash = hash.to_hash # rubocop:disable Style/RedundantSelfAssignment |
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.
Seems like this is a false positive?
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.
Yeah, this is a false positive.
I will fix this and most other mentioned false positives in upstream rubocop. Wdyt about leaving this as inline for now?
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.
My concern is that any new code similar to this would also have to add the pragma to keep Rubocop happy. And we don't know exactly when Rubocop will be fixed, released, and updated in Rails, so my opinion is that it's best to remove it until Rubocop is fixed.
Lint/DeprecatedOpenSSLConstant: | ||
Enabled: true |
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.
This is very useful! 💪 I still hold hope for ruby/openssl#377. 🤞
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.
Style/RedundantRegexpEscape: | ||
Enabled: true |
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 love this rule! 😍
It looks like we bumped the version of Rubocop in #40185 |
Ah, I see. |
I think it was to help the Debian maintainers. At least, that is my impression. Regardless, I think this PR worth pursuing. 👍 |
6186a9c
to
00f944e
Compare
@jonathanhefner thanks for review! Sorry for the noise, I'm for sure should have more carefully reviewed my autocorrected changes, esp. those testing Updated with most of your suggestions. |
Can you explain more about how much it's worth it to add some new style cops? Note that we don't follow The Ruby Style Guide. |
Is this rhetorical question? |
def extract_foreign_key_action(specifier) | ||
case specifier | ||
when "c"; :cascade |
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.
It looks like a cosmetic change.
def create_and_upload!(io:, filename:, key: nil, content_type: nil, metadata: nil, service_name: nil, identify: true, record: nil) | ||
create_after_unfurling!(key: key, io: io, filename: filename, content_type: content_type, metadata: metadata, service_name: service_name, identify: identify).tap do |blob| |
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.
It was originally intended to arrange the order of the keys, now the intent is broken by rubocop autocorrect.
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.
Round 2! 👀
FOREIGN_KEY_ACTIONS = { | ||
"CASCADE" => :cascade, | ||
"SET NULL" => :nullify, | ||
"RESTRICT" => :restrict | ||
} | ||
|
||
def extract_foreign_key_action(specifier) | ||
case specifier | ||
when "CASCADE"; :cascade | ||
when "SET NULL"; :nullify | ||
when "RESTRICT"; :restrict | ||
end | ||
FOREIGN_KEY_ACTIONS[specifier] |
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 still not sure that this change makes the code more readable. It is more clear than an inline Hash, but it breaks up the locality without an obvious reason why, since FOREIGN_KEY_ACTIONS
isn't used elsewhere.
But that's just my opinion. Other people may disagree. 😄
@@ -527,7 +527,7 @@ def test_indifferent_hash_with_array_of_hashes | |||
hash = { "urls" => { "url" => [ { "address" => "1" }, { "address" => "2" } ] } }.with_indifferent_access | |||
assert_equal "1", hash[:urls][:url].first[:address] | |||
|
|||
hash = hash.to_hash | |||
hash = hash.to_hash # rubocop:disable Style/RedundantSelfAssignment |
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.
My concern is that any new code similar to this would also have to add the pragma to keep Rubocop happy. And we don't know exactly when Rubocop will be fixed, released, and updated in Rails, so my opinion is that it's best to remove it until Rubocop is fixed.
values += [STDOUT, StringIO.new, ActionDispatch::Http::UploadedFile.new(tempfile: __FILE__), | ||
values += [$stdout, StringIO.new, ActionDispatch::Http::UploadedFile.new(tempfile: __FILE__), |
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 not sure about this one. The intent was actually STDOUT
, but I don't know if it makes a difference.
silence_stream(STDOUT) do | ||
silence_stream(STDERR) do | ||
silence_stream($stdout) do | ||
silence_stream($stderr) do |
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.
These should not be changed.
if id.is_a?(Array) | ||
case id | ||
when Array |
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.
It looks like a cosmetic change.
That is the reason that originaly if id.is_a?(Array)
was used is elsif id == :all
didn't exist before.
@@ -24,7 +24,7 @@ def initialize | |||
# If the adapter cannot be found, this will default to the Redis adapter. | |||
# Also makes sure proper dependencies are required. | |||
def pubsub_adapter | |||
adapter = (cable.fetch("adapter") { "redis" }) | |||
adapter = (cable.fetch("adapter", "redis")) |
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 don't want to enable such like unsafe autocorrect.
Whether a block is redundant depends on whether the receiver is a hash.
@kamipo I agree we should be judicious about which Perhaps we should only keep |
As a most active contributor in https://github.com/rails/rails/blob/master/.rubocop.yml, #36472 Since some your changes have little explanation, I feel it costs a lot to review it than more explained changes. I hope you can explain more in the future. |
Agreed, it is better to introduce some of them one by one, with better and more detailed explanations. If someone interested in this, please do. |
@fatkodima you have already invested much time in this one, so i think it would be better if you update this PR and remove "controversial" cops as of now. |
Please, do. You can take ownership of this pr without any doubts. |
No description provided.