-
Notifications
You must be signed in to change notification settings - Fork 124
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
Update RuboCop support; use Bixby style guide #2655
Conversation
def update(env) | ||
model_actor(env).update(env) | ||
end | ||
delegate :update, to: :model_actor |
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.
Maybe I'm tired, but how does this work? How does model actor get it's parameter passed to it?
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.
huh. I think this was a RuboCop autocorrect. I wonder if this might be a bug in the autocorrect code. If it passes CI, I'll look into it. If it fails, I'll revert the change and fence the rule.
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.
Thanks for the thorough review.
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 enough: rubocop/rubocop#5393
@@ -1,3 +1,4 @@ | |||
# coding: utf-8 |
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.
Why? Isn't this the default in ruby 2.x?
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 might be an editor artifact from me. I'll remove it.
@@ -133,7 +133,7 @@ def self.add_participants(collection_type_id, participants) | |||
agent_id = p.fetch(:agent_id) | |||
access = p.fetch(:access) | |||
Hyrax::CollectionTypeParticipant.create!(hyrax_collection_type_id: collection_type_id, agent_type: agent_type, agent_id: agent_id, access: access) | |||
rescue => e # rubocop:disable Lint/RescueWithoutErrorClass | |||
rescue => e |
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 really wish we called this out as something that should be fixed. Can we add this cop to Bixby?
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 cop is new since bixby launched. I've opened a bixby ticket, but it will be a 2.0 feature.
In the meanwhile, we can add this cop locally. However, I'm not sure what the value of doing that is at the moment, if we are just going to disable it in the individual cases.
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.
@jcoyne This cop has also been replaced with Style/RescueStandardError
.
Honestly, I'm looking at this now and pretty unconvinced that this is a Good Cop ™️. In this case, we're catching StandardError
and logging, which seems like an extremely common and happy use case.
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 disagree that this is a happy use case. Currently I have no idea what error we're expecting here. Could it be a KeyError or a Database error (out of space maybe?) I'd really like for those exceptions to be bubbling up.
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've added #2666 to address this case in particular, but I'd really think that over general error catching is likely a code smell.
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 opened a Bixby issue at samvera/bixby#23; but resolving it will be a major bixby
version. I'd suggest we discuss there for a bit.
If we want to add this locally in the meanwhile, I can do that. I'd prefer not to block this PR for it, since the only current instance of the issue is now fixed.
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.
catching StandardError is IMO fine to do when you are not actually swallowing the error but: a) logging and re-raising original, and/or b) re-raising another module-specific error wrapping the original.
I do both frequently. It would be annoying if I had to tell rubocop to let me do it all the time, but then, that may just be the way it is with rubocop.
At any rate, whether to add or remove a rule to Bixby definitely seems like a different issue, yes?
hyrax.gemspec
Outdated
@@ -1,3 +1,4 @@ | |||
# coding: utf-8 |
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.
Necessary?
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.
nope.
@@ -6,7 +6,7 @@ | |||
Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_PUBLIC => | |||
"<span class=\"label label-success\">Public</span>", | |||
Hydra::AccessControls::AccessRight::VISIBILITY_TEXT_VALUE_AUTHENTICATED => | |||
"<span class=\"label label-info\">%s</span>", | |||
"<span class=\"label label-info\">%<name>s</span>", |
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.
What is going on 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.
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.
Okay, looks good.
@@ -1,7 +1,6 @@ | |||
RSpec.describe Hyrax::QaSelectService do | |||
let(:authority) do | |||
# Implementing an ActiveRecord interface as required for this spec | |||
# rubocop:disable RSpec/InstanceVariable |
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 a cop that I wish we could maintain. Can we add to Bixby?
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 is enabled here: https://github.com/samvera-labs/bixby/blob/7d62f7ce8e7ea6d22e4478dce5c8af4baddeff98/bixby_rspec_enabled.yml#L66
I think RuboCop must have made this cop less sensitive to class definitions within RSpec. This has been a pain-point for me for cases like this for some time, so I'm grateful to find that these cases are no longer flagged.
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.
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.
Cool. 👍
My impression is that packing conditions and expressions (especially when both are complex) onto the same line actually reduces the readability of the code. I'm interested to know what others think. |
@jcoyne to clarify, you are arguing to drop enforcement of this rule? https://github.com/bbatsov/ruby-style-guide#if-as-a-modifier |
@no-reply that looks like the right cop.
In our real code, I don't think that this: @parent_presenter ||= show_presenter.new(search_result_document(id: params[:parent_id]), current_ability, request) if params[:parent_id] is an improvement over this. if params[:parent_id]
@parent_presenter ||= show_presenter.new(search_result_document(id: params[:parent_id]), current_ability, request)
end |
@jcoyne That makes sense. I tend to think this kind of sneaky nested conditional is pathological to begin with, but I'm not sure that should stop us from disabling the rule. I'm a fan of the rule in general, but open to consideration. I'd accept discussion on a Bixby ticket and/or PR. In the meanwhile, I'm open to blocking this ticket on a local disable of the cop. |
c783f2f
to
9f1c147
Compare
@no-reply I totally agree that those lines could have their readability improved in other ways, but I think we shouldn't make the current situation less readable while we wait for a refactor that may or may not ever come. |
I think issues are now fixed with the exception of open discussions: |
@jcoyne If that refactor came on a follow up commit on this PR, could we avoid disabling the rule? Or would other concerns about that rule's value remain? |
I really have no idea why the Ruby 2.1 syntax linter suddenly has unexpected tokens on perfectly reasonable Ruby code. I was able to reproduce locally with |
@no-reply Ruby 2.1 linter is failing based on https://github.com/whitequark/parser version 2.5.0.0 (a Rubocop dependency) Mine was running fine under 2.4.0.2. It failed when I updated it locally. We're pinning it to get travis to build again. |
Bixby is a RuboCop style guide that decouples (to the degree possible) RuboCop software updates from unrelated style guide updates. Bixby disables all rules by default, and re-enables rules that are adopted in the community in general. Bixby's promise is to avoid adding rules without bumping major version. Pinning to the current v1.0.0 will allow us to update software versions with reduced changes (ideally none) to code style. Enforcement of existing rules may still change to become more strict based on updates to rule enforcement code. Several rule exceptions and other configurations that I could identify as being inherited from Bixby are removed from the local `.rubocop.yml`. Closes #2568.
I can't see how nesting conditional assignment of the same variable does anything here; pushing this through CI to see if I'm wrong.
The version of RDF.rb checked in this conditional is no longer an allowed dependency. ActiveTriples 11.0.0 and up require RDF.rb >= 2.0.0.
@jcoyne I went ahead and refactored to remove the I also removed an unnecessary check for an RDF.rb version that isn't allowed by the dependency tree. |
@jcoyne were your concerns addressed? it would be really helpful to get this PR in, can we accept most of it and make issues of any remaining concerns? |
@jenlindner No, not really. I still don't agree that we should allow anyone to raise StandardError (without some justification as to why there isn't a more specific error that is more suitable). I also think that formatting the conditionals to the end often hurts readability. But I'll not want to block this PR if others think this is preferable. |
@jcoyne Yeah, it's not like there's no merit to that position, there clearly is. I don't want to see the discussion get lost and rubocop left in a state that also opens us up to trouble/tech debt, which it might be now? I'm not really sure about that, but we do need a working rubocop and most of the other improvements seem uncontested. I think how to handle errors and where to catch/log/raise is a really great topic for code quality/stability discussions and would love to have the dangers of over-catching presented in them. Thank you. @jrochkind how are you feeling about the PR as it is? would you be open to contributing to a discussion about error handling in code quality/stability? |
How does this relate to the discussion at samvera/bixby#23 (comment)?
I thought that we had refactored the cases that were problematic wrt this issue? It's not clear to me what work would unblock this PR at this point. Should I simply close it? |
@no-reply I think it is valuable to keep it open. How about we talk about it on the tech call if it isn't resolved by then? Or take it to the email list? Either way it would be good to get more voices on this. |
@samvera/hyrax-code-reviewers @jcoyne has indicated he doesn't intend to be blocking this PR. What can we do to move forward? |
@cjcolvar @no-reply I added this item to the tech call agenda: https://wiki.duraspace.org/display/samvera/Samvera+Tech+Call+2018-02-28. |
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.
👍 Final rubocop rule changes can be done on bixby and there weren't any blockers brought up on the tech call.
Update RuboCop support; use Bixby style guide
Bixby is a RuboCop style guide that decouples (to the degree possible) RuboCop
software updates from unrelated style guide updates. Bixby disables all rules by
default, and re-enables rules that are adopted in the community in general.
Bixby's promise is to avoid adding rules without bumping major
version. Pinning to the current v1.0.0 will allow us to update software versions
with reduced changes (ideally none) to code style. Enforcement of existing rules
may still change to become more strict based on updates to rule enforcement
code.
Several rule exceptions and other configurations that I could identify as being
inherited from Bixby are removed from the local
.rubocop.yml
.Closes #2568.
Changes proposed in this pull request:
@samvera/hyrax-code-reviewers