puppet-lint 5.1.0 → 5.1.1

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: 200023e7df4e5c5ad823fba0f940ee2ad73ae5d05eb04796e83dbcc118e2a47e
4
- data.tar.gz: 3a14e87f1f69fdc2495068d246609af04c81e6610e4e878a669ab9b8262f1265
3
+ metadata.gz: 52a7cadacf8d637032f1ffb76f773566a7f3be3cd9a19fd1fbdbac69c2a68204
4
+ data.tar.gz: 9d8272950c1abfb41d078bec0c0909a9ae8d8ff66a01019f7908319baf651152
5
5
  SHA512:
6
- metadata.gz: 5bad4d387c8695aa0bc3fca805a819c5af1e0c410953f61093ec77a1139848c1b284a53aa238bed450ba5195d9af8736a2ba6a9dfec97ceca09bdaca08da80bf
7
- data.tar.gz: 4d26e6093580630b0b838562efdc2d2e9492d8185652a469aaca3fdb48cec0f88b9d02367cacc595b46d10d08745d4b76874d304a891e1e265c35ffb01625752
6
+ metadata.gz: f84a46b9cc61045fd3239f1e00aeda2d6d5ed1c7f68035782763be817b0d696fa829364610ea94389485f05ccf289745a8a58ead975504c2626a431747034272
7
+ data.tar.gz: 3a75d2e340d8753dc9ec901b8dd183c20847bc70101c08d435ecceb2d956214c8f6704c7fa81072758b3b31fd8fcc8bd79b8c83adc3b61a5a6d34a651feb341a
@@ -90,9 +90,7 @@ class PuppetLint::Bin
90
90
 
91
91
  return_val = 1 if l.errors? || (l.warnings? && PuppetLint.configuration.fail_on_warnings)
92
92
 
93
- next unless PuppetLint.configuration.fix && l.problems.none? { |r| r[:check] == :syntax }
94
-
95
- File.binwrite(f, l.manifest)
93
+ l.write_fixes if PuppetLint.configuration.fix
96
94
  end
97
95
 
98
96
  if PuppetLint.configuration.sarif
@@ -1,3 +1,3 @@
1
1
  class PuppetLint
2
- VERSION = '5.1.0'.freeze
2
+ VERSION = '5.1.1'.freeze
3
3
  end
data/lib/puppet-lint.rb CHANGED
@@ -235,6 +235,42 @@ class PuppetLint
235
235
  report(@problems)
236
236
  end
237
237
 
238
+ # Public: Write fixes back to the file if this file type supports fixes.
239
+ #
240
+ # Returns nothing.
241
+ def write_fixes
242
+ return unless should_write_fixes?
243
+
244
+ File.binwrite(@path, @manifest)
245
+ end
246
+
247
+ # Internal: Determine if fixes should be written for this file.
248
+ #
249
+ # Returns true if all conditions are met for writing fixes, false otherwise.
250
+ def should_write_fixes?
251
+ # Don't write if file type doesn't support fixes
252
+ return false unless supports_fixes?
253
+
254
+ # Don't write if there are syntax errors (can't safely fix)
255
+ return false if @problems&.any? { |r| r[:check] == :syntax }
256
+
257
+ # Don't write if there's no manifest content
258
+ return false if @manifest.nil? || @manifest.empty?
259
+
260
+ true
261
+ end
262
+
263
+ # Public: Determine if this file type supports automatic fixes.
264
+ #
265
+ # Returns true if fixes are supported for this file type, false otherwise.
266
+ def supports_fixes?
267
+ return false if @path.nil?
268
+
269
+ # Only .pp files support fixes currently
270
+ # YAML files and other types may support fixes in the future
271
+ File.extname(@path).match?(%r{\.pp$}i)
272
+ end
273
+
238
274
  # Public: Define a new check.
239
275
  #
240
276
  # name - A unique name for the check as a Symbol.
@@ -0,0 +1,3 @@
1
+ class foo-bar {
2
+ notify { 'hello': }
3
+ }
@@ -0,0 +1,7 @@
1
+ ---
2
+ classes:
3
+ foo-bar:
4
+ parameters: []
5
+ resources:
6
+ notify:
7
+ - title: hello
@@ -615,9 +615,27 @@ describe PuppetLint::Bin do
615
615
  end
