Skip to content

Conversation

@tas50
Copy link
Contributor

@tas50 tas50 commented Dec 7, 2024

This picks up from #981 so that needs to get merged first

  • Upgrade to RuboCop 1.75.2
  • Bump the Ruby requirement to Ruby 3.0 by default for chefstyle and Ruby 2.6 by default for cookstyle (still allows upgrades from older client releases)
  • Fix deprecation warnings from some cops that inherited from Cop instead of Base
  • Correct style issues within cookstyle itself
  • Enable new cops available between 1.25 -> 1.75 which made sense
  • Update monkeypatch code to work with modern RuboCop
  • Remove rubocop-performance as a development dep
  • Modernize the autocorrection method used in Chef/Style/AttributeKeys

@tas50 tas50 requested review from a team as code owners December 7, 2024 21:48
tas50 added a commit to test-kitchen/test-kitchen that referenced this pull request Dec 7, 2024
These are the fixes discovered by upgrading to RuboCop 1.69 + enabling
new cops here: chef/cookstyle#984

Signed-off-by: Tim Smith <tsmith84@gmail.com>
@johnmccrae
Copy link
Contributor

Tim, I approved the other PR but I have some questions inline about this one - some of the cops appear to be duplicates of each other - the block starting around line 720 appears to be duplicated in a block at ~line 3531 or so? There's a couple of small typos that need clarifying too.

damacus pushed a commit to test-kitchen/test-kitchen that referenced this pull request Dec 10, 2024
These are the fixes discovered by upgrading to RuboCop 1.69 + enabling
new cops here: chef/cookstyle#984

Signed-off-by: Tim Smith <tsmith84@gmail.com>
@sean-sype-simmons
Copy link
Contributor

Related to: #984

@sonarqubecloud
Copy link

sonarqubecloud bot commented Jan 5, 2025

@tas50 tas50 force-pushed the tas50/bump_version branch from 4881140 to 63ad1a8 Compare February 4, 2025 21:38
@sonarqubecloud
Copy link

sonarqubecloud bot commented Feb 4, 2025

Copy link
Collaborator

@jaymzh jaymzh left a comment

Choose a reason for hiding this comment

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

This looks good to me, pending #981 stuff.

@ahasunos
Copy link

While using the tas50:tas50/bump_version branch of @tas50 to run chefstyle, I encountered a LoadError for rubocop-performance.

bundle exec cookstyle --chefstyle 

bundler: failed to load command: cookstyle (/.rbenv/versions/3.4.1/lib/ruby/gems/3.4.0/bin/cookstyle)
/.rbenv/versions/3.4.1/lib/ruby/gems/3.4.0/gems/rubocop-1.71.2/lib/rubocop/feature_loader.rb:46:in 'RuboCop::FeatureLoader#load': cannot load such file -- rubocop-performance (LoadError)

I was able to get it working temporarily by adding rubocop-performance to the Gemfile.

Does this gem need to be added as part of this project?

@tas50
Copy link
Contributor Author

tas50 commented Mar 26, 2025

@ahasunos rubocop-performance is already in one of the groups. Did you make sure to bundle install it first?

@ahasunos
Copy link

@tas50 - Oh, I see that rubocop-performance is already included in the Gemfile under the rubocop_gems group:

group :rubocop_gems do
  gem 'rubocop-performance'
end

However, since I'm using Cookstyle in my project by referencing it like this in my Gemfile:

gem "cookstyle", git: "https://github.com/tas50/cookstyle/", branch: "tas50/bump_version"

I believe this setup would install only the gems listed in the gemspec, not the ones from the Gemfile. Is that correct? 🤔

If that's the case, would it make sense to move rubocop-performance to the gemspec instead, or is it intentionally kept in the Gemfile? Just wanted to check and make sure.

@tas50 tas50 mentioned this pull request Mar 29, 2025
11 tasks
@tas50 tas50 changed the title Upgrade RuboCop to 1.69 + enable new cops Upgrade RuboCop to 1.71.2 + enable new cops Mar 30, 2025
@tas50 tas50 force-pushed the tas50/bump_version branch from 63ad1a8 to b8cefda Compare March 30, 2025 03:18
@tas50 tas50 changed the title Upgrade RuboCop to 1.71.2 + enable new cops Upgrade RuboCop to 1.75.1 + enable new cops Mar 30, 2025
@tas50 tas50 force-pushed the tas50/bump_version branch from b8cefda to 7992f82 Compare April 1, 2025 15:32
@tas50
Copy link
Contributor Author

