Skip to content
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

Use latest rubocop and target ruby 2.5 #40

Merged
merged 4 commits into from Oct 28, 2021

Conversation

alexjfisher
Copy link
Member

No description provided.

@smortex
Copy link
Member

smortex commented Apr 29, 2021

Since Puppetlabs only support Puppet 6+ now, I think we can even consider jumping to targeting Ruby 2.5 which is the version Puppet 6 use and has reached EOL only a few weeks ago?

@ekohl
Copy link
Member

ekohl commented May 23, 2021

I'm starting to add Rubocop to theforeman modules and I'm running into this as well now.

@bastelfreak
Copy link
Member

I agree, I think we should move forward with it

@ekohl
Copy link
Member

ekohl commented Jun 21, 2021

Related Github formatter introduced in Rubocop 1.2: puppetlabs/puppetlabs_spec_helper#340

@ekohl
Copy link
Member

ekohl commented Jul 26, 2021

puppetlabs/puppetlabs_spec_helper#340 has been merged. Once there's a release out, it'd be great if this PR also raised the minimum spec helper version to that.

@smortex
Copy link
Member

smortex commented Aug 11, 2021

puppetlabs/puppetlabs_spec_helper#340 has been merged. Once there's a release out, it'd be great if this PR also raised the minimum spec helper version to that.

This seems to have been released just after your message:
https://github.com/puppetlabs/puppetlabs_spec_helper/releases/tag/v4.0.0

@traylenator
Copy link
Contributor

Some extra motivation Puppetlabs now expect rubocop-performance to be present which needs newer rubocop.

e.g. puppetlabs-inifile results in

  • rubocop (1.6.1)
  • rubocop-ast (1.12.0)
  • rubocop-performance (1.9.1)
  • rubocop-rspec (2.0.1)

@traylenator
Copy link
Contributor

Okay so with extra commit on top for even latest rubocop again and targeting ruby 2.5 traylenator@20b292c

Ignored modules

  • Ignore puppet-openssl as Gemfile did not work.
  • Ignore puppet-archive, puppet-epel and puppet-jenkins as failing with 0.49.1 already.

Invalid config in module

  • puppet-vault_lookup
.rubocop.yml: Metrics/LineLength has the wrong namespace - should be Layout
Error: The `Layout/IndentHeredoc` cop has been renamed to `Layout/HeredocIndentation`.
(obsolete configuration found in .rubocop.yml, please update it)

Per module counts

e.g

  • puppet-allknowingdns 6 files inspected, 32 offenses detected, 17 offenses auto-correctable
  • puppet-alternatives 10 files inspected, 53 offenses detected, 47 offenses auto-correctable
  • ...
    count.txt

Count of un-Correctable Critical problems

e.g.

  • 2421 RSpec/ContextWording: Start context description with 'when', 'with', or 'without'.
  • 544 Naming/HeredocDelimiterNaming: Use meaningful heredoc delimiters.
  • ....

unfixable.txt

Count of un-Correctable Critical by module

e.g.

  • puppet-allknowingdns_rubocop_result.txt
    8 RSpec/ContextWording: Start context description with 'when', 'with', or 'without'.
    3 Style/MixinUsage: include is used at the top level. Use inside class or module.
    1 RSpec/RepeatedExampleGroupDescription: Repeated describe block description on line(s) [19]
    1 RSpec/RepeatedExampleGroupDescription: Repeated describe block description on line(s) [14]
    1 RSpec/RepeatedExampleGroupBody: Repeated describe block body on line(s) [19]
    1 RSpec/RepeatedExampleGroupBody: Repeated describe block body on line(s) [14]

unfixable-bymodule.txt

@genebean
Copy link

It is probably worth updating the PR title to match how this has evolved too.

@smortex smortex changed the title Use latest rubocop and target ruby 2.4 Use latest rubocop and target ruby 2.5 Oct 15, 2021
@smortex smortex changed the title Use latest rubocop and target ruby 2.5 Use latest rubocop and target ruby 2.4 Oct 16, 2021
@smortex
Copy link
Member

smortex commented Oct 16, 2021

@traylenator looks like a move in the right direction. Do you mind adding your changes to this PR?

