puppet-lint-topscope-variable-check 1.0.1 → 1.1.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.
- checksums.yaml +4 -4
- data/README.md +15 -3
- data/lib/puppet-lint/plugins/topscope_variable.rb +2 -2
- data/spec/puppet-lint/plugins/topscope_variable_spec.rb +85 -23
- data/spec/spec_helper.rb +25 -9
- metadata +21 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5d8122dcc09b9ab9845447832f3d805ebf35d84a77360f8cb8b1ac5789dd4f1c
|
4
|
+
data.tar.gz: 13c983d895775467a2472517b1edbefa723b6fdfc778ed4a8720d0f2af61f592
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 05dcff337b51dee7bbfdbad3d049392363944c03b8cc7791df12c1aa8e0b24792158c04264c2b8e6f607f91d7fdc75250378668c8351be983b8bb002098c8082
|
7
|
+
data.tar.gz: 78b06a1c9ca140dab88a5d44578154afb35f8270226788785daf81fe841a62d2f75138f3652441ba20e00d51637d6008070d71971025a78610cc1426b2eac100
|
data/README.md
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
puppet-lint-topscope-variable-check
|
2
2
|
========================
|
3
|
-
[](https://github.com/voxpupuli/puppet-lint-topscope-variable-check/blob/master/LICENSE)
|
4
|
+
[](https://github.com/voxpupuli/puppet-lint-topscope-variable-check/actions/workflows/test.yml)
|
5
|
+
[](https://github.com/voxpupuli/puppet-lint-topscope-variable-check/actions/workflows/release.yml)
|
6
|
+
[](https://rubygems.org/gems/puppet-lint-topscope-variable-check)
|
7
|
+
[](https://rubygems.org/gems/puppet-lint-topscope-variable-check)
|
5
8
|
|
6
9
|
A puppet-lint plugin to check that topscope variables in a class do not begin with $::
|
7
10
|
|
@@ -72,13 +75,22 @@ PuppetLint.configuration.send('disable_topscope_variable')
|
|
72
75
|
```
|
73
76
|
## Limitations
|
74
77
|
|
75
|
-
The fix function of this plugin does not work when the variable is used in a string
|
78
|
+
The fix function of this plugin does not work when the variable is used in a string and hasn't been enclosed with `{}`.
|
76
79
|
For example:
|
77
80
|
|
78
81
|
``` puppet
|
79
82
|
$foo = "/etc/$::foobar::path/test"
|
80
83
|
```
|
81
84
|
|
85
|
+
Note: The [Variables Not Enclosed](http://puppet-lint.com/checks/variables_not_enclosed/) check can fix the missing braces and then the fix from this plugin should work.
|
86
|
+
|
87
|
+
## Transfer Notice
|
88
|
+
|
89
|
+
This plugin and github repository was originally developed and maintained by [Sixt](https://www.sixt.com/).
|
90
|
+
On 2021/11/24 the github project was transferred to [Voxpupuli](https://voxpupuli.org/) for ongoing improvement and maintenance.
|
91
|
+
|
92
|
+
Previously: https://github.com/Sixt/puppet-lint-topscope-variable-check
|
93
|
+
|
82
94
|
## License
|
83
95
|
```
|
84
96
|
MIT License
|
@@ -3,9 +3,9 @@ PuppetLint.new_check(:topscope_variable) do
|
|
3
3
|
class_list = (class_indexes + defined_type_indexes)
|
4
4
|
# do not check if the code is not part of a class
|
5
5
|
return if class_list.first.nil?
|
6
|
-
|
6
|
+
|
7
7
|
tokens.select { |x| x.type == :VARIABLE }.each do |token|
|
8
|
-
next if token.value !~
|
8
|
+
next if token.value !~ /^::[a-z0-9_][a-zA-Z0-9_]+::/
|
9
9
|
fixed = token.value.sub(/^::/, '')
|
10
10
|
notify(
|
11
11
|
:warning,
|
@@ -5,7 +5,7 @@ describe 'topscope_variable' do
|
|
5
5
|
context 'with fix disabled' do
|
6
6
|
context 'with correct topscope' do
|
7
7
|
let(:code) do
|
8
|
-
|
8
|
+
<<~PUP
|
9
9
|
class foo::blub {
|
10
10
|
notify { 'foo':
|
11
11
|
message => $foo::bar
|
@@ -21,7 +21,7 @@ describe 'topscope_variable' do
|
|
21
21
|
|
22
22
|
context 'with incorrect topscope' do
|
23
23
|
let(:code) do
|
24
|
-
|
24
|
+
<<~PUP
|
25
25
|
class foo::blub {
|
26
26
|
notify { 'foo':
|
27
27
|
message => $::foo::bar
|
@@ -35,9 +35,25 @@ describe 'topscope_variable' do
|
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
38
|
+
context 'with incorrect topscope from external module' do
|
39
|
+
let(:code) do
|
40
|
+
<<~PUP
|
41
|
+
class profile::foo {
|
42
|
+
notify { 'foo':
|
43
|
+
message => $::some_component_module::bar
|
44
|
+
}
|
45
|
+
}
|
46
|
+
PUP
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'should detect one problem' do
|
50
|
+
expect(problems).to have(1).problem
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
38
54
|
context 'with correct topscope in params' do
|
39
55
|
let(:code) do
|
40
|
-
|
56
|
+
<<~PUP
|
41
57
|
class foo::blub(
|
42
58
|
String $foo = $params::foo
|
43
59
|
) {
|
@@ -53,7 +69,7 @@ describe 'topscope_variable' do
|
|
53
69
|
|
54
70
|
context 'with incorrect topscope in params' do
|
55
71
|
let(:code) do
|
56
|
-
|
72
|
+
<<~PUP
|
57
73
|
class foo::blub(
|
58
74
|
String $foo = $::foo::params::foo
|
59
75
|
) {
|
@@ -69,10 +85,10 @@ describe 'topscope_variable' do
|
|
69
85
|
|
70
86
|
context 'with a fact that has been used improperly' do
|
71
87
|
let(:code) do
|
72
|
-
|
88
|
+
<<~PUP
|
73
89
|
class foo::blub {
|
74
90
|
notify { 'foo':
|
75
|
-
message =>
|
91
|
+
message => $::operatingsystem
|
76
92
|
}
|
77
93
|
}
|
78
94
|
PUP
|
@@ -82,6 +98,22 @@ describe 'topscope_variable' do
|
|
82
98
|
expect(problems).to have(0).problem
|
83
99
|
end
|
84
100
|
end
|
101
|
+
|
102
|
+
context 'with a fact that has been used improperly in params' do
|
103
|
+
let(:code) do
|
104
|
+
<<~PUP
|
105
|
+
class foo::blub(
|
106
|
+
String $foo = $::operatingsystem
|
107
|
+
) {
|
108
|
+
# ...
|
109
|
+
}
|
110
|
+
PUP
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'should not detect any problems' do
|
114
|
+
expect(problems).to have(0).problem
|
115
|
+
end
|
116
|
+
end
|
85
117
|
end
|
86
118
|
|
87
119
|
context 'with fix enabled' do
|
@@ -95,7 +127,7 @@ describe 'topscope_variable' do
|
|
95
127
|
|
96
128
|
context 'with correct topscope' do
|
97
129
|
let(:code) do
|
98
|
-
|
130
|
+
<<~PUP
|
99
131
|
class foo::blub {
|
100
132
|
notify { 'foo':
|
101
133
|
message => $foo::bar
|
@@ -111,7 +143,7 @@ describe 'topscope_variable' do
|
|
111
143
|
|
112
144
|
context 'with incorrect topscope' do
|
113
145
|
let(:code) do
|
114
|
-
|
146
|
+
<<~PUP
|
115
147
|
class foo::blub {
|
116
148
|
notify { 'foo':
|
117
149
|
message => $::foo::bar
|
@@ -129,7 +161,7 @@ describe 'topscope_variable' do
|
|
129
161
|
end
|
130
162
|
|
131
163
|
it 'should remove :: after the $' do
|
132
|
-
expect(manifest).to eq
|
164
|
+
expect(manifest).to eq <<~PUP
|
133
165
|
class foo::blub {
|
134
166
|
notify { 'foo':
|
135
167
|
message => $foo::bar
|
@@ -139,9 +171,39 @@ describe 'topscope_variable' do
|
|
139
171
|
end
|
140
172
|
end
|
141
173
|
|
174
|
+
context 'with incorrect topscope from external module' do
|
175
|
+
let(:code) do
|
176
|
+
<<~PUP
|
177
|
+
class profile::foo {
|
178
|
+
notify { 'foo':
|
179
|
+
message => $::some_component_module::bar
|
180
|
+
}
|
181
|
+
}
|
182
|
+
PUP
|
183
|
+
end
|
184
|
+
|
185
|
+
it 'should detect one problem' do
|
186
|
+
expect(problems).to have(1).problem
|
187
|
+
end
|
188
|
+
|
189
|
+
it 'should fix the problem' do
|
190
|
+
expect(problems).to contain_fixed('use $some_component_module::bar instead of $::some_component_module::bar').on_line(3).in_column(16)
|
191
|
+
end
|
192
|
+
|
193
|
+
it 'should remove :: after the $' do
|
194
|
+
expect(manifest).to eq <<~PUP
|
195
|
+
class profile::foo {
|
196
|
+
notify { 'foo':
|
197
|
+
message => $some_component_module::bar
|
198
|
+
}
|
199
|
+
}
|
200
|
+
PUP
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
142
204
|
context 'with incorrect topscope in quoted variable' do
|
143
205
|
let(:code) do
|
144
|
-
|
206
|
+
<<~PUP
|
145
207
|
class foo::blub {
|
146
208
|
notify { 'foo':
|
147
209
|
message => ">${::foo::bar}<"
|
@@ -155,24 +217,24 @@ describe 'topscope_variable' do
|
|
155
217
|
end
|
156
218
|
|
157
219
|
it 'should fix the problem' do
|
158
|
-
expect(problems).to contain_fixed(msg).on_line(3).in_column(
|
159
|
-
end
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
220
|
+
expect(problems).to contain_fixed(msg).on_line(3).in_column(20)
|
221
|
+
end
|
222
|
+
|
223
|
+
it 'should remove :: after the $' do
|
224
|
+
expect(manifest).to eq <<~PUP
|
225
|
+
class foo::blub {
|
226
|
+
notify { 'foo':
|
227
|
+
message => ">${foo::bar}<"
|
228
|
+
}
|
229
|
+
}
|
230
|
+
PUP
|
231
|
+
end
|
170
232
|
end
|
171
233
|
end
|
172
234
|
|
173
235
|
context 'without a class scope' do
|
174
236
|
let(:code) do
|
175
|
-
|
237
|
+
<<~PUP
|
176
238
|
include ::foo
|
177
239
|
PUP
|
178
240
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,13 +1,29 @@
|
|
1
|
-
|
2
|
-
Coveralls.wear!
|
1
|
+
# frozen_string_literal: true
|
3
2
|
|
4
|
-
|
5
|
-
|
3
|
+
begin
|
4
|
+
require 'simplecov'
|
5
|
+
require 'simplecov-console'
|
6
|
+
require 'codecov'
|
7
|
+
rescue LoadError
|
8
|
+
else
|
9
|
+
SimpleCov.start do
|
10
|
+
track_files 'lib/**/*.rb'
|
11
|
+
|
12
|
+
add_filter '/spec'
|
6
13
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
14
|
+
enable_coverage :branch
|
15
|
+
|
16
|
+
# do not track vendored files
|
17
|
+
add_filter '/vendor'
|
18
|
+
add_filter '/.vendor'
|
12
19
|
end
|
20
|
+
|
21
|
+
SimpleCov.formatters = [
|
22
|
+
SimpleCov::Formatter::Console,
|
23
|
+
SimpleCov::Formatter::Codecov,
|
24
|
+
]
|
13
25
|
end
|
26
|
+
|
27
|
+
require 'puppet-lint'
|
28
|
+
|
29
|
+
PuppetLint::Plugins.load_spec_helper
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puppet-lint-topscope-variable-check
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- Vox Pupuli
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-07-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: puppet-lint
|
@@ -24,20 +24,6 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '2.0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: coveralls
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '0.8'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0.8'
|
41
27
|
- !ruby/object:Gem::Dependency
|
42
28
|
name: rake
|
43
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -108,9 +94,23 @@ dependencies:
|
|
108
94
|
- - "~>"
|
109
95
|
- !ruby/object:Gem::Version
|
110
96
|
version: '0.58'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: simplecov
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
111
|
description: " A puppet-lint plugin to check that topscope variable names don't
|
112
112
|
start with ::.\n"
|
113
|
-
email:
|
113
|
+
email: voxpupuli@groups.io
|
114
114
|
executables: []
|
115
115
|
extensions: []
|
116
116
|
extra_rdoc_files: []
|
@@ -120,7 +120,7 @@ files:
|
|
120
120
|
- lib/puppet-lint/plugins/topscope_variable.rb
|
121
121
|
- spec/puppet-lint/plugins/topscope_variable_spec.rb
|
122
122
|
- spec/spec_helper.rb
|
123
|
-
homepage: https://github.com/
|
123
|
+
homepage: https://github.com/voxpupuli/puppet-lint-topscope-variable-check
|
124
124
|
licenses:
|
125
125
|
- MIT
|
126
126
|
metadata: {}
|
@@ -139,11 +139,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
139
139
|
- !ruby/object:Gem::Version
|
140
140
|
version: '0'
|
141
141
|
requirements: []
|
142
|
-
|
143
|
-
rubygems_version: 2.7.8
|
142
|
+
rubygems_version: 3.2.33
|
144
143
|
signing_key:
|
145
144
|
specification_version: 4
|
146
145
|
summary: A puppet-lint plugin to check topscope variables.
|
147
146
|
test_files:
|
148
|
-
- spec/spec_helper.rb
|
149
147
|
- spec/puppet-lint/plugins/topscope_variable_spec.rb
|
148
|
+
- spec/spec_helper.rb
|