Skip to content

Commit 6913f88

Browse files
committed
rubocop: Fix Style cops
1 parent a0eb4d5 commit 6913f88

File tree

6 files changed

+180
-137
lines changed

6 files changed

+180
-137
lines changed

.rubocop.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@ inherit_from: .rubocop_todo.yml
44
inherit_gem:
55
voxpupuli-rubocop: rubocop.yml
66

7-
Style:
8-
Enabled: false
9-
107
Layout:
118
Enabled: false
129

.rubocop_todo.yml

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2024-06-09 13:09:14 UTC using RuboCop version 1.63.5.
3+
# on 2024-06-09 17:48:43 UTC using RuboCop version 1.63.5.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
@@ -52,7 +52,7 @@ RSpec/MessageSpies:
5252
RSpec/MultipleExpectations:
5353
Max: 2
5454

55-
# Offense count: 49
55+
# Offense count: 40
5656
# Configuration parameters: EnforcedStyle, IgnoreSharedExamples.
5757
# SupportedStyles: always, named_only
5858
RSpec/NamedSubject:
@@ -74,3 +74,60 @@ RSpec/StubbedMock:
7474
Rake/Desc:
7575
Exclude:
7676
- 'Rakefile'
77+
78+
# Offense count: 6
79+
# This cop supports unsafe autocorrection (--autocorrect-all).
80+
# Configuration parameters: EnforcedStyle.
81+
# SupportedStyles: always, always_true, never
82+
Style/FrozenStringLiteralComment:
83+
Exclude:
84+
- 'Gemfile'
85+
- 'Rakefile'
86+
- 'lib/rspec-puppet-facts.rb'
87+
- 'lib/rspec-puppet-facts/version.rb'
88+
- 'spec/rspec_puppet_facts_spec.rb'
89+
- 'spec/spec_helper.rb'
90+
91+
# Offense count: 1
92+
Style/MixinUsage:
93+
Exclude:
94+
- 'spec/spec_helper.rb'
95+
96+
# Offense count: 3
97+
# This cop supports unsafe autocorrection (--autocorrect-all).
98+
# Configuration parameters: EnforcedStyle.
99+
# SupportedStyles: literals, strict
100+
Style/MutableConstant:
101+
Exclude:
102+
- 'lib/rspec-puppet-facts.rb'
103+
- 'lib/rspec-puppet-facts/version.rb'
104+
- 'spec/rspec_puppet_facts_spec.rb'
105+
106+
# Offense count: 1
107+
# This cop supports unsafe autocorrection (--autocorrect-all).
108+
# Configuration parameters: Methods.
109+
Style/RedundantArgument:
110+
Exclude:
111+
- 'lib/rspec-puppet-facts.rb'
112+
113+
# Offense count: 1
114+
# This cop supports unsafe autocorrection (--autocorrect-all).
115+
Style/RedundantSort:
116+
Exclude:
117+
- 'lib/rspec-puppet-facts.rb'
118+
119+
# Offense count: 2
120+
# This cop supports unsafe autocorrection (--autocorrect-all).
121+
# Configuration parameters: ConvertCodeThatCanStartToReturnNil, AllowedMethods, MaxChainLength.
122+
# AllowedMethods: present?, blank?, presence, try, try!
123+
Style/SafeNavigation:
124+
Exclude:
125+
- 'lib/rspec-puppet-facts.rb'
126+
127+
# Offense count: 2
128+
# This cop supports unsafe autocorrection (--autocorrect-all).
129+
# Configuration parameters: RequireEnglish, EnforcedStyle.
130+
# SupportedStyles: use_perl_names, use_english_names, use_builtin_english_names
131+
Style/SpecialGlobalVars:
132+
Exclude:
133+
- 'lib/rspec-puppet-facts.rb'

Gemfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ source ENV['GEM_SOURCE'] || 'https://rubygems.org'
22

33
gemspec
44

5-
gem 'facter', ENV['FACTER_GEM_VERSION'], :require => false
5+
gem 'facter', ENV.fetch('FACTER_GEM_VERSION', nil), require: false
66

