Skip to content

Conversation

fatkodima
Copy link
Member

No description provided.

@rails-bot
Copy link

rails-bot bot commented Sep 1, 2020

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.
Thank you for your contributions.

@rails-bot rails-bot bot added the stale label Sep 1, 2020
@KapilSachdev
Copy link
Contributor

@fatkodima Do you think we can bump to 0.90 in this PR ?

@fatkodima
Copy link
Member Author

There were a lot of new cops introduced between 0.85 and 0.90. So, probably, it is more tractable to rebase and merge this and then do 0.85 -> 0.90 separately?

@KapilSachdev
Copy link
Contributor

Sounds good 👍.
I was thinking if version bump can be reviewed once rather twice.
Two PRs are always good and easier to review but in case we bump in this one, maybe there are reasonble amount of changes introduced that can be reviewed in one go.

@fatkodima fatkodima force-pushed the update-rubocop branch 2 times, most recently from b31a84d to c7d1d5b Compare September 5, 2020 19:14
@fatkodima fatkodima force-pushed the update-rubocop branch 2 times, most recently from a58d6c2 to 6186a9c Compare September 5, 2020 22:13
@fatkodima
Copy link
Member Author

Made an additional commit with updating 0.85 => 0.90.

Copy link
Member

@jonathanhefner jonathanhefner left a 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! 🙌

Comment on lines -18 to -19
fragment = ActionText::AttachmentGallery.fragment_by_canonicalizing_attachment_galleries(fragment)
fragment
Copy link
Member

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
Copy link
Member

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?

Copy link
Member Author

@fatkodima fatkodima Sep 6, 2020

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?

Copy link
Member

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.

Comment on lines +218 to +220
Lint/DeprecatedOpenSSLConstant:
Enabled: true
Copy link
Member

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. 🤞

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I do prefer to disscuss about it in #39410, #39504, #39540.

Comment on lines +288 to +285
Style/RedundantRegexpEscape:
Enabled: true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I love this rule! 😍

@composerinteralia
Copy link
Member

It looks like we bumped the version of Rubocop in #40185

@fatkodima
Copy link
Member Author

Ah, I see.
What is the point of just bumping rubocop without actually any changes to the code?

@jonathanhefner
Copy link
Member

I think it was to help the Debian maintainers. At least, that is my impression. Regardless, I think this PR worth pursuing. 👍

@fatkodima fatkodima changed the title Update rubocop to 0.85 Introduce new cops from newer rubocop Sep 6, 2020
@fatkodima
Copy link
Member Author

@jonathanhefner thanks for review! Sorry for the noise, I'm for sure should have more carefully reviewed my autocorrected changes, esp. those testing fetch/dig 😄

Updated with most of your suggestions.

@kamipo
Copy link
Member

kamipo commented Sep 6, 2020

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.

@fatkodima
Copy link
Member Author

Can you explain more about how much it's worth it to add some new style cops?

Is this rhetorical question?
(Likely) better, simpler, faster, safer, consistent, less buggy, etc code.

def extract_foreign_key_action(specifier)
case specifier
when "c"; :cascade
Copy link
Member

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.

Comment on lines +104 to 105
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|
Copy link
Member

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.

Copy link
Member

@jonathanhefner jonathanhefner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Round 2! 👀

Comment on lines +1500 to +1507
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]
Copy link
Member

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
Copy link
Member

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__),
Copy link
Member

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.

Comment on lines -18 to +19
silence_stream(STDOUT) do
silence_stream(STDERR) do
silence_stream($stdout) do
silence_stream($stderr) do
Copy link
Member

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.

Comment on lines -288 to +289
if id.is_a?(Array)
case id
when Array
Copy link
Member

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"))
Copy link
Member

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.

@jonathanhefner
Copy link
Member

@kamipo I agree we should be judicious about which Style rules we adopt. There are some rules here which might be better to omit (e.g. Style/HashLikeCase), but overall I think the changes are positive.

Perhaps we should only keep Style rules that have an immediate positive effect on the current code base (e.g. Style/RedundantRegexpEscape).

@kamipo
Copy link
Member

kamipo commented Sep 6, 2020

Can you explain more about how much it's worth it to add some new style cops?

Is this rhetorical question?
(Likely) better, simpler, faster, safer, consistent, less buggy, etc code.

As a most active contributor in https://github.com/rails/rails/blob/master/.rubocop.yml,
I basically explain why the cop should be enabled, what is worth (mostly a reduction in review costs).

#36472
4353ada
6b8daad
7ebfb31
#34904
6d95901
#34764
f907b41
b2c1e29

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.

@fatkodima
Copy link
Member Author

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 fatkodima closed this Sep 7, 2020
@KapilSachdev
Copy link
Contributor

@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.
But if you still don't want to, I can start adding cop in that case.

@fatkodima
Copy link
Member Author

But if you still don't want to, I can start adding cop in that case.

Please, do. You can take ownership of this pr without any doubts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants