puppet-lint 3.0.1 → 3.2.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.
@@ -0,0 +1,194 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'top_scope_facts' do
4
+ let(:msg) { 'top scope fact instead of facts hash' }
5
+
6
+ context 'with fix disabled' do
7
+ context 'fact variable using $facts hash' do
8
+ let(:code) { "$facts['operatingsystem']" }
9
+
10
+ it 'does not detect any problems' do
11
+ expect(problems).to have(0).problem
12
+ end
13
+ end
14
+ context 'non-fact variable with two colons' do
15
+ let(:code) { '$foo::bar' }
16
+
17
+ it 'does not detect any problems' do
18
+ expect(problems).to have(0).problem
19
+ end
20
+ end
21
+
22
+ context 'top scope $::facts hash' do
23
+ let(:code) { "$::facts['os']['family']" }
24
+
25
+ it 'does not detect any problems' do
26
+ expect(problems).to have(0).problem
27
+ end
28
+ end
29
+
30
+ context 'top scope $::trusted hash' do
31
+ let(:code) { "$::trusted['certname']" }
32
+
33
+ it 'does not detect any problems' do
34
+ expect(problems).to have(0).problem
35
+ end
36
+ end
37
+
38
+ context 'fact variable using top scope' do
39
+ let(:code) { '$::operatingsystem' }
40
+
41
+ it 'onlies detect a single problem' do
42
+ expect(problems).to have(1).problem
43
+ end
44
+
45
+ it 'creates a warning' do
46
+ expect(problems).to contain_warning(msg).on_line(1).in_column(1)
47
+ end
48
+ end
49
+
50
+ context 'fact variable using top scope with curly braces in double quote' do
51
+ let(:code) { '"${::operatingsystem}"' }
52
+
53
+ it 'onlies detect a single problem' do
54
+ expect(problems).to have(1).problem
55
+ end
56
+
57
+ it 'creates a warning' do
58
+ expect(problems).to contain_warning(msg).on_line(1).in_column(4)
59
+ end
60
+ end
61
+
62
+ context 'out of scope namespaced variable with leading ::' do
63
+ let(:code) { '$::profile::foo::bar' }
64
+
65
+ it 'does not detect any problems' do
66
+ expect(problems).to have(0).problem
67
+ end
68
+
69
+ context 'inside double quotes' do
70
+ let(:code) { '"$::profile::foo::bar"' }
71
+
72
+ it 'does not detect any problems' do
73
+ expect(problems).to have(0).problem
74
+ end
75
+ end
76
+
77
+ context 'with curly braces in double quote' do
78
+ let(:code) { '"${::profile::foo::bar}"' }
79
+
80
+ it 'does not detect any problems' do
81
+ expect(problems).to have(0).problem
82
+ end
83
+ end
84
+ end
85
+ end
86
+
87
+ context 'with fix enabled' do
88
+ before(:each) do
89
+ PuppetLint.configuration.fix = true
90
+ end
91
+
92
+ after(:each) do
93
+ PuppetLint.configuration.fix = false
94
+ end
95
+
96
+ context 'fact variable using $facts hash' do
97
+ let(:code) { "$facts['operatingsystem']" }
98
+
99
+ it 'does not detect any problems' do
100
+ expect(problems).to have(0).problem
101
+ end
102
+ end
103
+
104
+ context 'non-fact variable with two colons' do
105
+ let(:code) { '$foo::bar' }
106
+
107
+ it 'does not detect any problems' do
108
+ expect(problems).to have(0).problem
109
+ end
110
+ end
111
+
112
+ context 'top scope $::facts hash' do
113
+ let(:code) { "$::facts['os']['family']" }
114
+
115
+ it 'does not detect any problems' do
116
+ expect(problems).to have(0).problem
117
+ end
118
+ end
119
+
120
+ context 'top scope $::trusted hash' do
121
+ let(:code) { "$::trusted['certname']" }
122
+
123
+ it 'does not detect any problems' do
124
+ expect(problems).to have(0).problem
125
+ end
126
+ end
127
+
128
+ context 'fact variable using top scope' do
129
+ let(:code) { '$::operatingsystem' }
130
+
131
+ it 'onlies detect a single problem' do
132
+ expect(problems).to have(1).problem
133
+ end
134
+
135
+ it 'fixes the problem' do
136
+ expect(problems).to contain_fixed(msg).on_line(1).in_column(1)
137
+ end
138
+
139
+ it 'shoulds use the facts hash' do
140
+ expect(manifest).to eq("$facts['operatingsystem']")
141
+ end
142
+ end
143
+
144
+ context 'fact variable using top scope with curly braces in double quote' do
145
+ let(:code) { '"${::operatingsystem}"' }
146
+
147
+ it 'fixes the problem' do
148
+ expect(problems).to contain_fixed(msg).on_line(1).in_column(4)
149
+ end
150
+
151
+ it 'shoulds use the facts hash' do
152
+ expect(manifest).to eq('"${facts[\'operatingsystem\']}"')
153
+ end
154
+ end
155
+
156
+ context 'with custom top scope fact variables' do
157
+ before(:each) do
158
+ PuppetLint.configuration.top_scope_variables = ['location', 'role']
159
+ end
160
+
161
+ context 'fact variable using $facts hash' do
162
+ let(:code) { "$facts['operatingsystem']" }
163
+
164
+ it 'does not detect any problems' do
165
+ expect(problems).to have(0).problem
166
+ end
167
+ end
168
+
169
+ context 'fact variable using $trusted hash' do
170
+ let(:code) { "$trusted['certname']" }
171
+
172
+ it 'does not detect any problems' do
173
+ expect(problems).to have(0).problem
174
+ end
175
+ end
176
+
177
+ context 'whitelisted top scope variable $::location' do
178
+ let(:code) { '$::location' }
179
+
180
+ it 'does not detect any problems' do
181
+ expect(problems).to have(0).problem
182
+ end
183
+ end
184
+
185
+ context 'non-whitelisted top scope variable $::application' do
186
+ let(:code) { '$::application' }
187
+
188
+ it 'does not detect any problems' do
189
+ expect(problems).to have(1).problem
190
+ end
191
+ end
192
+ end
193
+ end
194
+ 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: 3.0.1
4
+ version: 3.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Sharpe
@@ -10,10 +10,10 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2022-10-20 00:00:00.000000000 Z
13
+ date: 2023-02-28 00:00:00.000000000 Z
14
14
  dependencies: []
