puppet-lint 4.2.3 → 4.2.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0bbb51ba5c4cc604cd5eb02b2d51791f6df279db955fcd9e77747f79b6890cff
4
- data.tar.gz: 0e187bb2ab101f20669c387ca3297513ff781edf20d2708e2271ba2778f8df4e
3
+ metadata.gz: 9b11b8ac88b45741f4cc6ec8a5eca05da09c52c1064a0bbd89394459981845b6
4
+ data.tar.gz: ed5b7f181a30f706ca4224a526d29212ed2a7e9fb4d2fea0927e2e2a3e02ae8c
5
5
  SHA512:
6
- metadata.gz: 221dc05dc214701d1ffc688ec01fc2c6aa9c3adddc699c55e62894124c66b08a222f864f285bc1e8a65c4466b90967778e02f4f2f7ab805874057ce02db52b72
7
- data.tar.gz: ba771036c9326dbd2e6831c4fc1ec17f7e81f7f4a41967c801ea78e3d74944dc61f51bda246428b62bedfa58891561bff078a7386d64cd61b6f3b78c5bfa6a66
6
+ metadata.gz: b79ad1ee950cc2dde1c61dd3adaf0b1900b80c63916d28f6ed5fba99f84ae76608ccfba01e533c6f7014f05b659904dc80ea9631b7ebfef573166a4a930b69ac
7
+ data.tar.gz: 927256f4add5e6c2fd2e0336ba6244b730223429de681fd73644e0c45df36b8d4237899af8bc2c92b7f3e4b159beedbe8c1071c94e5504178ea7dbfcaeb86d93
@@ -121,7 +121,7 @@ class PuppetLint::Checks
121
121
  # Returns an Array of String check names.
122
122
  def enabled_checks
123
123
  @enabled_checks ||= PuppetLint.configuration.checks.select do |check|
124
- PuppetLint.configuration.send("#{check}_enabled?")
124
+ PuppetLint.configuration.send(:"#{check}_enabled?")
125
125
  end
126
126
  end
127
127
 
@@ -17,21 +17,21 @@ class PuppetLint::Configuration
17
17
  # Public: Determine if the named check is enabled.
18
18
  #
19
19
  # Returns true if the check is enabled, otherwise return false.
20
- define_method("#{check}_enabled?") do
20
+ define_method(:"#{check}_enabled?") do
21
21
  settings["#{check}_disabled"] != true
22
22
  end
23
23
 
24
24
  # Public: Disable the named check.
25
25
  #
26
26
  # Returns nothing.
27
- define_method("disable_#{check}") do
27
+ define_method(:"disable_#{check}") do
28
28
  settings["#{check}_disabled"] = true
29
29
  end
30
30
 
31
31
  # Public: Enable the named check.
32
32
  #
33
33
  # Returns nothing.
34
- define_method("enable_#{check}") do
34
+ define_method(:"enable_#{check}") do
35
35
  settings["#{check}_disabled"] = false
36
36
  end
37
37
  end
@@ -92,7 +92,7 @@ class PuppetLint::Configuration
92
92
  # value - The value to set the option to.
93
93
  #
94
94
  # Returns nothing.
95
- define_method("#{option}=") do |value|
95
+ define_method(:"#{option}=") do |value|
96
96
  settings[option] = value
97
97
  end
98
98
 
@@ -117,9 +117,9 @@ class PuppetLint::OptParser
117
117
  enable_checks = checks.split(',').map(&:to_sym)
118
118
  PuppetLint.configuration.checks.each do |check|
119
119
  if enable_checks.include?(check)
120
- PuppetLint.configuration.send("enable_#{check}")
120
+ PuppetLint.configuration.send(:"enable_#{check}")
121
121
  else
122
- PuppetLint.configuration.send("disable_#{check}")
122
+ PuppetLint.configuration.send(:"disable_#{check}")
123
123
  end
124
124
  end
125
125
  end
@@ -130,13 +130,13 @@ class PuppetLint::OptParser
130
130
 
131
131
  PuppetLint.configuration.checks.each do |check|
132
132
  opts.on("--no-#{check}-check", "Skip the #{check} check.") do
133
- PuppetLint.configuration.send("disable_#{check}")
133
+ PuppetLint.configuration.send(:"disable_#{check}")
134
134
  end
135
135
 
136
- next if PuppetLint.configuration.send("#{check}_enabled?")
136
+ next if PuppetLint.configuration.send(:"#{check}_enabled?")
137
137
 
138
138
  opts.on("--#{check}-check", "Enable the #{check} check.") do
139
- PuppetLint.configuration.send("enable_#{check}")
139
+ PuppetLint.configuration.send(:"enable_#{check}")
140
140
  end
141
141
  end
142
142
  end
@@ -44,6 +44,14 @@ PuppetLint.new_check(:top_scope_facts) do
44
44
  end
45
45
 
46
46
  def fix(problem)
