puppet-lint-absolute_classname-check 2.0.0 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +29 -0
- data/lib/puppet-lint/plugins/check_absolute_classname.rb +10 -0
- data/lib/puppet-lint/plugins/check_classname_reference.rb +26 -0
- data/spec/puppet-lint/plugins/check_absolute_classname/relative_classname_inclusion_spec.rb +19 -4
- data/spec/puppet-lint/plugins/check_classname_reference/relative_classname_reference_spec.rb +137 -0
- metadata +10 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d80c6cabf675148fec4eba47d1fe97898c981c5e80694d910357203a19e6ca14
|
4
|
+
data.tar.gz: 64ece9ae2635f02514bd25e6f9d5ed2f80c4f2880d7c0de9bbb6885c0b562b7f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5a2f19eacda49f7211cd74e60914c0e9f07d76108268cfa918bf80c1eb4a4376838c6c2ef66c84d3c0ba5b4768ff208f5c751078724ca01a3017388cf2c0bf45
|
7
|
+
data.tar.gz: d08fff8a098711dcdda56193c83413196c90c8b228b5e16d91e9c34befe3bc0054c75d979e5827b6e42c3c3a99c83a46f7f3fc849b939525d053f5731252dd78
|
data/README.md
CHANGED
@@ -17,6 +17,7 @@ A puppet-lint plugin to check that classes are included by their absolute name.
|
|
17
17
|
* [In a Gemfile](#in-a-gemfile)
|
18
18
|
* [Checks](#checks)
|
19
19
|
* [Relative class name inclusion](#relative-class-name-inclusion)
|
20
|
+
* [Relative class reference](#relative-classname-reference)
|
20
21
|
* [Transfer notice](#transfer-notice)
|
21
22
|
* [Release Informaion](#release-information)
|
22
23
|
|
@@ -66,6 +67,34 @@ Alternatively, if you’re calling puppet-lint via the Rake task, you should ins
|
|
66
67
|
PuppetLint.configuration.send('disable_relative_classname_inclusion')
|
67
68
|
```
|
68
69
|
|
70
|
+
### Relative class reference
|
71
|
+
|
72
|
+
#### What you have done
|
73
|
+
|
74
|
+
```puppet
|
75
|
+
Class['::foo'] -> Class['::bar']
|
76
|
+
```
|
77
|
+
|
78
|
+
#### What you should have done
|
79
|
+
|
80
|
+
```puppet
|
81
|
+
Class['foo'] -> Class['bar']
|
82
|
+
```
|
83
|
+
|
84
|
+
#### Disabling the check
|
85
|
+
|
86
|
+
To disable this check, you can add `--no-relative_classname_reference-check` to your puppet-lint command line.
|
87
|
+
|
88
|
+
```shell
|
89
|
+
$ puppet-lint --no-relative_classname_reference-check path/to/file.pp
|
90
|
+
```
|
91
|
+
|
92
|
+
Alternatively, if you’re calling puppet-lint via the Rake task, you should insert the following line to your `Rakefile`.
|
93
|
+
|
94
|
+
```ruby
|
95
|
+
PuppetLint.configuration.send('disable_relative_classname_reference')
|
96
|
+
```
|
97
|
+
|
69
98
|
## Transfer Notice
|
70
99
|
|
71
100
|
This plugin was originally authored by [Camptocamp](http://www.camptocamp.com).
|
@@ -40,6 +40,16 @@ PuppetLint.new_check(:relative_classname_inclusion) do
|
|
40
40
|
end
|
41
41
|
s = s.next_token
|
42
42
|
end
|
43
|
+
elsif token.type == :INHERITS
|
44
|
+
s = token.next_code_token
|
45
|
+
if s.type == :NAME && s.value.start_with?('::')
|
46
|
+
notify :warning, {
|
47
|
+
message: message,
|
48
|
+
line: s.line,
|
49
|
+
column: s.column,
|
50
|
+
token: s
|
51
|
+
}
|
52
|
+
end
|
43
53
|
end
|
44
54
|
end
|
45
55
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
PuppetLint.new_check(:relative_classname_reference) do
|
2
|
+
def check
|
3
|
+
message = 'absolute class name reference'
|
4
|
+
|
5
|
+
tokens.each_with_index do |token, token_idx|
|
6
|
+
if token.type == :TYPE and token.value == 'Class' and token.next_code_token.type == :LBRACK
|
7
|
+
s = token.next_code_token
|
8
|
+
while s.type != :RBRACK
|
9
|
+
if (s.type == :NAME || s.type == :SSTRING) && s.value.start_with?('::')
|
10
|
+
notify :warning, {
|
11
|
+
message: message,
|
12
|
+
line: s.line,
|
13
|
+
column: s.column,
|
14
|
+
token: s
|
15
|
+
}
|
16
|
+
end
|
17
|
+
s = s.next_token
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def fix(problem)
|
24
|
+
problem[:token].value = problem[:token].value[2..-1]
|
25
|
+
end
|
26
|
+
end
|
@@ -29,11 +29,14 @@ describe 'relative_classname_inclusion' do
|
|
29
29
|
require('::foobar')
|
30
30
|
require(foobar(baz))
|
31
31
|
require(foobar('baz'))
|
32
|
+
|
33
|
+
class foobar inherits ::baz {
|
34
|
+
}
|
32
35
|
EOS
|
33
36
|
end
|
34
37
|
|
35
|
-
it 'should detect
|
36
|
-
expect(problems).to have(
|
38
|
+
it 'should detect 12 problems' do
|
39
|
+
expect(problems).to have(12).problems
|
37
40
|
end
|
38
41
|
|
39
42
|
it 'should create warnings' do
|
@@ -48,6 +51,7 @@ describe 'relative_classname_inclusion' do
|
|
48
51
|
expect(problems).to contain_warning(msg).on_line(15).in_column(17)
|
49
52
|
expect(problems).to contain_warning(msg).on_line(19).in_column(17)
|
50
53
|
expect(problems).to contain_warning(msg).on_line(20).in_column(17)
|
54
|
+
expect(problems).to contain_warning(msg).on_line(24).in_column(31)
|
51
55
|
end
|
52
56
|
end
|
53
57
|
|
@@ -61,6 +65,8 @@ describe 'relative_classname_inclusion' do
|
|
61
65
|
contain(foobar)
|
62
66
|
require foobar
|
63
67
|
require(foobar)
|
68
|
+
class foobar inherits baz {
|
69
|
+
}
|
64
70
|
EOS
|
65
71
|
end
|
66
72
|
|
@@ -136,11 +142,14 @@ describe 'relative_classname_inclusion' do
|
|
136
142
|
require('::foobar')
|
137
143
|
require(foobar(baz))
|
138
144
|
require(foobar('baz'))
|
145
|
+
|
146
|
+
class foobar inherits ::baz {
|
147
|
+
}
|
139
148
|
EOS
|
140
149
|
end
|
141
150
|
|
142
|
-
it 'should detect
|
143
|
-
expect(problems).to have(
|
151
|
+
it 'should detect 12 problems' do
|
152
|
+
expect(problems).to have(12).problems
|
144
153
|
end
|
145
154
|
|
146
155
|
it 'should fix the problems' do
|
@@ -155,6 +164,7 @@ describe 'relative_classname_inclusion' do
|
|
155
164
|
expect(problems).to contain_fixed(msg).on_line(15).in_column(17)
|
156
165
|
expect(problems).to contain_fixed(msg).on_line(19).in_column(17)
|
157
166
|
expect(problems).to contain_fixed(msg).on_line(20).in_column(17)
|
167
|
+
expect(problems).to contain_fixed(msg).on_line(24).in_column(31)
|
158
168
|
end
|
159
169
|
|
160
170
|
it 'should should remove colons' do
|
@@ -182,6 +192,9 @@ describe 'relative_classname_inclusion' do
|
|
182
192
|
require('foobar')
|
183
193
|
require(foobar(baz))
|
184
194
|
require(foobar('baz'))
|
195
|
+
|
196
|
+
class foobar inherits baz {
|
197
|
+
}
|
185
198
|
EOS
|
186
199
|
)
|
187
200
|
end
|
@@ -197,6 +210,8 @@ describe 'relative_classname_inclusion' do
|
|
197
210
|
contain(foobar)
|
198
211
|
require foobar
|
199
212
|
require(foobar)
|
213
|
+
class foobar inherits baz {
|
214
|
+
}
|
200
215
|
EOS
|
201
216
|
end
|
202
217
|
|
@@ -0,0 +1,137 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'relative_classname_reference' do
|
4
|
+
let(:msg) { 'absolute class name reference' }
|
5
|
+
|
6
|
+
context 'with fix disabled' do
|
7
|
+
context 'when absolute names are used' do
|
8
|
+
let(:code) do
|
9
|
+
<<-EOS
|
10
|
+
Class[::foo] -> Class['::bar']
|
11
|
+
|
12
|
+
file { '/path':
|
13
|
+
ensure => present,
|
14
|
+
require => Class['::foo', '::bar'],
|
15
|
+
}
|
16
|
+
|
17
|
+
file { '/path':
|
18
|
+
ensure => present,
|
19
|
+
require => [Class[::foo], Class['::bar']],
|
20
|
+
}
|
21
|
+
EOS
|
22
|
+
end
|
23
|
+
|
24
|
+
it 'should detect 6 problems' do
|
25
|
+
expect(problems).to have(6).problems
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'should create warnings' do
|
29
|
+
expect(problems).to contain_warning(msg).on_line(1).in_column(15)
|
30
|
+
expect(problems).to contain_warning(msg).on_line(1).in_column(31)
|
31
|
+
expect(problems).to contain_warning(msg).on_line(5).in_column(28)
|
32
|
+
expect(problems).to contain_warning(msg).on_line(5).in_column(37)
|
33
|
+
expect(problems).to contain_warning(msg).on_line(10).in_column(29)
|
34
|
+
expect(problems).to contain_warning(msg).on_line(10).in_column(43)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'when relative names are used' do
|
39
|
+
let(:code) do
|
40
|
+
<<-EOS
|
41
|
+
Class[foo] -> Class['bar']
|
42
|
+
file { '/path':
|
43
|
+
ensure => present,
|
44
|
+
require => Class['foo', 'bar'],
|
45
|
+
}
|
46
|
+
file { '/path':
|
47
|
+
ensure => present,
|
48
|
+
require => [Class['foo'], Class['bar']],
|
49
|
+
}
|
50
|
+
EOS
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'should not detect a problem' do
|
54
|
+
expect(problems).to have(0).problems
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context 'with fix enabled' do
|
60
|
+
before do
|
61
|
+
PuppetLint.configuration.fix = true
|
62
|
+
end
|
63
|
+
|
64
|
+
after do
|
65
|
+
PuppetLint.configuration.fix = false
|
66
|
+
end
|
67
|
+
|
68
|
+
context 'when absolute names are used' do
|
69
|
+
let(:code) do
|
70
|
+
<<-EOS
|
71
|
+
Class[::foo] -> Class['::bar']
|
72
|
+
|
73
|
+
file { '/path':
|
74
|
+
ensure => present,
|
75
|
+
require => Class['::foo', '::bar'],
|
76
|
+
}
|
77
|
+
|
78
|
+
file { '/path':
|
79
|
+
ensure => present,
|
80
|
+
require => [Class[::foo], Class['::bar']],
|
81
|
+
}
|
82
|
+
EOS
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'should detect 6 problems' do
|
86
|
+
expect(problems).to have(6).problems
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'should fix the problems' do
|
90
|
+
expect(problems).to contain_fixed(msg).on_line(1).in_column(15)
|
91
|
+
expect(problems).to contain_fixed(msg).on_line(1).in_column(31)
|
92
|
+
expect(problems).to contain_fixed(msg).on_line(5).in_column(28)
|
93
|
+
expect(problems).to contain_fixed(msg).on_line(5).in_column(37)
|
94
|
+
expect(problems).to contain_fixed(msg).on_line(10).in_column(29)
|
95
|
+
expect(problems).to contain_fixed(msg).on_line(10).in_column(43)
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'should should remove colons' do
|
99
|
+
expect(manifest).to eq(
|
100
|
+
<<-EOS
|
101
|
+
Class[foo] -> Class['bar']
|
102
|
+
|
103
|
+
file { '/path':
|
104
|
+
ensure => present,
|
105
|
+
require => Class['foo', 'bar'],
|
106
|
+
}
|
107
|
+
|
108
|
+
file { '/path':
|
109
|
+
ensure => present,
|
110
|
+
require => [Class[foo], Class['bar']],
|
111
|
+
}
|
112
|
+
EOS
|
113
|
+
)
|
114
|
+
end
|
115
|
+
end
|
116
|
+
|
117
|
+
context 'when relative names are used' do
|
118
|
+
let(:code) do
|
119
|
+
<<-EOS
|
120
|
+
Class[foo] -> Class['bar']
|
121
|
+
file { '/path':
|
122
|
+
ensure => present,
|
123
|
+
require => Class['foo', 'bar'],
|
124
|
+
}
|
125
|
+
file { '/path':
|
126
|
+
ensure => present,
|
127
|
+
require => [Class[foo], Class['bar']],
|
128
|
+
}
|
129
|
+
EOS
|
130
|
+
end
|
131
|
+
|
132
|
+
it 'should not detect any problems' do
|
133
|
+
expect(problems).to have(0).problems
|
134
|
+
end
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puppet-lint-absolute_classname-check
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.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: 2020-10-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: puppet-lint
|
@@ -100,8 +100,8 @@ dependencies:
|
|
100
100
|
- - ">="
|
101
101
|
- !ruby/object:Gem::Version
|
102
102
|
version: '0'
|
103
|
-
description: " A puppet-lint plugin to check that classes are included
|
104
|
-
absolute name.\n"
|
103
|
+
description: " A puppet-lint plugin to check that classes are not included or referenced
|
104
|
+
by their absolute name.\n"
|
105
105
|
email: voxpupuli@groups.io
|
106
106
|
executables: []
|
107
107
|
extensions: []
|
@@ -110,7 +110,9 @@ files:
|
|
110
110
|
- LICENSE
|
111
111
|
- README.md
|
112
112
|
- lib/puppet-lint/plugins/check_absolute_classname.rb
|
113
|
+
- lib/puppet-lint/plugins/check_classname_reference.rb
|
113
114
|
- spec/puppet-lint/plugins/check_absolute_classname/relative_classname_inclusion_spec.rb
|
115
|
+
- spec/puppet-lint/plugins/check_classname_reference/relative_classname_reference_spec.rb
|
114
116
|
- spec/spec_helper.rb
|
115
117
|
homepage: https://github.com/voxpupuli/puppet-lint-absolute_classname-check
|
116
118
|
licenses:
|
@@ -131,12 +133,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
131
133
|
- !ruby/object:Gem::Version
|
132
134
|
version: '0'
|
133
135
|
requirements: []
|
134
|
-
|
135
|
-
rubygems_version: 2.7.7
|
136
|
+
rubygems_version: 3.0.8
|
136
137
|
signing_key:
|
137
138
|
specification_version: 4
|
138
|
-
summary: A puppet-lint plugin to check that classes are included
|
139
|
-
name.
|
139
|
+
summary: A puppet-lint plugin to check that classes are not included or referenced
|
140
|
+
by their absolute name.
|
140
141
|
test_files:
|
141
142
|
- spec/spec_helper.rb
|
143
|
+
- spec/puppet-lint/plugins/check_classname_reference/relative_classname_reference_spec.rb
|
142
144
|
- spec/puppet-lint/plugins/check_absolute_classname/relative_classname_inclusion_spec.rb
|