616
616
  end
617
617
 
618
+ context 'when fixing a directory containing both .pp and .yaml files' do
619
+ let(:args) { ['--fix', 'spec/fixtures/test/manifests/issue_254_overwriting_yaml'] }
620
+
621
+ its(:exitstatus) { is_expected.to eq(1) }
622
+
623
+ it 'does not overwrite YAML files' do
624
+ yaml_file = 'spec/fixtures/test/manifests/issue_254_overwriting_yaml/class_with_dash.yaml'
625
+ original_yaml = File.read(yaml_file)
626
+
627
+ bin # Run the command
628
+
629
+ yaml_after = File.read(yaml_file)
630
+ expect(yaml_after).to eq(original_yaml)
631
+ expect(yaml_after).to include('classes:')
632
+ expect(yaml_after).not_to include('class foo-bar {')
633
+ end
634
+ end
635
+
618
636
  context 'when overriding config file options with command line options' do
619
637
  context 'and config file sets "--only-checks=variable_contains_dash"' do
620
- around(:context) do |example|
638
+ around(:each) do |example|
621
639
  Dir.mktmpdir do |tmpdir|
622
640
  Dir.chdir(tmpdir) do
623
641
  File.open('.puppet-lint.rc', 'wb') do |f|
@@ -15,4 +15,53 @@ describe PuppetLint do
15
15
  linter.run
16
16
  expect(linter.manifest).to eq('')
17
17
  end
18
+
19
+ describe '#supports_fixes?' do
20
+ context 'with a .pp file' do
21
+ it 'returns true' do
22
+ linter.instance_variable_set(:@path, 'test.pp')
23
+ expect(linter.supports_fixes?).to be true
24
+ end
25
+ end
26
+
27
+ context 'with a .yaml file' do
28
+ it 'returns false' do
29
+ linter.instance_variable_set(:@path, 'test.yaml')
30
+ expect(linter.supports_fixes?).to be false
31
+ end
32
+ end
33
+
34
+ context 'with no path set' do
35
+ it 'returns false' do
36
+ expect(linter.supports_fixes?).to be false
37
+ end
38
+ end
39
+ end
40
+
41
+ describe '#should_write_fixes?' do
42
+ before(:each) do
43
+ linter.instance_variable_set(:@path, 'test.pp')
44
+ linter.instance_variable_set(:@manifest, 'class test { }')
45
+ end
46
+
47
+ context 'when file supports fixes and has no syntax errors' do
48
+ it 'returns true' do
49
+ expect(linter.should_write_fixes?).to be true
50
+ end
51
+ end
52
+
53
+ context 'when file has syntax errors' do
54
+ it 'returns false' do
55
+ linter.instance_variable_set(:@problems, [{ check: :syntax }])
56
+ expect(linter.should_write_fixes?).to be false
57
+ end
58
+ end
59
+
60
+ context 'when file type does not support fixes' do
61
+ it 'returns false' do
62
+ linter.instance_variable_set(:@path, 'test.yaml')
63
+ expect(linter.should_write_fixes?).to be false
64
+ end
65
+ end
66
+ end
18
67
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppet-lint
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.1.0
4
+ version: 5.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Sharpe
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2025-09-25 00:00:00.000000000 Z
13
+ date: 2025-11-06 00:00:00.000000000 Z
14
14
  dependencies: []
15
15
  description: " Checks your Puppet manifests against the Puppetlabs style guide
16
16
  and alerts you to any discrepancies.\n"
@@ -92,6 +92,8 @@ files:
92
92
  - spec/fixtures/test/manifests/ignore_multiple_line.pp
93
93
  - spec/fixtures/test/manifests/ignore_reason.pp
94
94
  - spec/fixtures/test/manifests/init.pp
95
+ - spec/fixtures/test/manifests/issue_254_overwriting_yaml/class_with_dash.pp
96
+ - spec/fixtures/test/manifests/issue_254_overwriting_yaml/class_with_dash.yaml
95
97
  - spec/fixtures/test/manifests/malformed.pp
96
98
  - spec/fixtures/test/manifests/mismatched_control_comment.pp
97
99
  - spec/fixtures/test/manifests/parseable.yaml