puppet-check 2.4.0 → 2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c5c74c1af6aee54ad5dcfd3eeefa459ed9fd5eaaafdc847f346a8e3674ffb362
4
- data.tar.gz: c11db9238470434a489608d62360d12fe1ff10dda29627a05cdded940785b992
3
+ metadata.gz: 1a0fcb7ee7b05692747da7d0449b6bd442c3078311c0bcbd2e25bd56e491decd
4
+ data.tar.gz: 6ef3744b4c7a008c2a3042fd41b9bddc5f3dd236322180a8ff8cbc51df870b87
5
5
  SHA512:
6
- metadata.gz: 12416f0a0d2d2615c467645cb238e0b14be8f42c9172e5adf7acf3bfbdddbdae1d5b08ccd2a967dcb7b6af41a8149f2e30e22ed5d0db97c5f05e586e384c4a61
7
- data.tar.gz: 053f4f90842f2d71ccbc82a3b05cd5ef1347af5399686fc3ed4a7cbf824baeee63ad412c1d6261f3640929bdcba789db7e2fe46d7f3e529cf3cd6b1c8b9690d8
6
+ metadata.gz: 8bdf3f7e6ba85fa4917329314f7f87382940b5e039a49891eb8d789aa57861d0e91b9f63b0d2a738523ffe1fb056e30842005d0f1bc06312859420ac9df1986e
7
+ data.tar.gz: 01f4cd1102f300ffa35b4943c8426b2e91db54b68bfb439489b4f88efce58248abd8839d738681cc2f6c2d55c46241aed13ff455cc2eb059374b3c6589c137b5
data/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ### 2.5.0
2
+ - Minimum Ruby version increased to 3.1.
3
+ - Minimum Puppet-Lint increased to 5.0.
4
+ - Restore ERB validation mock Ruby binding.
5
+ - Update Reek API usage.
6
+ - Ensure `rubocop-rspec` plugin only loaded for spec files.
7
+
1
8
  ### 2.4.0
2
9
  - Minimum Ruby version increased to 3.0.
3
10
  - Fix `rubocop-performance` inclusion warning.
data/README.md CHANGED
@@ -331,6 +331,4 @@ To overcome the lack of convenient portability, you could try spinning up the Va
331
331
  ## Contributing
332
332
  Code should pass all spec tests. New features should involve new spec tests. Adherence to Rubocop and Reek is expected where not overly onerous or where the check is of dubious cost/benefit.
333
333
 
334
- A [Dockerfile](Dockerfile) is provided for easy rake testing. A [Vagrantfile](Vagrantfile) is provided for easy gem building, installation, and post-installation testing.
335
-
336
334
  Please consult the GitHub Project for the current development roadmap.
@@ -10,7 +10,6 @@ class RubyParser
10
10
  require 'json'
11
11
  require 'rubocop'
12
12
  require 'reek'
13
- require 'reek/cli/application'
14
13
 
15
14
  rubocop_cli = RuboCop::CLI.new
16
15
  end
@@ -23,13 +22,16 @@ class RubyParser
23
22
  else
24
23
  # check ruby style
25
24
  if style
25
+ # add rubocop rspec plugin if the file is a spec
26
+ rc_args.push('--plugin', 'rubocop-rspec') if file =~ /_spec\.rb$/
27
+
26
28
  # check RuboCop and parse warnings' JSON output
27
- rubocop_warnings = Utils.capture_stdout { rubocop_cli.run(rc_args + ['--enable-pending-cops', '--plugin', 'rubocop-performance', '--plugin', 'rubocop-rspec', '--format', 'json', file]) }
29
+ rubocop_warnings = Utils.capture_stdout { rubocop_cli.run(rc_args + ['--enable-pending-cops', '--plugin', 'rubocop-performance', '--format', 'json', file]) }
28
30
  rubocop_offenses = JSON.parse(rubocop_warnings)['files'][0]['offenses'].map { |warning| "#{warning['location']['line']}:#{warning['location']['column']} #{warning['message']}" }
29
31
 
30
- # check Reek and parse warnings' JSON output
31
- reek_warnings = Utils.capture_stdout { Reek::CLI::Application.new(['-f', 'json', file]).execute }
32
- reek_offenses = JSON.parse(reek_warnings).map { |warning| "#{warning['lines'].join(',')}: #{warning['context']} #{warning['message']}" }
32
+ # check Reek using examiner api
33
+ examiner = Reek::Examiner.new(Pathname.new(file))
34
+ reek_offenses = examiner.smells.map { |warning| "#{warning.lines.join(',')}: #{warning.context} #{warning.message}" }
33
35
 
34
36
  # assign warnings from combined offenses
35
37
  warnings = rubocop_offenses + reek_offenses
@@ -48,10 +50,7 @@ class RubyParser
48
50
  files.each do |file|
49
51
  # check ruby template syntax
50
52
  begin
51
- # need to eventually have this associated with a different binding during each iteration
52
- # older usage throws extra warning and mixes with valid warnings confusingly
53
- warnings = Utils.capture_stderr { ERB.new(File.read(file), trim_mode: '-').result }
54
- # warnings = ERB.new(File.read(file), trim_mode: '-').result(RubyParser.new.bind)
53
+ warnings = Utils.capture_stderr { ERB.new(File.read(file), trim_mode: '-').result(Object.new.instance_eval { binding }) }
55
54
  rescue NameError, TypeError
56
55
  # empty out warnings since it would contain an error if this pass triggers
57
56
  warnings = ''
@@ -79,8 +78,7 @@ class RubyParser
79
78
 
80
79
  files.each do |file|
81
80
  # check librarian puppet syntax
82
- # prevents ruby code from actually executing the input ruby file
83
- catch(:good) { instance_eval("BEGIN {throw :good}; #{File.read(file)} # BEGIN {throw :good}; ruby_file_content", file) }
81
+ RubyVM::InstructionSequence.compile_file(file)
84
82
  rescue SyntaxError, LoadError, ArgumentError => err
85
83
  PuppetCheck.files[:errors][file] = err.to_s.gsub("#{file}:", '').split("\n")
86
84
  # check librarian puppet style
@@ -95,9 +93,4 @@ class RubyParser
95
93
  PuppetCheck.files[:clean].push(file.to_s)
96
94
  end
97
95
  end
98
-
99
- # potentially for unique erb bindings
100
- def bind
101
- binding
102
- end
103
96
  end
data/puppet-check.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |spec|
2
2
  spec.name = 'puppet-check'
3
- spec.version = '2.4.0'
3
+ spec.version = '2.5.0'
4
4
  spec.authors = ['Matt Schuchard']
5
5
  spec.description = 'Puppet Check is a gem that provides a comprehensive, streamlined, and efficient analysis of the syntax, style, and validity of your entire Puppet code and data.'
6
6
  spec.summary = 'A streamlined comprehensive set of checks for your entire Puppet code and data'
@@ -11,9 +11,9 @@ Gem::Specification.new do |spec|
11
11
  spec.executables = spec.files.grep(%r{^bin/}) { |file| File.basename(file) }
12
12
  spec.require_paths = Dir['lib']
13
13
 
14
- spec.required_ruby_version = '>= 3.0.0'
14
+ spec.required_ruby_version = '>= 3.1.0'
15
15
  spec.add_dependency 'puppet', '>= 5.5', '< 9'
16
- spec.add_dependency 'puppet-lint', '~> 4.0'
16
+ spec.add_dependency 'puppet-lint', '~> 5.0'
17
17
  spec.add_dependency 'reek', '~> 6.0'
18
18
  spec.add_dependency 'rubocop', '~> 1.72'
19
19
  spec.add_dependency 'rubocop-performance', '~> 1.0'
@@ -5,7 +5,7 @@ describe PuppetCheck::CLI do
5
5
  context '.run' do
6
6
  it 'targets the current working directory if no paths were specified' do
7
7
  expect { PuppetCheck::CLI.run(%w[--fail-on-warnings]) }.not_to raise_exception
8
- expect(PuppetCheck.files[:clean].length).to eql(30)
8
+ expect(PuppetCheck.files[:clean].length).to eql(29)
9
9
  if ci_env
10
10
  expect(PuppetCheck.files[:ignored].length).to eql(8)
11
11
  else
@@ -24,7 +24,7 @@ describe RubyParser do
24
24
  expect(PuppetCheck.files[:errors]).to eql({})
25
25
  expect(PuppetCheck.files[:warnings].keys).to eql(["#{fixtures_dir}lib/style.rb"])
26
26
  unless ci_env
27
- expect(PuppetCheck.files[:warnings]["#{fixtures_dir}lib/style.rb"].join("\n")).to match(/Useless assignment.*\n.*Use the new.*\n.*Do not introduce.*\n.*Prefer single.*\n.*Remove unnecessary empty.*\n.*Source code comment is empty.*\n.*is a writable attribute.*\n.*Issue has no descriptive comment/)
27
+ expect(PuppetCheck.files[:warnings]["#{fixtures_dir}lib/style.rb"].length).to eql(8)
28
28
  else
29
29
  expect(PuppetCheck.files[:warnings]["#{fixtures_dir}lib/style.rb"].join("\n")).to match(/Useless assignment.*\n.*Use the new.*\n.*Do not introduce.*\n.*Prefer single.*\n.*Remove unnecessary empty.*\n.*Source code comment is empty/)
30
30
  end
@@ -72,6 +72,7 @@ describe PuppetCheck do
72
72
  before(:each) { Dir.chdir(fixtures_dir) }
73
73
 
74
74
  let(:no_files) { PuppetCheck.send(:parse_paths, %w[foo bar baz]) }
75
+ let(:mixed_files) { PuppetCheck.send(:parse_paths, %w[foo lib/good.rb]) }
75
76
  let(:file) { PuppetCheck.send(:parse_paths, ['lib/good.rb']) }
76
77
  let(:dir) { PuppetCheck.send(:parse_paths, ['.']) }
77
78
  let(:multi_dir) { PuppetCheck.send(:parse_paths, %w[hieradata lib manifests]) }
@@ -81,6 +82,11 @@ describe PuppetCheck do
81
82
  expect { no_files }.to raise_error(RuntimeError, 'puppet-check: no files found in supplied paths \'foo, bar, baz\'.')
82
83
  end
83
84
 
85
+ it 'warns on invalid path and correctly parses a valid file path' do
86
+ expect { mixed_files }.to output("puppet-check: foo is not a directory, file, or symlink, and will not be considered during parsing\n").to_stderr
87
+ expect(mixed_files[0]).to eql('lib/good.rb')
88
+ end
89
+
84
90
  it 'correctly parses one file and returns it' do
85
91
  expect(file[0]).to eql('lib/good.rb')
86
92
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppet-check
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.0
4
+ version: 2.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Schuchard
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-10-18 00:00:00.000000000 Z
11
+ date: 2026-02-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: puppet
@@ -36,14 +36,14 @@ dependencies:
36
36
  requirements:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: '4.0'
39
+ version: '5.0'
40
40
  type: :runtime
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
- version: '4.0'
46
+ version: '5.0'
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: reek
49
49
  requirement: !ruby/object:Gem::Requirement
@@ -221,7 +221,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
221
221
  requirements:
222
222
  - - ">="
223
223
  - !ruby/object:Gem::Version
224
- version: 3.0.0
224
+ version: 3.1.0
225
225
  required_rubygems_version: !ruby/object:Gem::Requirement
226
226
  requirements:
227
227
  - - ">="