puppet-lint 5.0.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/checkplugin.rb +3 -1
- data/lib/puppet-lint/data.rb +3 -26
- 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/checkplugin_spec.rb +36 -0
- data/spec/unit/puppet-lint/puppet-lint_spec.rb +49 -0
- metadata +5 -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
|
|
@@ -55,7 +55,9 @@ class PuppetLint::CheckPlugin
|
|
|
55
55
|
#
|
|
56
56
|
# Returns an Array of PuppetLint::Lexer::Token objects.
|
|
57
57
|
def tokens
|
|
58
|
-
|
|
58
|
+
# When called from a plugins `check` method, the tokens array returned should be a (shallow) copy
|
|
59
|
+
called_from_check = (caller_locations(1..1).first.base_label == 'check')
|
|
60
|
+
PuppetLint::Data.tokens(duplicate: called_from_check)
|
|
59
61
|
end
|
|
60
62
|
|
|
61
63
|
def add_token(index, token)
|
data/lib/puppet-lint/data.rb
CHANGED
|
@@ -38,37 +38,14 @@ class PuppetLint::Data
|
|
|
38
38
|
@defaults_indexes = nil
|
|
39
39
|
end
|
|
40
40
|
|
|
41
|
-
# @api private
|
|
42
|
-
def ruby1?
|
|
43
|
-
@ruby1 = RbConfig::CONFIG['MAJOR'] == '1' if @ruby1.nil?
|
|
44
|
-
@ruby1
|
|
45
|
-
end
|
|
46
|
-
|
|
47
41
|
# Get the tokenised manifest.
|
|
48
42
|
#
|
|
43
|
+
# @param duplicate [Boolean] if true, returns a duplicate of the token array.
|
|
49
44
|
# @return [Array[PuppetLint::Lexer::Token]]
|
|
50
45
|
#
|
|
51
46
|
# @api public
|
|
52
|
-
def tokens
|
|
53
|
-
|
|
54
|
-
begin
|
|
55
|
-
caller[0][%r{`.*'}][1..-2] # rubocop:disable Performance/Caller
|
|
56
|
-
rescue NoMethodError
|
|
57
|
-
caller[1][%r{`.*'}][1..-2] # rubocop:disable Performance/Caller
|
|
58
|
-
end
|
|
59
|
-
else
|
|
60
|
-
begin
|
|
61
|
-
caller(0..0).first[%r{`.*'}][1..-2]
|
|
62
|
-
rescue NoMethodError
|
|
63
|
-
caller(1..1).first[%r{`.*'}][1..-2]
|
|
64
|
-
end
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
if calling_method == 'check'
|
|
68
|
-
@tokens.dup
|
|
69
|
-
else
|
|
70
|
-
@tokens
|
|
71
|
-
end
|
|
47
|
+
def tokens(duplicate: false)
|
|
48
|
+
duplicate ? @tokens.dup : @tokens
|
|
72
49
|
end
|
|
73
50
|
|
|
74
51
|
# Add new token.
|
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|
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
class DummyCheckPlugin < PuppetLint::CheckPlugin
|
|
4
|
+
def check
|
|
5
|
+
# Since we're calling `tokens` from a `check` method, we should get our own Array object.
|
|
6
|
+
# If we add an extra token to it, PuppetLint::Data.tokens should remain unchanged.
|
|
7
|
+
tokens << :extra_token
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def fix
|
|
11
|
+
tokens << :fix_token
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
describe PuppetLint::CheckPlugin do
|
|
16
|
+
before(:each) do
|
|
17
|
+
PuppetLint::Data.tokens = [:token1, :token2, :token3]
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
it 'returns a duplicate of the token array when called from check' do
|
|
21
|
+
plugin = DummyCheckPlugin.new
|
|
22
|
+
|
|
23
|
+
plugin.check
|
|
24
|
+
|
|
25
|
+
# Verify that the global token array remains unchanged.
|
|
26
|
+
expect(PuppetLint::Data.tokens).to eq([:token1, :token2, :token3])
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
it 'other methods can modify the tokens array' do
|
|
30
|
+
plugin = DummyCheckPlugin.new
|
|
31
|
+
|
|
32
|
+
plugin.fix
|
|
33
|
+
|
|
34
|
+
expect(PuppetLint::Data.tokens).to eq([:token1, :token2, :token3, :fix_token])
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -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.
|
|
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
|
|
@@ -105,6 +107,7 @@ files:
|
|
|
105
107
|
- spec/spec_helper_acceptance.rb
|
|
106
108
|
- spec/spec_helper_acceptance_local.rb
|
|
107
109
|
- spec/unit/puppet-lint/bin_spec.rb
|
|
110
|
+
- spec/unit/puppet-lint/checkplugin_spec.rb
|
|
108
111
|
- spec/unit/puppet-lint/checks_spec.rb
|
|
109
112
|
- spec/unit/puppet-lint/configuration_spec.rb
|
|
110
113
|
- spec/unit/puppet-lint/data_spec.rb
|