From c017b0dcecb64b72d89c0d2a4016b3505e4a8efd Mon Sep 17 00:00:00 2001 From: Ewoud Kohl van Wijngaarden Date: Thu, 17 Nov 2022 10:52:06 +0100 Subject: [PATCH] Update RuboCop --- .github/workflows/main.yml | 6 +++++- vagrant/.rubocop.yml | 17 ++++++++++------- vagrant/Gemfile | 19 +++++++------------ vagrant/Rakefile | 3 +-- vagrant/lib/forklift.rb | 4 ++-- vagrant/lib/forklift/box_distributor.rb | 6 +++--- vagrant/lib/forklift/box_factory.rb | 2 +- 7 files changed, 29 insertions(+), 28 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index d946bd9df..48d9f18b6 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -59,6 +59,10 @@ jobs: ruby-version: ${{ matrix.ruby }} bundler-cache: true working-directory: vagrant + - name: Run Rubocop + run: bundle exec rubocop --format github + if: matrix.ruby == '3.1' + working-directory: vagrant - name: Run tests - run: bundle exec rake + run: bundle exec rake test working-directory: vagrant diff --git a/vagrant/.rubocop.yml b/vagrant/.rubocop.yml index 0514afeb1..1fdd607f6 100644 --- a/vagrant/.rubocop.yml +++ b/vagrant/.rubocop.yml @@ -1,15 +1,18 @@ +require: + - rubocop-minitest + - rubocop-rake + AllCops: Include: - '**/Rakefile' - 'lib/**/*.rb' - 'test/**/*.rb' Exclude: - - !ruby/regexp /katello-installer/ - - !ruby/regexp /.spec/ - 'vendor/**/*' - TargetRubyVersion: 2.0 + TargetRubyVersion: '2.7' + NewCops: enable -Metrics/LineLength: +Layout/LineLength: Max: 120 Metrics/ClassLength: @@ -18,14 +21,14 @@ Metrics/ClassLength: Metrics/BlockLength: Max: 50 -Documentation: +Style/Documentation: Enabled: false # don't require documentation -MethodLength: +Metrics/MethodLength: Description: 'Avoid methods longer than 30 lines of code.' Max: 30 -HashSyntax: +Style/HashSyntax: Enabled: false # don't force 1.9 hash syntax Layout/EmptyLinesAroundClassBody: diff --git a/vagrant/Gemfile b/vagrant/Gemfile index 2b7b86d04..4d24f6042 100644 --- a/vagrant/Gemfile +++ b/vagrant/Gemfile @@ -1,21 +1,16 @@ -# rubocop:disable Naming/FileName source 'https://rubygems.org' -if RUBY_VERSION < '2.1' - gem 'psych', '~> 2.0' -end - group :test do gem 'deep_merge' gem 'json' gem 'minitest' gem 'mocha' gem 'rake' - if RUBY_VERSION < '3.1' - # we need a rubocop that still can manage Ruby 2.0 code - # but 0.49.x is not compatible with Ruby 3.1 - gem 'rubocop', '<0.50' - end -end -# rubocop:enable Naming/FileName + # Make sure the Ruby version is supported + # https://docs.rubocop.org/rubocop/compatibility.html#support-matrix + gem 'rubocop', '~> 1.56.0' + gem 'rubocop-minitest' + gem 'rubocop-performance' + gem 'rubocop-rake' +end diff --git a/vagrant/Rakefile b/vagrant/Rakefile index 61425af1c..d0ba116b8 100644 --- a/vagrant/Rakefile +++ b/vagrant/Rakefile @@ -13,8 +13,7 @@ default_tasks = %i[test] begin require 'rubocop/rake_task' RuboCop::RakeTask.new - # insert 0, because Ruby 2.0 doesn't know Array.prepend - default_tasks.insert(0, 'rubocop') + default_tasks.prepend('rubocop') rescue LoadError puts 'Rubocop not loaded' end diff --git a/vagrant/lib/forklift.rb b/vagrant/lib/forklift.rb index ae500edb7..a27bc8de1 100644 --- a/vagrant/lib/forklift.rb +++ b/vagrant/lib/forklift.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true -$LOAD_PATH.unshift File.dirname(__FILE__) +$LOAD_PATH.unshift __dir__ -files = Dir[File.dirname(__FILE__) + '/forklift/**/*.rb'] +files = Dir["#{__dir__}/forklift/**/*.rb"] files.uniq.each { |f| require f } module Forklift diff --git a/vagrant/lib/forklift/box_distributor.rb b/vagrant/lib/forklift/box_distributor.rb index 86afe1a33..ba56dd631 100644 --- a/vagrant/lib/forklift/box_distributor.rb +++ b/vagrant/lib/forklift/box_distributor.rb @@ -5,7 +5,7 @@ module Forklift class BoxDistributor - VAGRANTFILE_API_VERSION = '2'.freeze + VAGRANTFILE_API_VERSION = '2' def initialize(boxes) @ansible_groups = {} @@ -177,12 +177,12 @@ def configure_networks(networks) def configure_ansible(machine, ansible, box_name) return unless ansible - if ansible.key?('group') && !ansible['group'].nil? + unless ansible['group'].nil? @ansible_groups[ansible['group'].to_s] ||= [] @ansible_groups[ansible['group'].to_s] << box_name end - if ansible.key?('server') && !ansible['server'].nil? + unless ansible['server'].nil? @ansible_groups["server-#{box_name}"] = ansible['server'] end diff --git a/vagrant/lib/forklift/box_factory.rb b/vagrant/lib/forklift/box_factory.rb index a23ce0c98..6fe596c66 100644 --- a/vagrant/lib/forklift/box_factory.rb +++ b/vagrant/lib/forklift/box_factory.rb @@ -31,7 +31,7 @@ def add_boxes!(box_file) def filter_boxes! box_config = Settings.new.settings['boxes'] - return unless box_config && box_config.key?('exclude') + return unless box_config&.key?('exclude') @boxes.reject! do |name, _box| box_config['exclude'].any? { |exclude| name.match(/#{exclude}/) }