Skip to content

Commit 2210858

Browse files
authored
Merge branch 'main' into space_before_arrow
2 parents a58ef96 + 05af720 commit 2210858

File tree

16 files changed

+102
-38
lines changed

16 files changed

+102
-38
lines changed

.github/workflows/ci.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
name: "ci"
22

33
on:
4+
push:
5+
branches:
6+
- "main"
47
pull_request:
58
branches:
69
- "main"
710
workflow_dispatch:
811

12+
env:
13+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
14+
915
jobs:
1016

1117
spec:
@@ -19,6 +25,7 @@ jobs:
1925
uses: "puppetlabs/cat-github-actions/.github/workflows/gem_ci.yml@main"
2026
secrets: "inherit"
2127
with:
28+
rake_task: "spec:coverage"
2229
ruby_version: ${{ matrix.ruby_version }}
2330

2431
acceptance:

.github/workflows/mend.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
name: "mend"
22

33
on:
4-
pull_request:
5-
branches:
6-
- "main"
4+
pull_request_target:
5+
types:
6+
- opened
7+
- synchronize
78
schedule:
89
- cron: "0 0 * * *"
910
workflow_dispatch:

.rubocop_todo.yml

Lines changed: 4 additions & 4 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 2023-09-12 15:54:37 UTC using RuboCop version 1.48.1.
3+
# on 2024-01-22 14:59:34 UTC using RuboCop version 1.50.2.
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
@@ -50,7 +50,7 @@ Metrics/BlockLength:
5050
Metrics/BlockNesting:
5151
Max: 5
5252

53-
# Offense count: 7
53+
# Offense count: 8
5454
# Configuration parameters: CountComments, CountAsOne.
5555
Metrics/ClassLength:
5656
Max: 387
@@ -92,7 +92,7 @@ Performance/CollectionLiteralInLoop:
9292
- 'lib/puppet-lint/plugins/check_resources/ensure_first_param.rb'
9393
- 'lib/puppet-lint/plugins/check_whitespace/trailing_whitespace.rb'
9494

95-
# Offense count: 408
95+
# Offense count: 409
9696
# Configuration parameters: Prefixes, AllowedPatterns.
9797
# Prefixes: when, with, without
9898
RSpec/ContextWording:
@@ -108,7 +108,7 @@ RSpec/DescribeClass:
108108
RSpec/ExampleLength:
109109
Max: 148
110110

111-
# Offense count: 138
111+
# Offense count: 119
112112
RSpec/MultipleExpectations:
113113
Max: 137
114114

CHANGELOG.md

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,29 @@ All notable changes to this project will be documented in this file.
55