tas50 commented Apr 1, 2025

@ahasunos I removed rubocop-performance entirely so give things a try now

tas50 added 2 commits April 19, 2025 20:18
This is the latest release

Signed-off-by: Tim Smith <tsmith84@gmail.com>
Keep cookstyle at the earlier version so people can migrate off older
chef client releases

Signed-off-by: Tim Smith <tsmith84@gmail.com>
tas50 and others added 10 commits April 19, 2025 20:18
Signed-off-by: Tim Smith <tsmith84@gmail.com>
Signed-off-by: Tim Smith <tsmith84@gmail.com>
Signed-off-by: Tim Smith <tsmith84@gmail.com>
Resolves a big pile of bugs

Signed-off-by: Tim Smith <tsmith84@gmail.com>
Signed-off-by: Tim Smith <tsmith84@gmail.com>
Signed-off-by: Tim Smith <tsmith84@gmail.com>
Signed-off-by: Tim Smith <tsmith84@gmail.com>
Signed-off-by: Tim Smith <tsmith84@gmail.com>
No need for this right now

Signed-off-by: Tim Smith <tsmith84@gmail.com>
Signed-off-by: Tim Smith <tsmith84@gmail.com>
@tas50 tas50 force-pushed the tas50/bump_version branch from e95d8f5 to 611c7b9 Compare April 20, 2025 03:19
@tas50 tas50 changed the title Upgrade RuboCop to 1.75.1 + enable new cops Upgrade RuboCop to 1.75.2 + enable new cops Apr 20, 2025
Signed-off-by: Tim Smith <tsmith84@gmail.com>
@tas50 tas50 force-pushed the tas50/bump_version branch from 2d7285c to 3eefdac Compare April 20, 2025 03:33
tas50 added 3 commits April 19, 2025 20:37
Signed-off-by: Tim Smith <tsmith84@gmail.com>
Signed-off-by: Tim Smith <tsmith84@gmail.com>
This is the very first Cookstyle cop and I never really touched it. It
hadn't been modernized and sometime in the last 3 years RuboCop nuked
the old method

Signed-off-by: Tim Smith <tsmith84@gmail.com>
@sonarqubecloud
Copy link

@tas50 tas50 requested a review from johnmccrae April 20, 2025 04:22
@johnmccrae johnmccrae added the Expeditor: Bump Version Major Used by github.major_bump_labels to bump the Major version number. label Apr 20, 2025

### Updated default Ruby release

Cookstyle now defaults to Ruby 2.6, enabling new language features, while still helping users on legacy Chef Infra Client releases to upgrade their cookbooks.
Copy link
Collaborator

Choose a reason for hiding this comment

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

3.0?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cookstyle previously defaulted to 2.5, which helped with really old Infra Client upgrades. You want to upgrade your cookbooks before doing the client release. By targeting an old version of Ruby by default you can resolve deprecations in your cookbooks without any modern Ruby-isms sneaking it. If you want to target the latest Infra Client release then you can bump up the target infra client and ruby versions in a .rubocop.yml file.

I did bump Chefstyle to 3.0 though since that's really just for internal use and 2.x support in Chef projects is all gone now.

NewCops: disable
DisabledByDefault: true
TargetRubyVersion: 2.5
TargetRubyVersion: 2.6
Copy link
Collaborator

Choose a reason for hiding this comment

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

wait, why is it 2.6 here and 3.0 above?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Cookstyle vs. Chefstyle

Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't that just the ruby version whose "cops" are applied to your code? You're apply Ruby 2.6 syntax-checking and linting. I would expect Ruby 3.0 as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Some cops will try to modernize your code with new methods that don't exist in old Ruby releases. If we set that to the latest and greatest Ruby releases you couldn't modernize the Chef side without introducing Ruby that old clients couldn't use. Folks can always crank that up as necessary. Ruby 2.6 is Infra Client 15.

@johnmccrae johnmccrae merged commit 6e1df82 into chef:main Apr 22, 2025
8 checks passed
@damacus
Copy link
Contributor

damacus commented Apr 23, 2025

Thanks for getting this merged 👍🏼

any chance we can get a release on RubyGems.org please?

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

Labels

Expeditor: Bump Version Major Used by github.major_bump_labels to bump the Major version number.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants