Skip to content

Commit

Permalink
Merge pull request #23 from voxpupuli/modulesync
Browse files Browse the repository at this point in the history
Drop Ruby < 2.7; Add RuboCop
  • Loading branch information
bastelfreak committed Apr 21, 2023
2 parents 83477bc + f7b8e14 commit 916a6c2
Show file tree
Hide file tree
Showing 10 changed files with 140 additions and 39 deletions.
8 changes: 8 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,11 @@ updates:
interval: daily
time: "13:00"
open-pull-requests-limit: 10

# Maintain dependencies for GitHub Actions
- package-ecosystem: github-actions
directory: "/"
schedule:
interval: daily
time: "13:00"
open-pull-requests-limit: 10
4 changes: 3 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ jobs:
with:
ruby-version: '3.0'
bundler: 'none'
env:
BUNDLE_WITHOUT: release:development:rubocop
- name: Build gem
run: gem build *.gemspec
run: gem build --strict --verbose *.gemspec
- name: Publish gem to rubygems.org
run: gem push *.gem
env:
Expand Down
26 changes: 22 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,34 @@ on:
push:
branches:
- master
- main

env:
BUNDLE_WITHOUT: release

jobs:
rubocop:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: '3.0'
bundler-cache: true
- name: Run rake rubocop
run: bundle exec rake rubocop
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
include:
- ruby: "2.4"
- ruby: "2.5"
- ruby: "2.6"
- ruby: "2.7"
- ruby: "3.0"
- ruby: "3.1"
coverage: "yes"
- ruby: "3.2"
env:
COVERAGE: ${{ matrix.coverage }}
name: Ruby ${{ matrix.ruby }}
Expand All @@ -36,4 +46,12 @@ jobs:
- name: Run tests
run: bundle exec rake spec
- name: Verify gem builds
run: gem build *.gemspec
run: gem build --strict --verbose *.gemspec
tests:
needs:
- rubocop
- test
runs-on: ubuntu-latest
name: Test suite
steps:
- run: echo Test suite completed
13 changes: 13 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
inherit_from: .rubocop_todo.yml


# Managed by modulesync - DO NOT EDIT
# https://voxpupuli.org/docs/updating-files-managed-with-modulesync/

inherit_gem:
voxpupuli-rubocop: rubocop.yml

Naming/FileName:
Exclude:
- "*.gemspec"
37 changes: 37 additions & 0 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2023-04-21 12:16:47 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: IgnoredMetadata.
RSpec/DescribeClass:
Exclude:
- '**/spec/features/**/*'
- '**/spec/requests/**/*'
- '**/spec/routing/**/*'
- '**/spec/system/**/*'
- '**/spec/views/**/*'
- 'spec/puppet-lint/plugins/topscope_variable_spec.rb'

# Offense count: 5
# This cop supports unsafe autocorrection (--autocorrect-all).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: always, always_true, never
Style/FrozenStringLiteralComment:
Exclude:
- 'Gemfile'
- 'Rakefile'
- 'lib/puppet-lint/plugins/topscope_variable.rb'
- 'puppet-lint-topscope-variable-check.gemspec'
- 'spec/puppet-lint/plugins/topscope_variable_spec.rb'

# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns.
# URISchemes: http, https
Layout/LineLength:
Max: 142
17 changes: 13 additions & 4 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,19 @@ source ENV['GEM_SOURCE'] || 'https://rubygems.org'
gemspec

group :release do
gem 'github_changelog_generator', require: false
gem 'faraday-retry', '~> 2.1', require: false
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

group :development do
gem 'rake', '~> 13.0', '>= 13.0.6'
gem 'rspec', '~> 3.12'
gem 'rspec-collection_matchers', '~> 1.2'
gem 'rspec-its', '~> 1.3'
gem 'voxpupuli-rubocop', '~> 1.1'
end
19 changes: 17 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,28 @@ task default: :spec
begin
require 'rubygems'
require 'github_changelog_generator/task'

rescue LoadError
# github-changelog-generator is an optional group
else
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 modulesync}
config.exclude_labels = %w[duplicate question invalid wontfix wont-fix skip-changelog modulesync]
config.user = 'voxpupuli'
config.project = 'puppet-lint-topscope-variable-check'
config.future_release = Gem::Specification.load("#{config.project}.gemspec").version
end
end

begin
require 'rubocop/rake_task'
rescue LoadError
# RuboCop is an optional group
else
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
end
5 changes: 3 additions & 2 deletions lib/puppet-lint/plugins/topscope_variable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ def check
return if class_list.first.nil?

tokens.select { |x| x.type == :VARIABLE }.each do |token|
next if token.value !~ /^::[a-z0-9_][a-zA-Z0-9_]+::/
next unless /^::[a-z0-9_][a-zA-Z0-9_]+::/.match?(token.value)

