puppet-lint-module_reference-check 0.1.0 → 0.1.3
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 12922e4a40ec5041a4fdbd2859cbacb179d2ad3242a6c536a0396e14eeb21f53
|
4
|
+
data.tar.gz: 11cafcbe2535f7a2275825a53ff3c590e6ebd28c1ae9239775537a139eb6b061
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 558649a232611019dfec62b41f410086855a19d8014e01e42f742d8007b40253a652d913434624d026055fa287d6716cf10344da0ec26756384c2ec43c357ac2
|
7
|
+
data.tar.gz: 55e2eb095791d72415cd9b09ec4b8adcbe0722f8e6679349ed36bfbf1fe2164087a972ec2794565cba91484265f86a2fb74466451f4591c206a7208e062f98b3
|
data/README.md
CHANGED
@@ -20,6 +20,9 @@ This checks whether used modules are properly referenced in the comments by thes
|
|
20
20
|
- internal modules
|
21
21
|
- modules referenced by features
|
22
22
|
|
23
|
+
**Note**: This check can only detect component module usage with the `class` and `include` keywords, but supports
|
24
|
+
reference comments to undetectable components modules as well.
|
25
|
+
|
23
26
|
## Usage
|
24
27
|
|
25
28
|
To use the plugin, add the following line to the Gemfile:
|
@@ -130,7 +130,7 @@ PuppetLint.new_check(:module_reference) do
|
|
130
130
|
return return_object if captures['name'].match?(%r(https?://))
|
131
131
|
|
132
132
|
reference = @workflow.references.select { |ref| ref[:name] == captures['name'] }
|
133
|
-
return
|
133
|
+
return return_object if reference.empty?
|
134
134
|
|
135
135
|
return_object[:type] = reference.first[:type]
|
136
136
|
else
|
@@ -146,6 +146,9 @@ PuppetLint.new_check(:module_reference) do
|
|
146
146
|
break
|
147
147
|
end
|
148
148
|
end
|
149
|
+
comments[index + 1]&.match(/^@note (?<name>.+)$/) do |matchdata|
|
150
|
+
return_object[:name] = matchdata['name']
|
151
|
+
end
|
149
152
|
end
|
150
153
|
return_object
|
151
154
|
end
|
@@ -53,7 +53,7 @@ class Reference
|
|
53
53
|
feature_includes = []
|
54
54
|
tokens.reject { |token| %i[WHITESPACE NEWLINE INDENT].include? token.type }.each do |token|
|
55
55
|
@current_token = token
|
56
|
-
@workflow.got_include if token.value == 'include'
|
56
|
+
@workflow.got_include if token.type == :NAME && token.value == 'include' && token.next_code_token&.type == :NAME
|
57
57
|
@workflow.got_class if token.value == 'class'
|
58
58
|
@workflow.got_features_start if token.value == 'role::include_features'
|
59
59
|
@workflow.got_feature if token.type == :LBRACK && @workflow.current == :awaiting_feature
|
@@ -34,6 +34,67 @@ describe 'module_reference' do
|
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
|
+
context 'valid code with reference to unused module' do
|
38
|
+
let(:code) do
|
39
|
+
<<~CODE
|
40
|
+
# @ref apache
|
41
|
+
# @note puppetlabs-apache
|
42
|
+
# @see https://forge.puppet.com/modules/puppetlabs/apache
|
43
|
+
#
|
44
|
+
# @see profile::test
|
45
|
+
#
|
46
|
+
# @see profile::testfeature - Feature "test"
|
47
|
+
class test () {
|
48
|
+
include profile::test
|
49
|
+
class {
|
50
|
+
'apache':
|
51
|
+
}
|
52
|
+
include apache
|
53
|
+
}
|
54
|
+
CODE
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'should detect detect any problems' do
|
58
|
+
expect(problems).to have(0).problems
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
context 'valid code with correctly sorted reference to undetectable component module' do
|
63
|
+
let(:code) do
|
64
|
+
<<~CODE
|
65
|
+
# @ref foo
|
66
|
+
# @note undetected-a
|
67
|
+
# @see https://forge.puppet.com/modules/undetected/a
|
68
|
+
# @ref bar
|
69
|
+
# @note undetected-b
|
70
|
+
# @see https://forge.puppet.com/modules/undetected/b
|
71
|
+
class test () {
|
72
|
+
}
|
73
|
+
CODE
|
74
|
+
end
|
75
|
+
|
76
|
+
it 'should detect detect any problems' do
|
77
|
+
expect(problems).to have(0).problems
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
context 'valid code with using include in a different context' do
|
82
|
+
let(:code) do
|
83
|
+
<<~CODE
|
84
|
+
class test () {
|
85
|
+
$a = {
|
86
|
+
include => 'something'
|
87
|
+
}
|
88
|
+
$a.reduce({})
|
89
|
+
}
|
90
|
+
CODE
|
91
|
+
end
|
92
|
+
|
93
|
+
it 'should detect detect any problems' do
|
94
|
+
expect(problems).to have(0).problems
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
37
98
|
context 'code with missing internal link' do
|
38
99
|
let(:code) do
|
39
100
|
<<~CODE
|
@@ -165,35 +226,6 @@ describe 'module_reference' do
|
|
165
226
|
end
|
166
227
|
end
|
167
228
|
|
168
|
-
context 'code with reference to unused module' do
|
169
|
-
let(:code) do
|
170
|
-
<<~CODE
|
171
|
-
# @ref apache
|
172
|
-
# @note puppetlabs-apache
|
173
|
-
# @see https://forge.puppet.com/modules/puppetlabs/apache
|
174
|
-
#
|
175
|
-
# @see profile::test
|
176
|
-
#
|
177
|
-
# @see profile::testfeature - Feature "test"
|
178
|
-
class test () {
|
179
|
-
include profile::test
|
180
|
-
class {
|
181
|
-
'apache':
|
182
|
-
}
|
183
|
-
include apache
|
184
|
-
}
|
185
|
-
CODE
|
186
|
-
end
|
187
|
-
|
188
|
-
it 'should detect exactly one problem' do
|
189
|
-
expect(problems).to have(1).problems
|
190
|
-
end
|
191
|
-
|
192
|
-
it 'should create a warning' do
|
193
|
-
expect(problems).to contain_warning('Can\'t find referenced module profile::testfeature').on_line(1).in_column(1)
|
194
|
-
end
|
195
|
-
end
|
196
|
-
|
197
229
|
context 'code with unsorted component references' do
|
198
230
|
let(:code) do
|
199
231
|
<<~CODE
|