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 +4 -4
- data/lib/puppet-lint/bin.rb +1 -3
- data/lib/puppet-lint/version.rb +1 -1
- data/lib/puppet-lint.rb +36 -0
- data/spec/fixtures/test/manifests/issue_254_overwriting_yaml/class_with_dash.pp +3 -0
- data/spec/fixtures/test/manifests/issue_254_overwriting_yaml/class_with_dash.yaml +7 -0
- data/spec/unit/puppet-lint/bin_spec.rb +19 -1
- data/spec/unit/puppet-lint/puppet-lint_spec.rb +49 -0
- metadata +4 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 52a7cadacf8d637032f1ffb76f773566a7f3be3cd9a19fd1fbdbac69c2a68204
|
|
4
|
+
data.tar.gz: 9d8272950c1abfb41d078bec0c0909a9ae8d8ff66a01019f7908319baf651152
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f84a46b9cc61045fd3239f1e00aeda2d6d5ed1c7f68035782763be817b0d696fa829364610ea94389485f05ccf289745a8a58ead975504c2626a431747034272
|
|
7
|
+
data.tar.gz: 3a75d2e340d8753dc9ec901b8dd183c20847bc70101c08d435ecceb2d956214c8f6704c7fa81072758b3b31fd8fcc8bd79b8c83adc3b61a5a6d34a651feb341a
|
data/lib/puppet-lint/bin.rb
CHANGED
|
@@ -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
|
-
|
|
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
|
data/lib/puppet-lint/version.rb
CHANGED
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.
|
|
@@ -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(:
|
|
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.
|
|
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-
|
|
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
|