fixed = token.value.sub(/^::/, '')
notify(
:warning,
message: "use $#{fixed} instead of $#{token.value}",
line: token.line,
column: token.column,
token: token
token: token,
)
end
end
Expand Down
12 changes: 4 additions & 8 deletions puppet-lint-topscope-variable-check.gemspec
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Gem::Specification.new do |spec|
spec.name = 'puppet-lint-topscope-variable-check'
spec.name = 'puppet-lint-topscope-variable-check'
spec.version = '1.2.0'
spec.homepage = 'https://github.com/voxpupuli/puppet-lint-topscope-variable-check'
spec.license = 'MIT'
Expand All @@ -11,16 +11,12 @@ Gem::Specification.new do |spec|
'lib/**/*',
'spec/**/*',
]
spec.test_files = Dir['spec/**/*']
spec.summary = 'A puppet-lint plugin to check topscope variables.'
spec.description = <<-DESC
A puppet-lint plugin to check that topscope variable names don't start with ::.
DESC

spec.add_dependency 'puppet-lint', '>= 2.0', '< 4'
spec.add_development_dependency 'rake', '>= 12.0', '< 14'
spec.add_development_dependency 'rspec', '~> 3.0'
spec.add_development_dependency 'rspec-collection_matchers', '~> 1.0'
spec.add_development_dependency 'rspec-its', '~> 1.0'
spec.add_development_dependency 'simplecov'
spec.required_ruby_version = '>= 2.7.0'

spec.add_dependency 'puppet-lint', '>= 3', '< 5'
end
38 changes: 20 additions & 18 deletions spec/puppet-lint/plugins/topscope_variable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

describe 'topscope_variable' do
let(:msg) { 'use $foo::bar instead of $::foo::bar' }

context 'with fix disabled' do
context 'with correct topscope' do
let(:code) do
Expand All @@ -14,7 +15,7 @@ class foo::blub {
PUP
end

it 'should not detect any problems' do
it 'does not detect any problems' do
expect(problems).to have(0).problem
end
end
Expand All @@ -30,7 +31,7 @@ class foo::blub {
PUP
end

it 'should detect one problem' do
it 'detects one problem' do
expect(problems).to have(1).problem
end
end
Expand All @@ -46,7 +47,7 @@ class profile::foo {
PUP
end

it 'should detect one problem' do
it 'detects one problem' do
expect(problems).to have(1).problem
end
end
Expand All @@ -62,7 +63,7 @@ class foo::blub(
PUP
end

it 'should not detect any problems' do
it 'does not detect any problems' do
expect(problems).to have(0).problem
end
end
Expand All @@ -78,7 +79,7 @@ class foo::blub(
PUP
end

it 'should detect one problem' do
it 'detects one problem' do
expect(problems).to have(1).problem
end
end
Expand All @@ -94,7 +95,7 @@ class foo::blub {
PUP
end

it 'should not detect any problems' do
it 'does not detect any problems' do
expect(problems).to have(0).problem
end
end
Expand All @@ -110,7 +111,7 @@ class foo::blub(
PUP
end

it 'should not detect any problems' do
it 'does not detect any problems' do
expect(problems).to have(0).problem
end
end
Expand All @@ -136,7 +137,7 @@ class foo::blub {
PUP
end

it 'should not detect any problems' do
it 'does not detect any problems' do
expect(problems).to have(0).problem
end
end
Expand All @@ -152,15 +153,15 @@ class foo::blub {
PUP
end

it 'should detect one problem' do
it 'detects one problem' do
expect(problems).to have(1).problem
end

it 'should fix the problem' do
it 'fixes the problem' do
expect(problems).to contain_fixed(msg).on_line(3).in_column(16)
end

it 'should remove :: after the $' do
it 'removes :: after the $' do
expect(manifest).to eq <<~PUP
class foo::blub {
notify { 'foo':
Expand All @@ -182,15 +183,15 @@ class profile::foo {
PUP
end

it 'should detect one problem' do
it 'detects one problem' do
expect(problems).to have(1).problem
end

it 'should fix the problem' do
it 'fixes the problem' do
expect(problems).to contain_fixed('use $some_component_module::bar instead of $::some_component_module::bar').on_line(3).in_column(16)
end

it 'should remove :: after the $' do
it 'removes :: after the $' do
expect(manifest).to eq <<~PUP
class profile::foo {
notify { 'foo':
Expand All @@ -212,15 +213,15 @@ class foo::blub {
PUP
end

it 'should detect one problem' do
it 'detects one problem' do
expect(problems).to have(1).problem
end

it 'should fix the problem' do
it 'fixes the problem' do
expect(problems).to contain_fixed(msg).on_line(3).in_column(20)
end

it 'should remove :: after the $' do
it 'removes :: after the $' do
expect(manifest).to eq <<~PUP
class foo::blub {
notify { 'foo':
Expand All @@ -238,7 +239,8 @@ class foo::blub {
include ::foo
PUP
end
it 'should not detect any problems' do

it 'does not detect any problems' do
expect(problems).to have(0).problem
end
end
Expand Down

0 comments on commit 916a6c2

Please sign in to comment.