47
- problem[:token].value = "facts['" + problem[:token].value.sub(%r{^::}, '') + "']"
47
+ problem[:token].value.sub!(%r{^::}, '')
48
+ # checks if the fact is a top level structured fact e.g. ::my_structured_fact['foo']['bar']
49
+ if %r{\[.*}.match?(problem[:token].value)
50
+ fact_name = problem[:token].value.sub(%r{\[.*}, '')
51
+ nested_facts = problem[:token].value.scan(%r{\[.*}).first
52
+ problem[:token].value = "facts['" + fact_name + "']" + nested_facts
53
+ else
54
+ problem[:token].value = "facts['" + problem[:token].value + "']"
55
+ end
48
56
  end
49
57
  end
@@ -52,19 +52,19 @@ class PuppetLint::RakeTask < Rake::TaskLib
52
52
  enable_checks = Array(@only_checks).map(&:to_sym)
53
53
  PuppetLint.configuration.checks.each do |check|
54
54
  if enable_checks.include?(check)
55
- PuppetLint.configuration.send("enable_#{check}")
55
+ PuppetLint.configuration.send(:"enable_#{check}")
56
56
  else
57
- PuppetLint.configuration.send("disable_#{check}")
57
+ PuppetLint.configuration.send(:"disable_#{check}")
58
58
  end
59
59
  end
60
60
  end
61
61
 
62
62
  Array(@disable_checks).each do |check|
63
- PuppetLint.configuration.send("disable_#{check}")
63
+ PuppetLint.configuration.send(:"disable_#{check}")
64
64
  end
65
65
 
66
66
  ['with_filename', 'fail_on_warnings', 'error_level', 'log_format', 'with_context', 'fix', 'show_ignored', 'relative'].each do |config|
67
- value = instance_variable_get("@#{config}")
67
+ value = instance_variable_get(:"@#{config}")
68
68
  PuppetLint.configuration.send("#{config}=".to_sym, value) unless value.nil?
69
69
  end
70
70
 
@@ -1,3 +1,3 @@
1
1
  class PuppetLint
2
- VERSION = '4.2.3'.freeze
2
+ VERSION = '4.2.4'.freeze
3
3
  end
data/lib/puppet-lint.rb CHANGED
@@ -252,7 +252,7 @@ class PuppetLint
252
252
  # end
253
253
  def self.new_check(name, &block)
254
254
  class_name = name.to_s.split('_').map(&:capitalize).join
255
- klass = PuppetLint.const_set("Check#{class_name}", Class.new(PuppetLint::CheckPlugin))
255
+ klass = PuppetLint.const_set(:"Check#{class_name}", Class.new(PuppetLint::CheckPlugin))
256
256
  klass.const_set(:NAME, name)
257
257
  klass.class_exec(&block)
258
258
  PuppetLint.configuration.add_check(name, klass)
data/spec/spec_helper.rb CHANGED
@@ -1,12 +1,22 @@
1
1
  # Disable GitHub Actions reporting since it breaks the test suite
2
2
  ENV.delete('GITHUB_ACTION')
3
3
 
4
- if ENV['COVERAGE'] == 'yes' && RUBY_VERSION.start_with?('2.7.')
5
- require 'simplecov'
6
- SimpleCov.start do
7
- add_filter('/spec/')
8
- add_filter('/vendor/')
9
- add_group('Checks', 'lib/puppet-lint/plugins')
4
+ if ENV['COVERAGE'] == 'yes'
5
+ begin
6
+ require 'simplecov'
7
+ require 'simplecov-console'
8
+ SimpleCov.formatters = [
9
+ SimpleCov::Formatter::HTMLFormatter,
10
+ SimpleCov::Formatter::Console,
11
+ ]
12
+
13
+ SimpleCov.start do
14
+ add_filter('/spec/')
15
+ add_filter('/vendor/')
16
+ add_group('Checks', 'lib/puppet-lint/plugins')
17
+ end
18
+ rescue LoadError
19
+ raise 'Add the simplecov & simplecov-console gems to Gemfile to enable this task'
10
20
  end
11
21
  end
12
22
 
@@ -102,6 +102,18 @@ describe 'top_scope_facts' do
102
102
  end
103
103
  end
104
104
 
105
+ context 'top scope structured fact not present on allowlist' do
106
+ let(:code) { "$::my_structured_fact['foo']['test']" }
107
+
108
+ it 'detects a problem' do
109
+ expect(problems).to contain_fixed('top scope fact instead of facts hash').on_line(1).in_column(1)
110
+ end
111
+
112
+ it 'fixes the problem' do
113
+ expect(manifest).to eq("$facts['my_structured_fact']['foo']['test']")
114
+ end
115
+ end
116
+
105
117
  context 'top scope $::trusted hash' do
106
118
  let(:code) { "$::trusted['certname']" }
107
119
 
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: 4.2.3
4
+ version: 4.2.4
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: 2023-11-22 00:00:00.000000000 Z
13
+ date: 2024-02-09 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"