-
Notifications
You must be signed in to change notification settings - Fork 293
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
Fixes #37517 - Upgrade theforeman-rubocop gem to the v0.1.0 #11009
Conversation
Note: While testing, there are new RuboCop offenses now. It's unclear for me to know which offenses to fix based on the code style, so should I consider regenerating the |
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.
Here are my thoughts about specific rules that are failing currently:
Style/OptionalBooleanParameter: Prefer keyword arguments for arguments with a boolean default value; use `redirect_on_failure: true` instead of `redirect_on_failure = true`.
Yeah kwargs! 👍 I like them in general because they're more explicit, but they can make function definitions long. In the case of Booleans, though, I think requiring them outweighs that, so I'm for it.
Style/TrailingCommaInHashLiteral: Put a comma after the last item of a multiline hash.
This will be a big change for Katello's Ruby, but it will also bring us in line with eslint
and our JS code. If Foreman is adopting this, I think Katello should too. 👍
Style/SlicingWithRange: Prefer ary[n..] over ary[n..-1].
uhh sure why not!
Rails/HttpStatus: Prefer `:ok` over `200` to define HTTP status code.
We do this in most every place, so I'm +1 to this rule.
Style/CaseLikeIf: Convert `if-elsif` to `case-when`.
I do like case-when
better, but this may get pushback from some veteran Rubyists. @parthaa thoughts?
I'm a junior Rubyist if that counts for anything? |
@archanaserver I haven't seen any dissents so I'd say you can go ahead with keeping these rules and fixing them. |
@jeremylenz yes, so looking at the Out current implementation works correctly here and this rule is purely a stylistic preference only and no any other concern. Therefore, I recommend not enforcing this rule at this time to avoid unnecessary complications. We have followed the same approach in some other repos. WDYT? Also, I have raised few PRs for different cops. Do you want me to update the rubocop_todo file after the changes got merged? |
If we've got consistency across repos, I'm fine with this. 👍
What does that mean exactly? |
@jeremylenz so even after fixing cops like Style/TrailingCommaInHashLiteral, Style/SlicingWithRange, Rails/HttpStatus and Style/CaseLikeIf. There are still many other cops causing failure in RuboCop job run. Some of them are from Style/, Layout/, Lint/, Metrics/ and Minitest/. Do you want continue fixing each one of them or want to proceed for now by updating .rubocop_todo.yml file, adding all those in todo list for later fix. |
I would prefer to have little or nothing in todo. I feel like most of them should be resolved with |
This is to track list of PRs submitted to fixing cops, after the theforeman-rubocop version update:
|
@jeremylenz I'm on it! I did use I'm making sure to fix the rules which seems relevant and safe to use, or decided to put some marked disabled by following rest of the foreman repo's, like this 9ab6e28. WDYT? |
If we are consistent with other repos then 👍 🚀 |
@archanaserver is there a particular order that you'd like these PRs merged? I wasn't sure if there were interdependencies that required some to go before others. |
@ianballou This particular PR require all of these PRs to merge(in any order) first, so that we have all the new rubocop rules here after the theforeman-rubocop gem update to v0.1.0. Also this will make the rubocop job green here. |
@ianballou some of the PRs from the list are approved by others and ready to be merge i belive, would you mind taking a look? |
72693bb
to
5055b0d
Compare
hie @ianballou, could you please find moment to dropping some reviews here? |
5055b0d
to
295f6a4
Compare
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.
Looking pretty good overall! Small amount of failures left after rebasing.
Since Foreman needs to update their version of theforeman-rubocop, is the plan to merge a Foreman PR right after the Katello one is merged? Otherwise our tests will be broken.
Here's the latest output from rubocop after rebasing:
/home/vagrant/katello/app/controllers/katello/api/v2/activation_keys_controller.rb:303:7: C: Naming/MemoizedInstanceVariableName: Memoized variable @organization does not match method name find_content_view_environments. Use @find_content_view_environments instead.
@organization ||= @content_view_environments.first&.organization
^^^^^^^^^^^^^
/home/vagrant/katello/app/models/katello/content_view_environment.rb:71:7: C: [Correctable] Style/CaseLikeIf: Convert if-elsif to case-when.
if content_object.is_a? Katello::ActivationKey ...
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/home/vagrant/katello/app/models/katello/content_view_environment.rb:78:46: C: [Correctable] Style/KeywordParametersOrder: Place optional keyword parameters at the end of the parameters list.
def self.fetch_content_view_environments(labels: [], ids: [], organization:)
^^^^^^^^^^
/home/vagrant/katello/app/models/katello/content_view_environment.rb:78:58: C: Style/KeywordParametersOrder: Place optional keyword parameters at the end of the parameters list.
def self.fetch_content_view_environments(labels: [], ids: [], organization:)
^^^^^^^
/home/vagrant/katello/engines/bastion/bastion.gemspec:1:22: C: [Correctable] Style/ExpandPathArguments: Use expand_path('lib', __dir__) instead of expand_path('../lib', __FILE__).
$LOAD_PATH.push File.expand_path("../lib", __FILE__)
^^^^^^^^^^^
/home/vagrant/katello/engines/bastion/bastion.gemspec:14:33: C: Gemspec/RequiredRubyVersion: required_ruby_version and TargetRubyVersion (2.7, which may be specified in .rubocop.yml) should be equal.
s.gem.required_ruby_version = ['>= 2.5.0', '< 2.7.0']
^^^^^^^^^^^^^^^^^^^^^^^
/home/vagrant/katello/katello.gemspec:1:22: C: [Correctable] Style/ExpandPathArguments: Use expand_path('lib', __dir__) instead of expand_path('../lib', __FILE__).
$LOAD_PATH.push File.expand_path("../lib", __FILE__)
^^^^^^^^^^^
/home/vagrant/katello/lib/katello/permission_creator.rb:56:28: C: [Correctable] Style/TrailingCommaInHashLiteral: Put a comma after the last item of a multiline hash.
'katello/api/v2/capsules' => [:index, :show]
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/home/vagrant/katello/test/models/association_test.rb:70:9: C: [Correctable] Style/TrailingCommaInArrayLiteral: Put a comma after the last item of a multiline array.
"Katello::SubscriptionFacetPurposeAddon"
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
/home/vagrant/katello/test/models/content_view_environment_activation_key_test.rb:18:73: C: [Correctable] Layout/MultilineArrayBraceLayout: The closing array brace must be on the line after the last array element when the opening brace is on a separate line from the first array element.
katello_content_view_environments(:library_dev_staging_view_dev)]
^
1932 files inspected, 10 offenses detected, 7 offenses auto-correctable
Since the tests are broken I'm running them locally. Will report back soon. |
Only saw one test failure that is likely not related to this PR:
|
This should be good to ACK once the rebase is done 👍 |
295f6a4
to
460af38
Compare
Thanks @ianballou! I just rebased it and solved some of the cops offenses.
And about this, I guess mentioning @ekohl would be good for a clear answer. |
I see this error output. Is this due to Katello specifying I think, unlike other plugins, Katello has a tight relationship with Foreman's target version of the I am thinking one of two approaches would help:
One of the above changes can be made as an independent PR. |
Any chance this is just leftover from when we ran rubocop directly in Katello instead of via foreman-rake katello:rubocop? I wonder if it can be removed entirely. |
I believe in that case it’s better to first test removing the gem declaration from Katello's Gemfile and rely on Foreman's version to see if this resolves the conflict. That would also mean we need to merge the Foreman PR first. If that doesn’t work, I’ll explore the alternative options that @ehelms suggested, such as moving it to the .gemspec or gemfile.d/lint.rb. |
460af38
to
c699227
Compare
c699227
to
f231c3d
Compare
This now passing all the checks, also added few more fixes for different rubocop offenses. @ianballou @jeremylenz do you have any thoughts on this? |
If you squash the commits that'll take care of the "Redmine issues" check :) |
f231c3d
to
8e22676
Compare
Choose to inherit `lenient.yml` from `theforeman-rubocop` style, because that it matches to the rubocop style this repo follows. Also dropped `Rails` and `Style/Documentation` cops because that already exist in the lenient style we now follow. Update .rubocop_todo.yml file Fix Style/TrailingCommaInHashLiteral cop Fix cop Style/TrailingCommaInArrayLiteral Fix Style/KeywordParametersOrder cop Fix Style/ClassEqualityComparison cop Fix Style/CommentAnnotation cop Fix Style/RedundantAssignment cop Fix Style/CaseLikeIf cop Fix Lint/AmbiguousBlockAssociation offenses Added parentheses around method calls in assert statements to resolve ambiguous block associations as flagged by RuboCop. Fix Naming/RescuedExceptionsVariableName Fix Style/RegexpLiteral
8e22676
to
909dfe3
Compare
Done @jeremylenz ! You can take a look 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.
Can this merge now? Is it waiting on any dependencies?
Yes, we can merge this now. |
Thanks @archanaserver ! |
What are the changes introduced in this pull request?
lenient.yml
style provided bytheforeman-rubocop
, https://github.com/theforeman/theforeman-rubocop?tab=readme-ov-file#not-intrusive-style---lenientRails
andStyle/Documentation
cops from the configuration as they are already included in thelenient.yml
style.Considerations taken when implementing this change?
lenient.yml
because it aligns well with the existing RuboCop style followed by this repo.Rails
andStyle/Documentation
cops to avoid redundancy and conflicts since they are already covered bylenient.yml
.What are the testing steps for this pull request?
bundle install
to ensure all dependencies are correctly installed, including the updatedtheforeman-rubocop
gem.bundle exec rubocop
to verify that the new RuboCop configuration is being applied without errors.