66
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/) and this project adheres to [Semantic Versioning](http://semver.org).
77

8-
## [v5.0.0](https://github.com/puppetlabs/puppet-lint/tree/v5.0.0) - 2023-10-18
8+
## [v4.2.4](https://github.com/puppetlabs/puppet-lint/tree/v4.2.4) - 2024-02-09
99

10-
[Full Changelog](https://github.com/puppetlabs/puppet-lint/compare/v4.2.1...v5.0.0)
10+
[Full Changelog](https://github.com/puppetlabs/puppet-lint/compare/v4.2.3...v4.2.4)
1111

12-
### Changed
13-
- (CAT-1248) Update Published Name and Owner [#158](https://github.com/puppetlabs/puppet-lint/pull/158) ([david22swan](https://github.com/david22swan))
12+
### Fixed
13+
14+
- (GH-189) - invalid fact correction for top scope structured fact [#190](https://github.com/puppetlabs/puppet-lint/pull/190) ([jordanbreen28](https://github.com/jordanbreen28))
15+
16+
## [v4.2.3](https://github.com/puppetlabs/puppet-lint/tree/v4.2.3) - 2023-11-22
17+
18+
[Full Changelog](https://github.com/puppetlabs/puppet-lint/compare/v4.2.2...v4.2.3)
19+
20+
### Fixed
21+
22+
- (maint) - Update redundant description [#179](https://github.com/puppetlabs/puppet-lint/pull/179) ([jordanbreen28](https://github.com/jordanbreen28))
23+
24+
## [v4.2.2](https://github.com/puppetlabs/puppet-lint/tree/v4.2.2) - 2023-11-21
25+
26+
[Full Changelog](https://github.com/puppetlabs/puppet-lint/compare/v4.2.1...v4.2.2)
27+
28+
### Fixed
29+
30+
- Use better yardoc tags [#172](https://github.com/puppetlabs/puppet-lint/pull/172) ([ekohl](https://github.com/ekohl))
1431

1532
## [v4.2.1](https://github.com/puppetlabs/puppet-lint/tree/v4.2.1) - 2023-10-09
1633

Gemfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ group :test do
1010
gem 'json'
1111

1212
gem 'rspec-json_expectations', '~> 1.4'
13-
14-
gem 'simplecov', :require => false if ENV['COVERAGE'] == 'yes'
13+
gem 'simplecov', :require => false
14+
gem 'simplecov-console', :require => false
1515
end
1616

1717
group :acceptance do
@@ -29,7 +29,7 @@ group :development do
2929
end
3030

3131
group :rubocop do
32-
gem 'rubocop', '~> 1.48.1', require: false
32+
gem 'rubocop', '~> 1.50.0', require: false
3333
gem 'rubocop-rspec', '~> 2.19', require: false
3434
gem 'rubocop-performance', '~> 1.16', require: false
3535
end

Rakefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@ rescue LoadError
2727
# Gem not present
2828
end
2929

30+
namespace :spec do
31+
desc 'Run RSpec code examples with coverage collection'
32+
task :coverage do
33+
ENV['COVERAGE'] = 'yes'
34+
Rake::Task['spec'].execute
35+
end
36+
end
37+
3038
RSpec::Core::RakeTask.new(:spec) do |t|
3139
t.exclude_pattern = 'spec/acceptance/**/*_spec.rb'
3240
end

lib/puppet-lint.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ def print_problems
252252
# end
253253
def self.new_check(name, &block)
254254
class_name = name.to_s.split('_').map(&:capitalize).join
255-
klass = PuppetLint.const_set("Check#{class_name}", Class.new(PuppetLint::CheckPlugin))
255+
klass = PuppetLint.const_set(:"Check#{class_name}", Class.new(PuppetLint::CheckPlugin))
256256
klass.const_set(:NAME, name)
257257
klass.class_exec(&block)
258258
PuppetLint.configuration.add_check(name, klass)

lib/puppet-lint/checks.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def run(fileinfo, data)
121121
# Returns an Array of String check names.
122122
def enabled_checks
123123
@enabled_checks ||= PuppetLint.configuration.checks.select do |check|
124-
PuppetLint.configuration.send("#{check}_enabled?")
124+
PuppetLint.configuration.send(:"#{check}_enabled?")
125125
end
126126
end
127127

lib/puppet-lint/configuration.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,21 @@ def self.add_check(check)
1717
# Public: Determine if the named check is enabled.
1818
#
1919
# Returns true if the check is enabled, otherwise return false.
20-
define_method("#{check}_enabled?") do
20+
define_method(:"#{check}_enabled?") do
2121
settings["#{check}_disabled"] != true
2222
end
2323

2424
# Public: Disable the named check.
2525
#
2626
# Returns nothing.
27-
define_method("disable_#{check}") do
27+
define_method(:"disable_#{check}") do
2828
settings["#{check}_disabled"] = true
2929
end
3030

3131
# Public: Enable the named check.
3232
#
3333
# Returns nothing.
34-
define_method("enable_#{check}") do
34+
define_method(:"enable_#{check}") do
3535
settings["#{check}_disabled"] = false
3636
end
3737
end
@@ -92,7 +92,7 @@ def self.add_option(option)
9292
# value - The value to set the option to.
9393
#
9494
# Returns nothing.
95-
define_method("#{option}=") do |value|
95+
define_method(:"#{option}=") do |value|
9696
settings[option] = value
9797
end
9898

lib/puppet-lint/optparser.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,9 +117,9 @@ def self.build(args = [])
117117
enable_checks = checks.split(',').map(&:to_sym)
118118
PuppetLint.configuration.checks.each do |check|
119119
if enable_checks.include?(check)
120-
PuppetLint.configuration.send("enable_#{check}")
120+
PuppetLint.configuration.send(:"enable_#{check}")
121121
else
122-
PuppetLint.configuration.send("disable_#{check}")
122+
PuppetLint.configuration.send(:"disable_#{check}")
123123
end
124124
end
125125
end
@@ -130,13 +130,13 @@ def self.build(args = [])
130130

131131
PuppetLint.configuration.checks.each do |check|
132132
opts.on("--no-#{check}-check", "Skip the #{check} check.") do
133-
PuppetLint.configuration.send("disable_#{check}")
133+
PuppetLint.configuration.send(:"disable_#{check}")
134134
end
135135

136-
next if PuppetLint.configuration.send("#{check}_enabled?")
136+
next if PuppetLint.configuration.send(:"#{check}_enabled?")
137137

138138
opts.on("--#{check}-check", "Enable the #{check} check.") do
139-
PuppetLint.configuration.send("enable_#{check}")
139+
PuppetLint.configuration.send(:"enable_#{check}")
140140
end
141141
end
142142
end

lib/puppet-lint/plugins/top_scope_facts/top_scope_facts.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ def check
4444
end
4545

4646
def fix(problem)
47-
problem[:token].value = "facts['" + problem[:token].value.sub(%r{^::}, '') + "']"
47+
problem[:token].value.sub!(%r{^::}, '')
48+
# checks if the fact is a top level structured fact e.g. ::my_structured_fact['foo']['bar']
49+
if %r{\[.*}.match?(problem[:token].value)
50+
fact_name = problem[:token].value.sub(%r{\[.*}, '')
51+
nested_facts = problem[:token].value.scan(%r{\[.*}).first
52+
problem[:token].value = "facts['" + fact_name + "']" + nested_facts
53+
else
54+
problem[:token].value = "facts['" + problem[:token].value + "']"
55+
end
4856
end
4957
end

lib/puppet-lint/tasks/puppet-lint.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,19 @@ def define(args, &task_block)
5252
enable_checks = Array(@only_checks).map(&:to_sym)
5353
PuppetLint.configuration.checks.each do |check|
5454
if enable_checks.include?(check)
55-
PuppetLint.configuration.send("enable_#{check}")
55+
PuppetLint.configuration.send(:"enable_#{check}")
5656
else
57-
PuppetLint.configuration.send("disable_#{check}")
57+
PuppetLint.configuration.send(:"disable_#{check}")
5858
end
5959
end
6060
end
6161

6262
Array(@disable_checks).each do |check|
63-
PuppetLint.configuration.send("disable_#{check}")
63+
PuppetLint.configuration.send(:"disable_#{check}")
6464
end
6565

6666
['with_filename', 'fail_on_warnings', 'error_level', 'log_format', 'with_context', 'fix', 'show_ignored', 'relative'].each do |config|
67-
value = instance_variable_get("@#{config}")
67+
value = instance_variable_get(:"@#{config}")
6868
PuppetLint.configuration.send("#{config}=".to_sym, value) unless value.nil?
6969
end
7070

lib/puppet-lint/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
class PuppetLint
2-
VERSION = '5.0.0'.freeze
2+
VERSION = '4.2.4'.freeze
33
end

puppet-lint.gemspec

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ $LOAD_PATH.push(File.expand_path('lib', __dir__))
22
require 'puppet-lint/version'
33

44
Gem::Specification.new do |spec|
5-
spec.name = 'puppetlabs-puppet-lint'
5+
spec.name = 'puppet-lint'
66
spec.version = PuppetLint::VERSION.dup
77
spec.homepage = 'https://github.com/puppetlabs/puppet-lint/'
88
spec.summary = 'Ensure your Puppet manifests conform with the Puppetlabs style guide'
@@ -27,6 +27,7 @@ Gem::Specification.new do |spec|
2727
'Community Contributors',
2828
]
2929
spec.email = [
30+
'tim@sharpe.id.au',
3031
'modules-team@puppet.com',
3132
]
3233
spec.license = 'MIT'

spec/spec_helper.rb

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
# Disable GitHub Actions reporting since it breaks the test suite
22
ENV.delete('GITHUB_ACTION')
33

4-
if ENV['COVERAGE'] == 'yes' && RUBY_VERSION.start_with?('2.7.')
5-
require 'simplecov'
6-
SimpleCov.start do
7-
add_filter('/spec/')
8-
add_filter('/vendor/')
9-
add_group('Checks', 'lib/puppet-lint/plugins')
4+
if ENV['COVERAGE'] == 'yes'
5+
begin
6+
require 'simplecov'
7+
require 'simplecov-console'
8+
SimpleCov.formatters = [
9+
SimpleCov::Formatter::HTMLFormatter,
10+
SimpleCov::Formatter::Console,
11+
]
12+
13+
SimpleCov.start do
14+
add_filter('/spec/')
15+
add_filter('/vendor/')
16+
add_group('Checks', 'lib/puppet-lint/plugins')
17+
end
18+
rescue LoadError
19+
raise 'Add the simplecov & simplecov-console gems to Gemfile to enable this task'
1020
end
1121
end
1222

spec/unit/puppet-lint/plugins/top_scope_facts/top_scope_facts_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,18 @@
102102
end
103103
end
104104

105+
context 'top scope structured fact not present on allowlist' do
106+
let(:code) { "$::my_structured_fact['foo']['test']" }
107+
108+
it 'detects a problem' do
109+
expect(problems).to contain_fixed('top scope fact instead of facts hash').on_line(1).in_column(1)
110+
end
111+
112+
it 'fixes the problem' do
113+
expect(manifest).to eq("$facts['my_structured_fact']['foo']['test']")
114+
end
115+
end
116+
105117
context 'top scope $::trusted hash' do
106118
let(:code) { "$::trusted['certname']" }
107119

0 commit comments

Comments
 (0)