Naming/HeredocDelimiterNaming and RSpec/* are the most frequent offenses. Maybe we can ignore them if this is a concern?

@traylenator
Copy link
Contributor

@smortex unsure how to update this PR with my changes - short of creating a whole new PR ?

@alexjfisher alexjfisher changed the title Use latest rubocop and target ruby 2.4 Use latest rubocop and target ruby 2.5 Oct 18, 2021
@alexjfisher
Copy link
Member Author

@traylenator Are you able to push to this PR now?

@codecov
Copy link

codecov bot commented Oct 18, 2021

Codecov Report

Merging #40 (7c0ad20) into master (cfe8c99) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##           master      #40   +/-   ##
=======================================
  Coverage   28.33%   28.33%           
=======================================
  Files           2        2           
  Lines          60       60           
=======================================
  Hits           17       17           
  Misses         43       43           

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update cfe8c99...7c0ad20. Read the comment docs.

voxpupuli-test.gemspec Outdated Show resolved Hide resolved
rubocop.yml Outdated
TargetRubyVersion: 1.9
# Ruby 2.4 is the oldest version we can use with the latest version of rubocop (1.11.0 as of 13/03/2021).
# Puppet agent 5 ships with ruby 2.4. Puppetserver 5 has JRuby 2.1.x which is only ruby 2.3 compatible, but this
# is unlikely to cause many issues. If/when it does, we can disable the relevant cop inline as appropriate.
Copy link
Member

Choose a reason for hiding this comment

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

maybe add a note that we chose Ruby 2.5 because that's in Puppet Agent 6 vendored and that's the oldest agent we still support.

Copy link
Member Author

Choose a reason for hiding this comment

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

Out of date docs updated.

@alexjfisher alexjfisher marked this pull request as ready for review October 18, 2021 10:24
@ekohl
Copy link
Member

ekohl commented Oct 18, 2021

  • 2421 RSpec/ContextWording: Start context description with 'when', 'with', or 'without'.

  • 544 Naming/HeredocDelimiterNaming: Use meaningful heredoc delimiters.

These are very high. Should we ignore these?

@alexjfisher
Copy link
Member Author

  • 2421 RSpec/ContextWording: Start context description with 'when', 'with', or 'without'.
  • 544 Naming/HeredocDelimiterNaming: Use meaningful heredoc delimiters.

These are very high. Should we ignore these?

I'm happy to create todo files so that we don't disable the cops for all future code too.

@alexjfisher
Copy link
Member Author

  • 2421 RSpec/ContextWording: Start context description with 'when', 'with', or 'without'.
  • 544 Naming/HeredocDelimiterNaming: Use meaningful heredoc delimiters.

These are very high. Should we ignore these?

I'm happy to create todo files so that we don't disable the cops for all future code too.

Actually, I'm happy either way! :)

@ekohl
Copy link
Member

ekohl commented Oct 19, 2021

Given it's test code and many Puppet developers are not Ruby developers, I'm leaning to disabling the cops. IMHO we're not going for perfect code quality so let's not set the bar too high.

@alexjfisher
Copy link
Member Author

Given it's test code and many Puppet developers are not Ruby developers, I'm leaning to disabling the cops. IMHO we're not going for perfect code quality so let's not set the bar too high.

Updated. (but not tested!)

Copy link
Member

@smortex smortex left a comment

Choose a reason for hiding this comment

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

Updated. (but not tested!)

217 -> 123 offenses detected on WIP puppet-elasticsearch

:shipit: :shipit: :shipit:

@smortex
Copy link
Member

smortex commented Oct 25, 2021

FWIW, with more testing I am experiencing a lot of these:

spec/spec_utilities.rb:112:8: C: [Corrected] Layout/DotPosition: Place the . on the previous line, together with the method call receiver.
    end.empty?
       ^

89 files inspected, 38 offenses detected, 3 offenses corrected
Infinite loop detected in /usr/home/romain/Projects/voxpupuli/modulesync_config/modules/voxpupuli/puppet-elasticsearch/spec/spec_utilities.rb and caused by Layout/DotPosition
/usr/home/romain/.vendor/ruby/2.7/gems/rubocop-1.22.2/lib/rubocop/runner.rb:298:in `check_for_infinite_loop'
/usr/home/romain/.vendor/ruby/2.7/gems/rubocop-1.22.2/lib/rubocop/runner.rb:281:in `block in iterate_until_no_changes'
/usr/home/romain/.vendor/ruby/2.7/gems/rubocop-1.22.2/lib/rubocop/runner.rb:280:in `loop'
/usr/home/romain/.vendor/ruby/2.7/gems/rubocop-1.22.2/lib/rubocop/runner.rb:280:in `iterate_until_no_changes'
/usr/home/romain/.vendor/ruby/2.7/gems/rubocop-1.22.2/lib/rubocop/runner.rb:249:in `do_inspection_loop'
/usr/home/romain/.vendor/ruby/2.7/gems/rubocop-1.22.2/lib/rubocop/runner.rb:130:in `block in file_offenses'
/usr/home/romain/.vendor/ruby/2.7/gems/rubocop-1.22.2/lib/rubocop/runner.rb:155:in `file_offense_cache'
/usr/home/romain/.vendor/ruby/2.7/gems/rubocop-1.22.2/lib/rubocop/runner.rb:129:in `file_offenses'
/usr/home/romain/.vendor/ruby/2.7/gems/rubocop-1.22.2/lib/rubocop/runner.rb:120:in `process_file'
/usr/home/romain/.vendor/ruby/2.7/gems/rubocop-1.22.2/lib/rubocop/runner.rb:101:in `block in each_inspected_file'
/usr/home/romain/.vendor/ruby/2.7/gems/rubocop-1.22.2/lib/rubocop/runner.rb:100:in `each'
/usr/home/romain/.vendor/ruby/2.7/gems/rubocop-1.22.2/lib/rubocop/runner.rb:100:in `reduce'
/usr/home/romain/.vendor/ruby/2.7/gems/rubocop-1.22.2/lib/rubocop/runner.rb:100:in `each_inspected_file'
/usr/home/romain/.vendor/ruby/2.7/gems/rubocop-1.22.2/lib/rubocop/runner.rb:86:in `inspect_files'
/usr/home/romain/.vendor/ruby/2.7/gems/rubocop-1.22.2/lib/rubocop/runner.rb:47:in `run'
/usr/home/romain/.vendor/ruby/2.7/gems/rubocop-1.22.2/lib/rubocop/cli/command/execute_runner.rb:26:in `block in execute_runner'
/usr/home/romain/.vendor/ruby/2.7/gems/rubocop-1.22.2/lib/rubocop/cli/command/execute_runner.rb:52:in `with_redirect'
/usr/home/romain/.vendor/ruby/2.7/gems/rubocop-1.22.2/lib/rubocop/cli/command/execute_runner.rb:25:in `execute_runner'
/usr/home/romain/.vendor/ruby/2.7/gems/rubocop-1.22.2/lib/rubocop/cli/command/execute_runner.rb:17:in `run'
/usr/home/romain/.vendor/ruby/2.7/gems/rubocop-1.22.2/lib/rubocop/cli/command.rb:11:in `run'
/usr/home/romain/.vendor/ruby/2.7/gems/rubocop-1.22.2/lib/rubocop/cli/environment.rb:18:in `run'
/usr/home/romain/.vendor/ruby/2.7/gems/rubocop-1.22.2/lib/rubocop/cli.rb:71:in `run_command'
/usr/home/romain/.vendor/ruby/2.7/gems/rubocop-1.22.2/lib/rubocop/cli.rb:78:in `execute_runners'
/usr/home/romain/.vendor/ruby/2.7/gems/rubocop-1.22.2/lib/rubocop/cli.rb:47:in `run'
/usr/home/romain/.vendor/ruby/2.7/gems/rubocop-1.22.2/exe/rubocop:12:in `block in <top (required)>'
/usr/local/lib/ruby/2.7/benchmark.rb:308:in `realtime'
/usr/home/romain/.vendor/ruby/2.7/gems/rubocop-1.22.2/exe/rubocop:12:in `<top (required)>'
/home/romain/.vendor/ruby/2.7/bin/rubocop:23:in `load'
/home/romain/.vendor/ruby/2.7/bin/rubocop:23:in `<main>'

Autocorrect fails at fixing these, and the manual fix is not that better IMHO:

-    end.empty?
+    end.
+      empty?

Any multi-line block / hash followed by .something trigger this 😱 .

Maybe we can disable this test (Layout/DotPosition)?

@alexjfisher
Copy link
Member Author

@smortex Rubocop bug fixed in rubocop/rubocop#10207

traylenator and others added 3 commits October 28, 2021 10:18
4.0.0 provides rubocop annotations in GitHub Actions. This version was
tested in voxpupuli/puppet-wireguard#9.
It was decided that leaving these enabled word create too much
unnecessary work.
@bastelfreak
Copy link
Member

I will merge this now and make a new major release. If the rubocop config doesn't turn out be be useable/we experience trouble we've always the option to adjust it.

@bastelfreak bastelfreak merged commit 36c46e2 into voxpupuli:master Oct 28, 2021
@traylenator
Copy link
Contributor

Thanks for merging - was offline a couple of weeks.

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.

None yet

6 participants