77
group :release do
88
gem 'faraday-retry', '~> 2.1', require: false
99
gem 'github_changelog_generator', '~> 1.16.4', require: false
1010
end
1111

1212
group :coverage, optional: ENV['COVERAGE']!='yes' do
13-
gem 'codecov', :require => false
14-
gem 'simplecov-console', :require => false
13+
gem 'codecov', require: false
14+
gem 'simplecov-console', require: false
1515
end

Rakefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ namespace :puppet_versions do
4040

4141
output = `git status --porcelain #{PUPPET_VERSIONS_PATH}`
4242
unless output.strip.empty?
43-
$stderr.puts "#{PUPPET_VERSIONS_PATH} is out of date."
44-
$stderr.puts 'Run the puppet_versions:update task to update it and commit the changes.'
43+
warn "#{PUPPET_VERSIONS_PATH} is out of date."
44+
warn 'Run the puppet_versions:update task to update it and commit the changes.'
4545
raise
4646
end
4747
end
@@ -54,7 +54,7 @@ rescue LoadError
5454
else
5555
require 'rubygems'
5656
GitHubChangelogGenerator::RakeTask.new :changelog do |config|
57-
config.exclude_labels = %w{duplicate question invalid wontfix wont-fix skip-changelog github_actions}
57+
config.exclude_labels = %w[duplicate question invalid wontfix wont-fix skip-changelog github_actions]
5858
config.user = 'voxpupuli'
5959
config.project = 'rspec-puppet-facts'
6060
gem_version = Gem::Specification.load("#{config.project}.gemspec").version

lib/rspec-puppet-facts.rb

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def on_supported_os_implementation(opts = {})
9090
os_release_filter = "\"#{operatingsystemmajrelease}\""
9191
when /Amazon/i
9292
# Tighten the regex for Amazon Linux 2 so that we don't pick up Amazon Linux 2016 or 2017 facts
93-
os_release_filter = "/^2$/" if operatingsystemmajrelease == '2'
93+
os_release_filter = '/^2$/' if operatingsystemmajrelease == '2'
9494
end
9595

9696
filter << {
@@ -110,9 +110,9 @@ def on_supported_os_implementation(opts = {})
110110
end
111111
end
112112

113-
strict_requirement = RspecPuppetFacts::facter_version_to_strict_requirement(facterversion)
113+
strict_requirement = RspecPuppetFacts.facter_version_to_strict_requirement(facterversion)
114114

115-
loose_requirement = RspecPuppetFacts::facter_version_to_loose_requirement(facterversion)
115+
loose_requirement = RspecPuppetFacts.facter_version_to_loose_requirement(facterversion)
116116
received_facts = []
117117

118118
# FacterDB may have newer versions of facter data for which it contains a subset of all possible
@@ -127,9 +127,7 @@ def on_supported_os_implementation(opts = {})
127127
version, facts = versions.select { |v, _f| loose_requirement =~ v }.max_by { |v, _f| v } if loose_requirement
128128
next unless version
129129

130-
if RspecPuppetFacts.spec_facts_strict?
131-
raise ArgumentError, "No facts were found in the FacterDB for Facter v#{facterversion} on #{filter_spec}, aborting"
132-
end
130+
raise ArgumentError, "No facts were found in the FacterDB for Facter v#{facterversion} on #{filter_spec}, aborting" if RspecPuppetFacts.spec_facts_strict?
133131

134132
RspecPuppetFacts.warning "No facts were found in the FacterDB for Facter v#{facterversion} on #{filter_spec}, using v#{version} instead"
135133
end
@@ -193,7 +191,7 @@ def add_custom_fact(name, value, options = {})
193191
def self.register_custom_fact(name, value, options)
194192
@custom_facts ||= {}
195193
name = RSpec.configuration.facterdb_string_keys ? name.to_s : name.to_sym
196-
@custom_facts[name] = {:options => options, :value => value}
194+
@custom_facts[name] = {options: options, value: value}
197195
end
198196

199197
# Adds any custom facts according to the rules defined for the operating
@@ -235,7 +233,7 @@ def self.custom_facts
235233
# @return [nil,String]
236234
# @api private
237235
def self.spec_facts_os_filter
238-
ENV['SPEC_FACTS_OS']
236+
ENV.fetch('SPEC_FACTS_OS', nil)
239237
end
240238

241239
# If SPEC_FACTS_STRICT is set to `yes`, RspecPuppetFacts will error on missing FacterDB entries, instead of warning & skipping the tests, or using an older facter version.
@@ -252,16 +250,14 @@ def self.spec_facts_strict?
252250
def self.common_facts
253251
return @common_facts if @common_facts
254252
@common_facts = {
255-
:puppetversion => Puppet.version,
256-
:rubysitedir => RbConfig::CONFIG['sitelibdir'],
257-
:rubyversion => RUBY_VERSION,
253+
puppetversion: Puppet.version,
254+
rubysitedir: RbConfig::CONFIG['sitelibdir'],
255+
rubyversion: RUBY_VERSION,
258256
}
259257

260258
@common_facts[:mco_version] = MCollective::VERSION if mcollective?
261259

262-
if augeas?
263-
@common_facts[:augeasversion] = Augeas.open(nil, nil, Augeas::NO_MODL_AUTOLOAD).get('/augeas/version')
264-
end
260+
@common_facts[:augeasversion] = Augeas.open(nil, nil, Augeas::NO_MODL_AUTOLOAD).get('/augeas/version') if augeas?
265261
@common_facts = stringify_keys(@common_facts) if RSpec.configuration.facterdb_string_keys
266262

267263
@common_facts
@@ -298,9 +294,7 @@ def self.mcollective?
298294
# @return [Array<Hash>]
299295
# @api private
300296
def self.meta_supported_os
301-
unless metadata['operatingsystem_support'].is_a? Array
302-
fail StandardError, 'Unknown operatingsystem support in the metadata file!'
303-
end
297+
raise StandardError, 'Unknown operatingsystem support in the metadata file!' unless metadata['operatingsystem_support'].is_a? Array
304298
metadata['operatingsystem_support']
305299
end
306300

@@ -311,9 +305,7 @@ def self.meta_supported_os
311305
# @api private
312306
def self.metadata
313307
return @metadata if @metadata
314-
unless File.file? metadata_file
315-
fail StandardError, "Can't find metadata.json... dunno why"
316-
end
308+
raise StandardError, "Can't find metadata.json... dunno why" unless File.file? metadata_file
317309
content = File.read metadata_file
318310
@metadata = JSON.parse content
319311
end
@@ -329,7 +321,7 @@ def self.metadata_file
329321
# @param message [String]
330322
# @api private
331323
def self.warning(message)
332-
STDERR.puts message
324+
warn message
333325
end
334326

335327
# Reset the memoization
@@ -379,9 +371,6 @@ def self.facter_version_to_loose_requirement_string(version)
379371
elsif /\A[0-9]+\Z/.match?(version)
380372
# Interpret 3 as < 4
381373
"< #{version.to_i + 1}"
382-
else
383-
# This would be the same as the strict requirement
384-
nil
385374
end
386375
end
387376

@@ -397,13 +386,13 @@ def self.facter_version_for_puppet_version(puppet_version)
397386
fd = File.open(json_path, 'rb:UTF-8')
398387
data = JSON.parse(fd.read)
399388

400-
version_map = data.map { |_, versions|
389+
version_map = data.map do |_, versions|
401390
if versions['puppet'].nil? || versions['facter'].nil?
402391
nil
403392
else
404393
[Gem::Version.new(versions['puppet']), versions['facter']]
405394
end
406-
}.compact
395+
end.compact
407396

408397
puppet_gem_version = Gem::Version.new(puppet_version)
409398
applicable_versions = version_map.select { |p, _| puppet_gem_version >= p }

0 commit comments

Comments
 (0)