15
15
  description: " Checks your Puppet manifests against the Puppetlabs style guide
16
- and alerts you to any discrepancies.'\n"
16
+ and alerts you to any discrepancies.\n"
17
17
  email:
18
18
  - tim@sharpe.id.au
19
19
  - modules-team@puppet.com
@@ -22,7 +22,6 @@ executables:
22
22
  extensions: []
23
23
  extra_rdoc_files: []
24
24
  files:
25
- - ".rubocop.yml"
26
25
  - LICENSE
27
26
  - README.md
28
27
  - bin/puppet-lint
@@ -76,12 +75,16 @@ files:
76
75
  - lib/puppet-lint/plugins/check_whitespace/hard_tabs.rb
77
76
  - lib/puppet-lint/plugins/check_whitespace/line_length.rb
78
77
  - lib/puppet-lint/plugins/check_whitespace/trailing_whitespace.rb
78
+ - lib/puppet-lint/plugins/legacy_facts/legacy_facts.rb
79
+ - lib/puppet-lint/plugins/top_scope_facts/top_scope_facts.rb
80
+ - lib/puppet-lint/report/codeclimate.rb
79
81
  - lib/puppet-lint/report/github.rb
80
82
  - lib/puppet-lint/report/sarif_template.json
81
83
  - lib/puppet-lint/tasks/gemfile_rewrite.rb
82
84
  - lib/puppet-lint/tasks/puppet-lint.rb
83
85
  - lib/puppet-lint/tasks/release_test.rb
84
86
  - lib/puppet-lint/version.rb
87
+ - rubocop_baseline.yml
85
88
  - spec/acceptance/puppet_lint_spec.rb
86
89
  - spec/fixtures/test/manifests/fail.pp
87
90
  - spec/fixtures/test/manifests/ignore.pp
@@ -95,6 +98,7 @@ files:
95
98
  - spec/fixtures/test/manifests/unterminated_control_comment.pp
96
99
  - spec/fixtures/test/manifests/url_interpolation.pp
97
100
  - spec/fixtures/test/manifests/warning.pp
101
+ - spec/fixtures/test/reports/code_climate.json
98
102
  - spec/spec_helper.rb
99
103
  - spec/spec_helper_acceptance.rb
100
104
  - spec/spec_helper_acceptance_local.rb
@@ -143,6 +147,8 @@ files:
143
147
  - spec/unit/puppet-lint/plugins/check_whitespace/arrow_alignment_spec.rb
144
148
  - spec/unit/puppet-lint/plugins/check_whitespace/hard_tabs_spec.rb
145
149
  - spec/unit/puppet-lint/plugins/check_whitespace/trailing_whitespace_spec.rb
150
+ - spec/unit/puppet-lint/plugins/legacy_facts/legacy_facts_spec.rb
151
+ - spec/unit/puppet-lint/plugins/top_scope_facts/top_scope_facts_spec.rb
146
152
  - spec/unit/puppet-lint/puppet-lint_spec.rb
147
153
  homepage: https://github.com/puppetlabs/puppet-lint/
148
154
  licenses:
@@ -156,7 +162,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
156
162
  requirements:
157
163
  - - ">="
158
164
  - !ruby/object:Gem::Version
159
- version: '2.7'
165
+ version: '2.5'
160
166
  required_rubygems_version: !ruby/object:Gem::Requirement
161
167
  requirements:
162
168
  - - ">="