Skip to content

Commit 15e48b7

Browse files
Merge pull request #113 from puppetlabs/CONT-811-add_ruby_3
(CONT-811) Add Ruby 3.2 support
2 parents 7f160d7 + 95d7dff commit 15e48b7

File tree

65 files changed

+604
-891
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+604
-891
lines changed

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ jobs:
1313
fail-fast: false
1414
matrix:
1515
ruby_version:
16-
- '2.5'
1716
- '2.7'
17+
- '3.2'
1818
name: "spec (ruby ${{ matrix.ruby_version }})"
1919
uses: "puppetlabs/cat-github-actions/.github/workflows/gem_ci.yml@main"
2020
secrets: "inherit"
@@ -26,8 +26,8 @@ jobs:
2626
fail-fast: false
2727
matrix:
2828
ruby_version:
29-
- '2.5'
3029
- '2.7'
30+
- '3.2'
3131
name: "acceptance (ruby ${{ matrix.ruby_version }})"
3232
needs: "spec"
3333
uses: "puppetlabs/cat-github-actions/.github/workflows/gem_acceptance.yml@main"

.github/workflows/nightly.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ jobs:
1212
fail-fast: false
1313
matrix:
1414
ruby_version:
15-
- '2.5'
1615
- '2.7'
16+
- '3.2'
1717
name: "spec (ruby ${{ matrix.ruby_version }})"
1818
uses: "puppetlabs/cat-github-actions/.github/workflows/gem_ci.yml@main"
1919
secrets: "inherit"
@@ -25,8 +25,8 @@ jobs:
2525
fail-fast: false
2626
matrix:
2727
ruby_version:
28-
- '2.5'
2928
- '2.7'
29+
- '3.2'
3030
name: "acceptance (ruby ${{ matrix.ruby_version }})"
3131
needs: "spec"
3232
uses: "puppetlabs/cat-github-actions/.github/workflows/gem_acceptance.yml@main"

.rubocop.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
inherit_from: rubocop_baseline.yml
1+
inherit_from:
2+
- rubocop_baseline.yml
3+
- .rubocop_todo.yml

.rubocop_todo.yml

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
# This configuration was generated by
2+
# `rubocop --auto-gen-config`
3+
# on 2023-04-04 08:44:46 UTC using RuboCop version 1.48.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: 1
10+
# This cop supports safe autocorrection (--autocorrect).
11+
# Configuration parameters: Severity, Include.
12+
# Include: **/*.gemspec
13+
Gemspec/RequireMFA:
14+
Exclude:
15+
- 'puppet-lint.gemspec'
16+
17+
# Offense count: 4
18+
# Configuration parameters: IgnoreLiteralBranches, IgnoreConstantBranches.
19+
Lint/DuplicateBranch:
20+
Exclude:
21+
- 'lib/puppet-lint/lexer/string_slurper.rb'
22+
- 'lib/puppet-lint/lexer/token.rb'
23+
24+
# Offense count: 9
25+
# Configuration parameters: MaximumRangeSize.
26+
Lint/MissingCopEnableDirective:
27+
Exclude:
28+
- 'lib/puppet-lint.rb'
29+
- 'lib/puppet-lint/lexer.rb'
30+
- 'lib/puppet-lint/lexer/string_slurper.rb'
31+
- 'lib/puppet-lint/lexer/token.rb'
32+
- 'lib/puppet-lint/report/codeclimate.rb'
33+
- 'lib/puppet-lint/report/github.rb'
34+
- 'lib/puppet-lint/tasks/puppet-lint.rb'
35+
- 'spec/unit/puppet-lint/puppet-lint_spec.rb'
36+
37+
# Offense count: 58
38+
# Configuration parameters: AllowedMethods, AllowedPatterns, CountRepeatedAttributes.
39+
Metrics/AbcSize:
40+
Max: 142
41+
42+
# Offense count: 34
43+
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns, inherit_mode.
44+
# AllowedMethods: refine
45+
Metrics/BlockLength:
46+
Max: 104
47+
48+
# Offense count: 2
49+
# Configuration parameters: CountBlocks.
50+
Metrics/BlockNesting:
51+
Max: 5
52+
53+
# Offense count: 7
54+
# Configuration parameters: CountComments, CountAsOne.
55+
Metrics/ClassLength:
56+
Max: 387
57+
58+
# Offense count: 33
59+
# Configuration parameters: AllowedMethods, AllowedPatterns.
60+
Metrics/CyclomaticComplexity:
61+
Max: 33
62+
63+
# Offense count: 80
64+
# Configuration parameters: CountComments, CountAsOne, AllowedMethods, AllowedPatterns.
65+
Metrics/MethodLength:
66+
Max: 108
67+
68+
# Offense count: 26
69+
# Configuration parameters: AllowedMethods, AllowedPatterns.
70+
Metrics/PerceivedComplexity:
71+
Max: 31
72+
73+
# Offense count: 182
74+
# Configuration parameters: ForbiddenDelimiters.
75+
# ForbiddenDelimiters: (?i-mx:(^|\s)(EO[A-Z]{1}|END)(\s|$))
76+
Naming/HeredocDelimiterNaming:
77+
Enabled: false
78+
79+
# Offense count: 2
80+
# Configuration parameters: MinNameLength, AllowNamesEndingInNumbers, AllowedNames, ForbiddenNames.
81+
# AllowedNames: as, at, by, cc, db, id, if, in, io, ip, of, on, os, pp, to
82+
Naming/MethodParameterName:
83+
Exclude:
84+
- 'lib/puppet-lint/monkeypatches.rb'
85+
86+
# Offense count: 7
87+
# Configuration parameters: MinSize.
88+
Performance/CollectionLiteralInLoop:
89+
Exclude:
90+
- 'lib/puppet-lint/bin.rb'
91+
- 'lib/puppet-lint/data.rb'
92+
- 'lib/puppet-lint/plugins/check_resources/ensure_first_param.rb'
93+
- 'lib/puppet-lint/plugins/check_whitespace/trailing_whitespace.rb'
94+
95+
# Offense count: 406
96+
# Configuration parameters: Prefixes, AllowedPatterns.
97+
# Prefixes: when, with, without
98+
RSpec/ContextWording:
99+
Enabled: false
100+
101+
# Offense count: 41
102+
# Configuration parameters: IgnoredMetadata.
103+
RSpec/DescribeClass:
104+
Enabled: false
105+
106+
# Offense count: 50
107+
# Configuration parameters: CountAsOne.
108+
RSpec/ExampleLength:
109+
Max: 148
110+
111+
# Offense count: 8
112+
# Configuration parameters: Include, CustomTransform, IgnoreMethods, SpecSuffixOnly.
113+
# Include: **/*_spec*rb*, **/spec/**/*
114+
RSpec/FilePath:
115+
Exclude:
116+
- 'spec/unit/puppet-lint/bin_spec.rb'
117+
- 'spec/unit/puppet-lint/checks_spec.rb'
118+
- 'spec/unit/puppet-lint/configuration_spec.rb'
119+
- 'spec/unit/puppet-lint/data_spec.rb'
120+
- 'spec/unit/puppet-lint/lexer/string_slurper_spec.rb'
121+
- 'spec/unit/puppet-lint/lexer/token_spec.rb'
122+
- 'spec/unit/puppet-lint/lexer_spec.rb'
123+
- 'spec/unit/puppet-lint/puppet-lint_spec.rb'
124+
125+
# Offense count: 138
126+
RSpec/MultipleExpectations:
127+
Max: 137
128+
129+
# Offense count: 3
130+
# Configuration parameters: AllowSubject.
131+
RSpec/MultipleMemoizedHelpers:
132+
Max: 13
133+
134+
# Offense count: 52
135+
# Configuration parameters: AllowedGroups.
136+
RSpec/NestedGroups:
137+
Max: 5
138+
139+
# Offense count: 8
140+
RSpec/RepeatedExampleGroupDescription:
141+
Exclude:
142+
- 'spec/unit/puppet-lint/plugins/check_resources/file_mode_spec.rb'
143+
- 'spec/unit/puppet-lint/plugins/check_resources/unquoted_file_mode_spec.rb'
144+
- 'spec/unit/puppet-lint/plugins/legacy_facts/legacy_facts_spec.rb'
145+
146+
# Offense count: 106
147+
# This cop supports unsafe autocorrection (--autocorrect-all).
148+
# Configuration parameters: EnforcedStyle.
149+
# SupportedStyles: always, always_true, never
150+
Style/FrozenStringLiteralComment:
151+
Enabled: false
152+
153+
# Offense count: 9
154+
# This cop supports unsafe autocorrection (--autocorrect-all).
155+
# Configuration parameters: Mode.
156+
Style/StringConcatenation:
157+
Exclude:
158+
- 'lib/puppet-lint/bin.rb'
159+
- 'lib/puppet-lint/plugins.rb'
160+
- 'lib/puppet-lint/plugins/top_scope_facts/top_scope_facts.rb'
161+
- 'spec/unit/puppet-lint/plugins/check_strings/variables_not_enclosed_spec.rb'

Gemfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ group :development do
3030
end
3131

3232
group :rubocop do
33-
gem 'rubocop', '~> 1.6.1', require: false
34-
gem 'rubocop-rspec', '~> 2.0.1', require: false
35-
gem 'rubocop-performance', '~> 1.9.1', require: false
33+
gem 'rubocop', '~> 1.48.1', require: false
34+
gem 'rubocop-rspec', '~> 2.19', require: false
35+
gem 'rubocop-performance', '~> 1.16', require: false
3636
end

lib/puppet-lint.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def file=(path)
9595

9696
# Check if the input is an SE Linux policy package file (which also use
9797
# the .pp extension), which all have the first 4 bytes 0xf97cff8f.
98-
@code = '' if @code[0..3].unpack('V').first == 0xf97cff8f
98+
@code = '' if @code[0..3].unpack1('V') == 0xf97cff8f
9999
end
100100

101101
# Internal: Retrieve the format string to be used when writing problems to
@@ -155,8 +155,10 @@ def get_context(message)
155155
def print_context(message)
156156
return if message[:check] == 'documentation'
157157
return if message[:kind] == :fixed
158+
158159
line = message[:context]
159160
return unless line
161+
160162
offset = line.index(%r{\S}) || 1
161163
puts "\n #{line.strip}"
162164
printf("%#{message[:column] + 2 - offset}s\n\n", '^')
@@ -188,7 +190,7 @@ def report(problems)
188190
print_github_annotation(message) if configuration.github_actions
189191
end
190192
end
191-
$stderr.puts 'Try running `puppet parser validate <file>`' if problems.any? { |p| p[:check] == :syntax }
193+
warn 'Try running `puppet parser validate <file>`' if problems.any? { |p| p[:check] == :syntax }
192194
json
193195
end
194196

@@ -251,7 +253,7 @@ def print_problems
251253
def self.new_check(name, &block)
252254
class_name = name.to_s.split('_').map(&:capitalize).join
253255
klass = PuppetLint.const_set("Check#{class_name}", Class.new(PuppetLint::CheckPlugin))
254-
klass.const_set('NAME', name)
256+
klass.const_set(:NAME, name)
255257
klass.class_exec(&block)
256258
PuppetLint.configuration.add_check(name, klass)
257259
PuppetLint::Data.ignore_overrides[name] ||= {}

lib/puppet-lint/bin.rb

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def run
4949

5050
begin
5151
path = @args[0]
52-
full_path = File.expand_path(path, ENV['PWD'])
52+
full_path = File.expand_path(path, ENV.fetch('PWD', nil))
5353
full_base_path = if File.directory?(full_path)
5454
full_path
5555
else
@@ -79,19 +79,17 @@ def run
7979

8080
path.each do |f|
8181
next if ignore_paths.any? { |p| File.fnmatch(p, f) }
82+
8283
l = PuppetLint.new
8384
l.file = f
8485
l.run
8586
all_problems << l.print_problems
8687

87-
if l.errors? || (l.warnings? && PuppetLint.configuration.fail_on_warnings)
88-
return_val = 1
89-
end
88+
return_val = 1 if l.errors? || (l.warnings? && PuppetLint.configuration.fail_on_warnings)
9089

9190
next unless PuppetLint.configuration.fix && l.problems.none? { |r| r[:check] == :syntax }
92-
File.open(f, 'wb') do |fd|
93-
fd.write(l.manifest)
94-
end
91+
92+
File.binwrite(f, l.manifest)
9593
end
9694

9795
if PuppetLint.configuration.sarif
@@ -105,9 +103,7 @@ def run
105103
puts JSON.pretty_generate(all_problems)
106104
end
107105

