From 5ea987b18c2ca2abdffeecfdc000cfa47e1f68fb Mon Sep 17 00:00:00 2001 From: Tim Meusel Date: Fri, 24 May 2024 10:55:17 +0200 Subject: [PATCH] rubocop: fix save violations --- .rubocop.yml | 1 + .rubocop_todo.yml | 56 +++++++++++++++++++++++++++++++ Gemfile | 10 +++--- Rakefile | 6 ++-- lib/voxpupuli/test.rb | 0 lib/voxpupuli/test/facts.rb | 5 +-- lib/voxpupuli/test/rake.rb | 5 +-- lib/voxpupuli/test/spec_helper.rb | 4 +-- spec/facts_spec.rb | 47 +++++++++++++------------- spec/spec_helper.rb | 4 ++- voxpupuli-test.gemspec | 4 +-- 11 files changed, 103 insertions(+), 39 deletions(-) create mode 100644 .rubocop.yml create mode 100644 .rubocop_todo.yml delete mode 100644 lib/voxpupuli/test.rb diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..cc32da4 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1 @@ +inherit_from: .rubocop_todo.yml diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 0000000..a083d18 --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,56 @@ +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2024-05-24 08:54:49 UTC using RuboCop version 1.50.2. +# The point is for the user to remove these configuration records +# one by one as the offenses are removed from the code base. +# Note that changes in the inspected code, or installation of new +# versions of RuboCop, may require this file to be generated again. + +# Offense count: 1 +# Configuration parameters: AllowComments, AllowNil. +Lint/SuppressedException: + Exclude: + - 'Rakefile' + +# Offense count: 1 +# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes. +Metrics/AbcSize: + Max: 23 + +# Offense count: 3 +# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns. +# AllowedMethods: refine +Metrics/BlockLength: + Max: 80 + +# Offense count: 1 +# Configuration parameters: AllowedMethods, AllowedPatterns. +Metrics/CyclomaticComplexity: + Max: 13 + +# Offense count: 1 +# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns. +Metrics/MethodLength: + Max: 28 + +# Offense count: 3 +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: EnforcedStyle. +# SupportedStyles: always, always_true, never +Style/FrozenStringLiteralComment: + Exclude: + - 'lib/voxpupuli/test/facts.rb' + - 'lib/voxpupuli/test/rake.rb' + - 'lib/voxpupuli/test/spec_helper.rb' + +# Offense count: 1 +Style/MixinUsage: + Exclude: + - 'lib/voxpupuli/test/facts.rb' + +# Offense count: 1 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns. +# URISchemes: http, https +Layout/LineLength: + Max: 136 diff --git a/Gemfile b/Gemfile index 5b2c938..d383607 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,5 @@ +# frozen_string_literal: true + source 'https://rubygems.org' gemspec @@ -7,10 +9,10 @@ group :release do gem 'github_changelog_generator', '~> 1.16.4', require: false end -group :coverage, optional: ENV['COVERAGE']!='yes' do - gem 'simplecov-console', :require => false - gem 'codecov', :require => false +group :coverage, optional: ENV['COVERAGE'] != 'yes' do + gem 'codecov', require: false + gem 'simplecov-console', require: false end # Override gemspec for CI matrix builds. -gem 'puppet', ENV.fetch('PUPPET_VERSION', '>= 7.24'), :require => false +gem 'puppet', ENV.fetch('PUPPET_VERSION', '>= 7.24'), require: false diff --git a/Rakefile b/Rakefile index eac57e5..a477cbb 100644 --- a/Rakefile +++ b/Rakefile @@ -1,15 +1,17 @@ +# frozen_string_literal: true + require 'rspec/core/rake_task' RSpec::Core::RakeTask.new(:spec) -task :default => :spec +task default: :spec begin require 'github_changelog_generator/task' GitHubChangelogGenerator::RakeTask.new :changelog do |config| config.header = "# Changelog\n\nAll notable changes to this project will be documented in this file." - config.exclude_labels = %w{duplicate question invalid wontfix wont-fix skip-changelog} + config.exclude_labels = %w[duplicate question invalid wontfix wont-fix skip-changelog] config.user = 'voxpupuli' config.project = 'voxpupuli-test' config.future_release = "v#{Gem::Specification.load("#{config.project}.gemspec").version}" diff --git a/lib/voxpupuli/test.rb b/lib/voxpupuli/test.rb deleted file mode 100644 index e69de29..0000000 diff --git a/lib/voxpupuli/test/facts.rb b/lib/voxpupuli/test/facts.rb index ea33b6d..efac254 100644 --- a/lib/voxpupuli/test/facts.rb +++ b/lib/voxpupuli/test/facts.rb @@ -60,6 +60,7 @@ def add_facts_for_metadata(metadata) def normalize_module_name(name) return unless name + name.sub('-', '/') end @@ -70,7 +71,7 @@ def add_stdlib_facts # Rough conversion of grepping in the puppet source: # grep defaultfor lib/puppet/provider/service/*.rb - add_custom_fact :service_provider, ->(_os, facts) do + add_custom_fact :service_provider, lambda { |_os, facts| os = RSpec.configuration.facterdb_string_keys ? facts['os'] : facts[:os] case os['family'].downcase when 'archlinux' @@ -94,5 +95,5 @@ def add_stdlib_facts else 'init' end - end + } end diff --git a/lib/voxpupuli/test/rake.rb b/lib/voxpupuli/test/rake.rb index fd2c101..113cf0f 100644 --- a/lib/voxpupuli/test/rake.rb +++ b/lib/voxpupuli/test/rake.rb @@ -1,6 +1,6 @@ require 'puppetlabs_spec_helper/rake_tasks' -PuppetLint.configuration.log_format = '%{path}:%{line}:%{check}:%{KIND}:%{message}' +PuppetLint.configuration.log_format = '%s:%s:%s:%s:%s' # without this, puppet-lint always gives an exit code of 0 PuppetLint.configuration.fail_on_warnings = true @@ -14,8 +14,9 @@ task :trailing_whitespace do Dir.glob('**/*.md', File::FNM_DOTMATCH).sort.each do |filename| next if filename =~ %r{^((modules|acceptance|\.?vendor|spec/fixtures|pkg)/|REFERENCE.md)} + File.foreach(filename).each_with_index do |line, index| - if line =~ %r{\s\n$} + if line =~ /\s\n$/ puts "#{filename} has trailing whitespace on line #{index + 1}" exit 1 end diff --git a/lib/voxpupuli/test/spec_helper.rb b/lib/voxpupuli/test/spec_helper.rb index 6022b13..8d2aacf 100644 --- a/lib/voxpupuli/test/spec_helper.rb +++ b/lib/voxpupuli/test/spec_helper.rb @@ -2,9 +2,7 @@ # puppetlabs_spec_helper defaults to mocha but emits a deprecation warning # Vox Pupuli prefers rspec to avoid the deprecation warning unless explicitly # set - if config.instance_variable_get(:@mock_framework).nil? - config.mock_with :rspec - end + config.mock_with :rspec if config.instance_variable_get(:@mock_framework).nil? end require 'voxpupuli/test/facts' diff --git a/spec/facts_spec.rb b/spec/facts_spec.rb index 0b29bd7..88b6e92 100644 --- a/spec/facts_spec.rb +++ b/spec/facts_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' require 'voxpupuli/test/facts' @@ -11,7 +13,7 @@ 'full' => '7.7.1908', 'major' => '7', 'minor' => '7' - }, + } } } end @@ -26,7 +28,7 @@ 'full' => '7.7.1908', 'major' => '7', 'minor' => '7' - }, + } } } end @@ -44,15 +46,15 @@ 'full' => '7.7.1908', 'major' => '7', 'minor' => '7' - }, + } }, ruby: { - 'sitedir' => '/usr/local/share/ruby/site_ruby', + 'sitedir' => '/usr/local/share/ruby/site_ruby' } } end - it { expect(override_facts(base_facts, ruby: {sitedir: '/usr/local/share/ruby/site_ruby'})).to eq(expected) } + it { expect(override_facts(base_facts, ruby: { sitedir: '/usr/local/share/ruby/site_ruby' })).to eq(expected) } end describe 'with deep merging' do @@ -65,12 +67,12 @@ 'full' => '7.7.1908', 'major' => '7', 'minor' => '8' - }, + } } } end - it { expect(override_facts(base_facts, os: {release: {minor: '8'}})).to eq(expected) } + it { expect(override_facts(base_facts, os: { release: { minor: '8' } })).to eq(expected) } end describe 'with strings' do @@ -83,12 +85,12 @@ 'full' => '7.7.1908', 'major' => '7', 'minor' => '8' - }, + } } } end - it { expect(override_facts(base_facts, os: {'release' => {minor: '8'}})).to eq(expected) } + it { expect(override_facts(base_facts, os: { 'release' => { minor: '8' } })).to eq(expected) } end end @@ -112,7 +114,7 @@ context 'with systemd' do let(:dependencies) do [ - {'name' => 'puppet/systemd'}, + { 'name' => 'puppet/systemd' } ] end @@ -124,32 +126,29 @@ context 'and stdlib' do let(:dependencies) do [ - {'name' => 'puppetlabs/stdlib'}, - {'name' => 'puppet/systemd'}, + { 'name' => 'puppetlabs/stdlib' }, + { 'name' => 'puppet/systemd' } ] end it 'has systemd on Red Hat 7' do add_facts_for_metadata(metadata) - facts = RspecPuppetFacts.with_custom_facts('redhat-7-x86_64', { - os: { 'family' => 'RedHat', 'release' => { 'major' => '7' } } - }) + facts = RspecPuppetFacts.with_custom_facts('redhat-7-x86_64', { os: { 'family' => 'RedHat', 'release' => { 'major' => '7' } } }) expect(facts['systemd']).to be true end it 'has no systemd on Red Hat 6' do add_facts_for_metadata(metadata) - facts = RspecPuppetFacts.with_custom_facts('redhat-6-x86_64', { - os: {'family' => 'RedHat', 'release' => { 'major' => '6' }} - }) + facts = RspecPuppetFacts.with_custom_facts('redhat-6-x86_64', + { os: { 'family' => 'RedHat', 'release' => { 'major' => '6' } } }) expect(facts['systemd']).to be false end it 'has no systemd on openbsd' do add_facts_for_metadata(metadata) facts = RspecPuppetFacts.with_custom_facts('openbsd-6.4-x86_64', { - os: { 'family' => 'OpenBSD' } - }) + os: { 'family' => 'OpenBSD' } + }) expect(facts['systemd']).to be false end end @@ -158,13 +157,15 @@ context 'with stdlib' do let(:dependencies) do [ - {'name' => 'puppetlabs/stdlib'}, + { 'name' => 'puppetlabs/stdlib' } ] end it 'adds the systemd fact' do - expect(RspecPuppetFacts).to receive(:register_custom_fact).with(:puppet_environmentpath, '/etc/puppetlabs/code/environments', {}) - expect(RspecPuppetFacts).to receive(:register_custom_fact).with(:puppet_vardir, '/opt/puppetlabs/puppet/cache', {}) + expect(RspecPuppetFacts).to receive(:register_custom_fact).with(:puppet_environmentpath, + '/etc/puppetlabs/code/environments', {}) + expect(RspecPuppetFacts).to receive(:register_custom_fact).with(:puppet_vardir, '/opt/puppetlabs/puppet/cache', + {}) expect(RspecPuppetFacts).to receive(:register_custom_fact).with(:root_home, '/root', {}) expect(RspecPuppetFacts).to receive(:register_custom_fact).with(:service_provider, instance_of(Proc), {}) add_facts_for_metadata(metadata) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 73fb578..ae3a767 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + begin require 'simplecov' require 'simplecov-console' @@ -18,7 +20,7 @@ SimpleCov.formatters = [ SimpleCov::Formatter::Console, - SimpleCov::Formatter::Codecov, + SimpleCov::Formatter::Codecov ] end diff --git a/voxpupuli-test.gemspec b/voxpupuli-test.gemspec index b9df7d6..ba37e90 100644 --- a/voxpupuli-test.gemspec +++ b/voxpupuli-test.gemspec @@ -1,4 +1,4 @@ -# -*- encoding: utf-8 -*- +# frozen_string_literal: true Gem::Specification.new do |s| s.name = 'voxpupuli-test' @@ -32,8 +32,8 @@ Gem::Specification.new do |s| # newest versions that still support Ruby 2.6 # jruby 9.3 in Puppetserver 7 is compatible with C Ruby 2.6 s.add_runtime_dependency 'rubocop', '~> 1.50.0' - s.add_runtime_dependency 'rubocop-rspec', '~> 2.20.0' s.add_runtime_dependency 'rubocop-rake', '~> 0.6.0' + s.add_runtime_dependency 'rubocop-rspec', '~> 2.20.0' # Linting # meta gem to pull in all puppet-lint plugins + puppet-lint itself