puppet-lint-topscope-variable-check 1.0.1 → 1.2.0

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: e0ad23632093e2963ab543f0e674b202023a5c6f959138af1c1f5f9391457f5a
4
- data.tar.gz: f1aa73f43b44e3cf0cfbe3ab5751e4ce4b036c95bfb4c12830c3e3fae4572320
3
+ metadata.gz: 8168088835aca0348f181b125582456955c20cb0dee175dd62f72ba1df6607bc
4
+ data.tar.gz: 646719472eedfae47ad5ad0a3cd5d3f57bc5bf6ef3e7f8f0f6a845f27052ed95
5
5
  SHA512:
6
- metadata.gz: 729764ccad0c21ff5ac08c93d892bf60b9e158c7639f307eaa3eaff6e1d30f21de26a4fdd47b0c2940c451ccbd998f9c6d63c69804c8fdce368bc8bf707079b6
7
- data.tar.gz: ebd1ab0074b7c9056c6a66b38160a7b6d9cda7323be9e188343aaf0ac719a48e5fed838a511e8c743b94c4e438b8b633abfe64d1ed42c78d75b9de3fd07bbd75
6
+ metadata.gz: e0585fb8efa9c97dade2f2a3ee3d725d1ccb0c59e220a105420b19100b33c73631b0de286e084b06c79d015ac3faa768044f243c54f4a5500821350a522d8d00
7
+ data.tar.gz: 23f37b88e4b10d51b8b05702e87081d554e048546193e9e633edc31a1a0350671ff3d01472702e8d7440c197cf2a9d0f63880440cb2b9c993a9827ac2d277392
data/README.md CHANGED
@@ -1,7 +1,10 @@
1
1
  puppet-lint-topscope-variable-check
2
2
  ========================