108-
if PuppetLint.configuration.codeclimate_report_file
109-
PuppetLint::Report::CodeClimateReporter.write_report_file(all_problems, PuppetLint.configuration.codeclimate_report_file)
110-
end
106+
PuppetLint::Report::CodeClimateReporter.write_report_file(all_problems, PuppetLint.configuration.codeclimate_report_file) if PuppetLint.configuration.codeclimate_report_file
111107

112108
return_val
113109
rescue PuppetLint::NoCodeError
@@ -148,7 +144,7 @@ def report_sarif(problems, base_path, base_path_uri)
148144
'ruleIndex' => rule_index,
149145
'message' => { 'text' => message[:message] },
150146
'locations' => [{ 'physicalLocation' => { 'artifactLocation' => { 'uri' => relative_path, 'uriBaseId' => 'ROOTPATH' },
151-
'region' => { 'startLine' => message[:line], 'startColumn' => message[:column] } } }],
147+
'region' => { 'startLine' => message[:line], 'startColumn' => message[:column] } } }]
152148
}
153149
results << result
154150
end

lib/puppet-lint/checkplugin.rb

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,10 @@ def manifest_lines
179179
# Returns a Hash of default problem information.
180180
def default_info
181181
@default_info ||= {
182-
check: self.class.const_get('NAME'),
182+
check: self.class.const_get(:NAME),
183183
fullpath: fullpath,
184184
path: path,
185-
filename: filename,
185+
filename: filename
186186
}
187187
end
188188

@@ -202,14 +202,10 @@ def notify(kind, problem)
202202
problem[:kind] = kind
203203
problem.merge!(default_info) { |_key, v1, _v2| v1 }
204204

205-
unless [:warning, :error, :fixed].include?(kind)
206-
raise ArgumentError, 'unknown value passed for kind'
207-
end
205+
raise ArgumentError, 'unknown value passed for kind' unless [:warning, :error, :fixed].include?(kind)
208206

209207
[:message, :line, :column, :check].each do |attr|
210-
unless problem.key?(attr)
211-
raise ArgumentError, "problem hash must contain #{attr.inspect}"
212-
end
208+
raise ArgumentError, "problem hash must contain #{attr.inspect}" unless problem.key?(attr)
213209
end
214210

215211
@problems << problem

lib/puppet-lint/checks.rb

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def load_data(path, content)
3939
column: e.column,
4040
fullpath: PuppetLint::Data.fullpath,
4141
path: PuppetLint::Data.path,
42-
filename: PuppetLint::Data.filename,
42+
filename: PuppetLint::Data.filename
4343
}
4444
PuppetLint::Data.tokens = []
4545
end
@@ -76,15 +76,15 @@ def run(fileinfo, data)
7676
kind: :error,
7777
check: :syntax,
7878
message: 'Syntax error',
79-
fullpath: File.expand_path(fileinfo, ENV['PWD']),
79+
fullpath: File.expand_path(fileinfo, ENV.fetch('PWD', nil)),
8080
filename: File.basename(fileinfo),
8181
path: fileinfo,
8282
line: e.token.line,
83-
column: e.token.column,
83+
column: e.token.column
8484
}
8585

8686
@problems
87-
rescue => e
87+
rescue StandardError => e
8888
$stdout.puts <<-END.gsub(%r{^ {6}}, '')
8989
Whoops! It looks like puppet-lint has encountered an error that it doesn't
9090
know how to handle. Please open an issue at https://github.com/puppetlabs/puppet-lint
@@ -120,17 +120,15 @@ def run(fileinfo, data)
120120
#
121121
# Returns an Array of String check names.
122122
def enabled_checks
123-
@enabled_checks ||= begin
124-
PuppetLint.configuration.checks.select do |check|
125-
PuppetLint.configuration.send("#{check}_enabled?")
126-
end
123+
@enabled_checks ||= PuppetLint.configuration.checks.select do |check|
124+
PuppetLint.configuration.send("#{check}_enabled?")
127125
end
128126
end
129127

130128
# Internal: Render the fixed manifest.
131129
#
132130
# Returns the manifest as a String.
133131
def manifest
134-
PuppetLint::Data.tokens.map(&:to_manifest).join('')
132+
PuppetLint::Data.tokens.map(&:to_manifest).join
135133
end
136134
end

0 commit comments

Comments
 (0)