Skip to content

Commit fc931ae

Browse files
authored
Merge pull request #146 from ekohl/rubocop
Introduce RuboCop and fix various cops
2 parents ae75c7a + 8b8773b commit fc931ae

File tree

9 files changed

+342
-169
lines changed

9 files changed

+342
-169
lines changed

.github/dependabot.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
version: 2
22
updates:
3+
# raise PRs for gem updates
34
- package-ecosystem: bundler
45
directory: "/"
56
schedule:
67
interval: daily
7-
time: "04:00"
8+
time: "13:00"
9+
open-pull-requests-limit: 10
10+
11+
# Maintain dependencies for GitHub Actions
12+
- package-ecosystem: github-actions
13+
directory: "/"
14+
schedule:
15+
interval: daily
16+
time: "13:00"
817
open-pull-requests-limit: 10

.github/workflows/test.yml

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,28 @@
11
name: Test
22

33
on:
4-
- pull_request
5-
- push
4+
pull_request: {}
5+
push:
6+
branches:
7+
- master
68

79
env:
810
BUNDLE_WITHOUT: release
911

1012
jobs:
13+
rubocop:
14+
env:
15+
BUNDLE_WITHOUT: release
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v3
19+
- name: Install Ruby ${{ matrix.ruby }}
20+
uses: ruby/setup-ruby@v1
21+
with:
22+
ruby-version: "3.0"
23+
bundler-cache: true
24+
- name: Run Rubocop
25+
run: bundle exec rake rubocop
1126
test:
1227
runs-on: ubuntu-latest
1328
strategy:

.rubocop.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
---
2+
inherit_from: .rubocop_todo.yml
3+
4+
require:
5+
- rubocop-performance
6+
- rubocop-rake
7+
- rubocop-rspec
8+
9+
AllCops:
10+
NewCops: enable
11+
TargetRubyVersion: '2.4'
12+
13+
Style/TrailingCommaInHashLiteral:
14+
Enabled: True
15+
EnforcedStyleForMultiline: consistent_comma
16+
17+
Style/TrailingCommaInArrayLiteral:
18+
Enabled: True
19+
EnforcedStyleForMultiline: consistent_comma
20+
21+
Style/TrailingCommaInArguments:
22+
Enabled: True
23+
EnforcedStyleForMultiline: comma
24+
25+
Metrics:
26+
Enabled: false
27+
28+
Style:
29+
Enabled: false
30+
31+
Layout:
32+
Enabled: false
33+
34+
# To match the gem name
35+
Naming/FileName:
36+
Exclude:
37+
- 'lib/rspec-puppet-facts.rb'

.rubocop_todo.yml

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# This configuration was generated by
2+
# `rubocop --auto-gen-config`
3+
# on 2023-03-17 10:58:25 UTC using RuboCop version 1.12.1.
4+
# The point is for the user to remove these configuration records
5+
# one by one as the offenses are removed from the code base.
6+
# Note that changes in the inspected code, or installation of new
7+
# versions of RuboCop, may require this file to be generated again.
8+
9+
# Offense count: 32
10+
# Configuration parameters: Prefixes.
11+
# Prefixes: when, with, without
12+
RSpec/ContextWording:
13+
Exclude:
14+
- 'spec/rspec_puppet_facts_spec.rb'
15+
16+
# Offense count: 7
17+
# Configuration parameters: CountAsOne.
18+
RSpec/ExampleLength:
19+
Max: 13
20+
21+
# Offense count: 1
22+
RSpec/ExpectInHook:
23+
Exclude:
24+
- 'spec/rspec_puppet_facts_spec.rb'
25+
26+
# Offense count: 20
27+
# Cop supports --auto-correct.
28+
# Configuration parameters: EnforcedStyle.
29+
# SupportedStyles: single_line_only, single_statement_only, disallow
30+
RSpec/ImplicitSubject:
31+
Exclude:
32+
- 'spec/rspec_puppet_facts_spec.rb'
33+
34+
# Offense count: 4
35+
RSpec/LeakyConstantDeclaration:
36+
Exclude:
37+
- 'spec/rspec_puppet_facts_spec.rb'
38+
39+
# Offense count: 7
40+
# Configuration parameters: .
41+
# SupportedStyles: have_received, receive
42+
RSpec/MessageSpies:
43+
EnforcedStyle: receive
44+
45+
# Offense count: 4
46+
RSpec/MultipleExpectations:
47+
Max: 2
48+
49+
# Offense count: 46
50+
# Configuration parameters: IgnoreSharedExamples.
51+
RSpec/NamedSubject:
52+
Exclude:
53+
- 'spec/rspec_puppet_facts_spec.rb'
54+
55+
# Offense count: 14
56+
RSpec/NestedGroups:
57+
Max: 6
58+
59+
# Offense count: 1
60+
RSpec/StubbedMock:
61+
Exclude:
62+
- 'spec/rspec_puppet_facts_spec.rb'
63+
64+
# Offense count: 2
65+
# Cop supports --auto-correct.
66+
Rake/Desc:
67+
Exclude:
68+
- 'Rakefile'

Gemfile

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

33
gemspec
44