3
- [![Build Status](https://api.travis-ci.org/sixt/puppet-lint-topscope-variable-check.svg)](https://travis-ci.org/sixt/puppet-lint-topscope-variable-check)
4
-
3
+ [![License](https://img.shields.io/github/license/voxpupuli/puppet-lint-topscope-variable-check.svg)](https://github.com/voxpupuli/puppet-lint-topscope-variable-check/blob/master/LICENSE)
4
+ [![Test](https://github.com/voxpupuli/puppet-lint-topscope-variable-check/actions/workflows/test.yml/badge.svg)](https://github.com/voxpupuli/puppet-lint-topscope-variable-check/actions/workflows/test.yml)
5
+ [![Release](https://github.com/voxpupuli/puppet-lint-topscope-variable-check/actions/workflows/release.yml/badge.svg)](https://github.com/voxpupuli/puppet-lint-topscope-variable-check/actions/workflows/release.yml)
6
+ [![RubyGem Version](https://img.shields.io/gem/v/puppet-lint-topscope-variable-check.svg)](https://rubygems.org/gems/puppet-lint-topscope-variable-check)
7
+ [![RubyGem Downloads](https://img.shields.io/gem/dt/puppet-lint-topscope-variable-check.svg)](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
- class_name = class_list.first[:name_token].value.split('::').first
6
+
7
7
  tokens.select { |x| x.type == :VARIABLE }.each do |token|
8
- next if token.value !~ /^::#{class_name}::/
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
- <<-PUP.strip_heredoc
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
- <<-PUP.strip_heredoc
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
- <<-PUP.strip_heredoc
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
- <<-PUP.strip_heredoc
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
- <<-PUP.strip_heredoc
88
+ <<~PUP
73
89
  class foo::blub {
74
90
  notify { 'foo':
75
- message => $blub::bar
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
- <<-PUP.strip_heredoc
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
- <<-PUP.strip_heredoc
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 <<-PUP.strip_heredoc
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
- <<-PUP.strip_heredoc
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(19)
159
- end
160
-
161
- # it 'should remove :: after the $' do
162
- # expect(manifest).to eq <<-PUP.strip_heredoc
163
- # class foo::blub {
164
- # notify { 'foo':
165
- # message => ">${foo::bar}<"
166
- # }
167
- # }
168
- # PUP
169
- # end
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
- <<-PUP.strip_heredoc
237
+ <<~PUP
176
238
  include ::foo
177
239
  PUP
178
240
  end
data/spec/spec_helper.rb CHANGED
@@ -1,13 +1,29 @@
1
- require 'coveralls'
2
- Coveralls.wear!
1
+ # frozen_string_literal: true
3
2
 
4
- require 'puppet-lint'
5
- PuppetLint::Plugins.load_spec_helper
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
- # strip left spaces from heredoc
8
- # this emulates the behaviour of the ~ heredoc from ruby 2.3
9
- class String
10
- def strip_heredoc
11
- gsub(/^#{scan(/^\s*/).min_by(&:length)}/, '')
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,57 +1,55 @@
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.1
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
- - Martin Merfort
7
+ - Vox Pupuli
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-12 00:00:00.000000000 Z
11
+ date: 2023-02-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: puppet-lint
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '2.0'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '4'
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
- - - "~>"
27
+ - - ">="
25
28
  - !ruby/object:Gem::Version
26
29
  version: '2.0'
27
- - !ruby/object:Gem::Dependency
28
- name: coveralls
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
30
+ - - "<"
32
31
  - !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'
32
+ version: '4'
41
33
  - !ruby/object:Gem::Dependency
42
34
  name: rake
43
35
  requirement: !ruby/object:Gem::Requirement
44
36
  requirements:
45
- - - "~>"
37
+ - - ">="
46
38
  - !ruby/object:Gem::Version
47
39
  version: '12.0'
40
+ - - "<"
41
+ - !ruby/object:Gem::Version
42
+ version: '14'
48
43
  type: :development
49
44
  prerelease: false
50
45
  version_requirements: !ruby/object:Gem::Requirement
51
46
  requirements:
52
- - - "~>"
47
+ - - ">="
53
48
  - !ruby/object:Gem::Version
54
49
  version: '12.0'
50
+ - - "<"
51
+ - !ruby/object:Gem::Version
52
+ version: '14'
55
53
  - !ruby/object:Gem::Dependency
56
54
  name: rspec
57
55
  requirement: !ruby/object:Gem::Requirement
@@ -95,22 +93,22 @@ dependencies:
95
93
  - !ruby/object:Gem::Version
96
94
  version: '1.0'
97
95
  - !ruby/object:Gem::Dependency
98
- name: rubocop
96
+ name: simplecov
99
97
  requirement: !ruby/object:Gem::Requirement
100
98
  requirements:
101
- - - "~>"
99
+ - - ">="
102
100
  - !ruby/object:Gem::Version
103
- version: '0.58'
101
+ version: '0'
104
102
  type: :development
105
103
  prerelease: false
106
104
  version_requirements: !ruby/object:Gem::Requirement
107
105
  requirements:
108
- - - "~>"
106
+ - - ">="
109
107
  - !ruby/object:Gem::Version
110
- version: '0.58'
108
+ version: '0'
111
109
  description: " A puppet-lint plugin to check that topscope variable names don't
112
110
  start with ::.\n"
113
- email: platformengineering@sixt.com
111
+ email: voxpupuli@groups.io
114
112
  executables: []
115
113
  extensions: []
116
114
  extra_rdoc_files: []
@@ -120,7 +118,7 @@ files:
120
118
  - lib/puppet-lint/plugins/topscope_variable.rb
121
119
  - spec/puppet-lint/plugins/topscope_variable_spec.rb
122
120
  - spec/spec_helper.rb
123
- homepage: https://github.com/Sixt/puppet-lint-topscope-variable-check
121
+ homepage: https://github.com/voxpupuli/puppet-lint-topscope-variable-check
124
122
  licenses:
125
123
  - MIT
126
124
  metadata: {}
@@ -139,11 +137,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
139
137
  - !ruby/object:Gem::Version
140
138
  version: '0'
141
139
  requirements: []
142
- rubyforge_project:
143
- rubygems_version: 2.7.8
140
+ rubygems_version: 3.2.33
144
141
  signing_key:
145
142
  specification_version: 4
146
143
  summary: A puppet-lint plugin to check topscope variables.
147
144
  test_files:
148
- - spec/spec_helper.rb
149
145
  - spec/puppet-lint/plugins/topscope_variable_spec.rb
146
+ - spec/spec_helper.rb