Skip to content

Commit

Permalink
Merge pull request #130 from bastelfreak/rubocop2
Browse files Browse the repository at this point in the history
Add rubocop config
  • Loading branch information
bastelfreak authored Jul 5, 2024
2 parents 6b8c448 + aa61dc4 commit bf10e92
Show file tree
Hide file tree
Showing 12 changed files with 189 additions and 40 deletions.
12 changes: 12 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ env:
BUNDLE_WITHOUT: release

jobs:
rubocop:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Ruby ${{ matrix.ruby }}
uses: ruby/setup-ruby@v1
with:
ruby-version: "3.3"
bundler-cache: true
- name: Run Rubocop
run: bundle exec rake rubocop
test:
runs-on: ubuntu-latest
strategy:
Expand Down Expand Up @@ -45,6 +56,7 @@ jobs:
run: bundle exec rake spec
tests:
needs:
- rubocop
- test
runs-on: ubuntu-latest
name: Test suite
Expand Down
41 changes: 41 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
---
require:
- rubocop-rake
- rubocop-rspec

# this alligns with our settings in voxpupuli-rubocop
# but we cannot depend on that because it pulls in newer rubocop versions,
# which would break our modules on legacy puppetserver
AllCops:
NewCops: enable
DisplayCopNames: true
ExtraDetails: true
DisplayStyleGuide: true

# this currently doesn't work with the way we handle our secrets
Gemspec/RequireMFA:
Enabled: false

# Vox Pupuli default is to use `add_development_dependency` in the gemspec
Gemspec/DevelopmentDependencies:
Enabled: false

Style/TernaryParentheses:
EnforcedStyle: require_parentheses_when_complex

Style/TrailingCommaInHashLiteral:
Enabled: true
EnforcedStyleForMultiline: consistent_comma

Style/TrailingCommaInArrayLiteral:
Enabled: true
EnforcedStyleForMultiline: consistent_comma

Style/TrailingCommaInArguments:
Enabled: true
EnforcedStyleForMultiline: comma

Style/IfUnlessModifier:
Enabled: false

inherit_from: .rubocop_todo.yml
72 changes: 72 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2024-06-21 10:27:03 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: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
Metrics/AbcSize:
Max: 18

# Offense count: 1
# Configuration parameters: AllowedMethods, AllowedPatterns.
Metrics/CyclomaticComplexity:
Max: 10

# Offense count: 1
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
Metrics/MethodLength:
Max: 24

# Offense count: 1
# Configuration parameters: Prefixes, AllowedPatterns.
# Prefixes: when, with, without
RSpec/ContextWording:
Exclude:
- 'spec/facts_spec.rb'

# Offense count: 2
# Configuration parameters: IgnoredMetadata.
RSpec/DescribeClass:
Exclude:
- '**/spec/features/**/*'
- '**/spec/requests/**/*'
- '**/spec/routing/**/*'
- '**/spec/system/**/*'
- '**/spec/views/**/*'
- 'spec/facts_spec.rb'

# Offense count: 1
# Configuration parameters: CountAsOne.
RSpec/ExampleLength:
Max: 7

# Offense count: 6
# Configuration parameters: .
# SupportedStyles: have_received, receive
RSpec/MessageSpies:
EnforcedStyle: receive

# Offense count: 1
RSpec/MultipleDescribes:
Exclude:
- 'spec/facts_spec.rb'

# Offense count: 1
RSpec/MultipleExpectations:
Max: 4

# 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
10 changes: 6 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

source 'https://rubygems.org'

gemspec
Expand All @@ -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
16 changes: 14 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,19 +1,31 @@
# 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}"
end
rescue LoadError
# Optional gem, release group is probably disabled
end

# this is identical to our config in voxpupuli-rubocop, but that gem targets Ruby 2.7
# and voxupuli-test depends on an older rubocop version because we provide it for our modules
require 'rubocop/rake_task'
RuboCop::RakeTask.new(:rubocop) do |task|
# These make the rubocop experience maybe slightly less terrible
task.options = ['--display-cop-names', '--display-style-guide', '--extra-details']
# Use Rubocop's Github Actions formatter if possible
task.formatters << 'github' if ENV['GITHUB_ACTIONS'] == 'true'
end
Empty file removed lib/voxpupuli/test.rb
Empty file.
9 changes: 6 additions & 3 deletions lib/voxpupuli/test/facts.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'rspec-puppet-facts'
include RspecPuppetFacts

Expand Down Expand Up @@ -60,6 +62,7 @@ def add_facts_for_metadata(metadata)

def normalize_module_name(name)
return unless name

name.sub('-', '/')
end

Expand All @@ -70,7 +73,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', 'debian', 'redhat'
Expand All @@ -84,11 +87,11 @@ def add_stdlib_facts
when 'openbsd'
'openbsd'
when 'suse'
os['release']['major'].to_i >= 12 ? 'systemd' : 'redhat'
(os['release']['major'].to_i >= 12) ? 'systemd' : 'redhat'
when 'windows'
'windows'
else
'init'
end
end
}
end
7 changes: 5 additions & 2 deletions lib/voxpupuli/test/rake.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# frozen_string_literal: true

require 'puppetlabs_spec_helper/rake_tasks'

PuppetLint.configuration.log_format = '%{path}:%{line}:%{check}:%{KIND}:%{message}'
PuppetLint.configuration.log_format = '%<path>s:%<line>s:%<check>s:%<KIND>s:%<message>s'
# without this, puppet-lint always gives an exit code of 0
PuppetLint.configuration.fail_on_warnings = true

Expand All @@ -16,8 +18,9 @@

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$/
errors << "#{filename} has trailing whitespace on line #{index + 1}"
end
end
Expand Down
2 changes: 2 additions & 0 deletions lib/voxpupuli/test/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'voxpupuli/test/facts'
require 'puppetlabs_spec_helper/module_spec_helper'

Expand Down
Loading

0 comments on commit bf10e92

Please sign in to comment.