5-
if facterversion = ENV['FACTER_GEM_VERSION']
6-
gem 'facter', facterversion, :require => false
7-
else
8-
gem 'facter', :require => false
9-
end
5+
gem 'facter', ENV['FACTER_GEM_VERSION'], :require => false
106

117
group :release do
128
gem 'github_changelog_generator', require: false
139
end
1410

1511
group :coverage, optional: ENV['COVERAGE']!='yes' do
16-
gem 'simplecov-console', :require => false
1712
gem 'codecov', :require => false
13+
gem 'simplecov-console', :require => false
1814
end

Rakefile

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ begin
88
RSpec::Core::RakeTask.new(:spec)
99
YARD::Rake::YardocTask.new
1010
rescue LoadError
11+
# yard is optional
1112
end
1213

1314
desc 'Produce Commit history since last tag'
@@ -60,4 +61,20 @@ begin
6061
config.future_release = gem_version
6162
end
6263
rescue LoadError
64+
# Changelog generator is optional
65+
end
66+
67+
begin
68+
require 'rubocop/rake_task'
69+
rescue LoadError
70+
# RuboCop is an optional group
71+
else
72+
RuboCop::RakeTask.new(:rubocop) do |task|
73+
# These make the rubocop experience maybe slightly less terrible
74+
task.options = ['--display-cop-names', '--display-style-guide', '--extra-details']
75+
# Use Rubocop's Github Actions formatter if possible
76+
if ENV['GITHUB_ACTIONS'] == 'true'
77+
task.formatters << 'github'
78+
end
79+
end
6380
end

lib/rspec-puppet-facts.rb

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def on_supported_os(opts = {})
5656
#
5757
# @api private
5858
def on_supported_os_implementation(opts = {})
59-
unless (facterversion = opts[:facterversion]) =~ /\A\d+\.\d+(?:\.\d+)*\z/
59+
unless /\A\d+\.\d+(?:\.\d+)*\z/.match?((facterversion = opts[:facterversion]))
6060
raise ArgumentError, ":facterversion must be in the format 'n.n' or " \
6161
"'n.n.n' (n is numeric), not '#{facterversion}'"
6262
end
@@ -68,19 +68,20 @@ def on_supported_os_implementation(opts = {})
6868
opts[:hardwaremodels].each do |hardwaremodel|
6969

7070
os_release_filter = "/^#{Regexp.escape(operatingsystemmajrelease.split(' ')[0])}/"
71-
if os_sup['operatingsystem'] =~ /BSD/i
71+
case os_sup['operatingsystem']
72+
when /BSD/i
7273
hardwaremodel = 'amd64'
73-
elsif os_sup['operatingsystem'] =~ /Solaris/i
74+
when /Solaris/i
7475
hardwaremodel = 'i86pc'
75-
elsif os_sup['operatingsystem'] =~ /AIX/i
76+
when /AIX/i
7677
hardwaremodel = '/^IBM,.*/'
7778
os_release_filter = if operatingsystemmajrelease =~ /\A(\d+)\.(\d+)\Z/
7879
"/^#{$~[1]}#{$~[2]}00-/"
7980
else
8081
"/^#{operatingsystemmajrelease}-/"
8182
end
82-
elsif os_sup['operatingsystem'] =~ /Windows/i
83-
hardwaremodel = facterversion =~ /^[12]\./ ? 'x64' : 'x86_64'
83+
when /Windows/i
84+
hardwaremodel = /^[12]\./.match?(facterversion) ? 'x64' : 'x86_64'
8485
os_sup['operatingsystem'] = os_sup['operatingsystem'].downcase
8586
operatingsystemmajrelease = operatingsystemmajrelease[/\A(?:Server )?(.+)/i, 1]
8687

@@ -90,7 +91,7 @@ def on_supported_os_implementation(opts = {})
9091
if operatingsystemmajrelease == '2016' && Puppet::Util::Package.versioncmp(facterversion, '3.4') < 0
9192
os_release_filter = '/^10\\.0\\./'
9293
end
93-
elsif os_sup['operatingsystem'] =~ /Amazon/i
94+
when /Amazon/i
9495
# Tighten the regex for Amazon Linux 2 so that we don't pick up Amazon Linux 2016 or 2017 facts
9596
os_release_filter = "/^2$/" if operatingsystemmajrelease == '2'
9697
end

rspec-puppet-facts.gemspec

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,13 @@ Gem::Specification.new do |s|
2424
s.add_development_dependency 'rake'
2525
s.add_development_dependency 'rspec'
2626
s.add_development_dependency 'yard'
27-
s.add_runtime_dependency 'puppet'
27+
28+
s.add_development_dependency 'rubocop', '~> 1.12.0'
29+
s.add_development_dependency 'rubocop-performance'
30+
s.add_development_dependency 'rubocop-rake'
31+
s.add_development_dependency 'rubocop-rspec'
32+
2833
s.add_runtime_dependency 'facter'
2934
s.add_runtime_dependency 'facterdb', '>= 0.5.0'
35+
s.add_runtime_dependency 'puppet'
3036
end

0 commit comments

Comments
 (0)