puppet-lint-global_definition-check 0.4.2 → 0.5.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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: edfa4379a68cd98b941f2156587b388d2de7300e05355d012e3d98390195a2e8
|
4
|
+
data.tar.gz: 36b7d81094a0fea0762cc435de4b445e9917f051fae7cebc826d1f46dba4b0f6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d5690c151f070e3b408149b24786b776a7b6d2162e97fedcba2b8f50b9084cda8928cea7cb6c397ea16afb20dce278b0c4a226dd3d5a2ff539487a3dbb64ef9
|
7
|
+
data.tar.gz: 719e6c2dab89070dbce14cf0acc03549f6004302af15e412a8baf0d6328e0e25f9821657c419299160d6be6c87508de882658c0113467988cced6aad5c26dc94
|
@@ -9,26 +9,70 @@ module PuppetLintGlobalDefinionCheck
|
|
9
9
|
next unless message
|
10
10
|
|
11
11
|
notify :error,
|
12
|
-
message: "
|
12
|
+
message: "#{message} in global space",
|
13
13
|
line: token.line,
|
14
14
|
column: token.column
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
18
|
def global_tokens
|
19
|
-
@global_tokens ||= tokens.reject.with_index { |_, i|
|
19
|
+
@global_tokens ||= tokens.reject.with_index { |_, i| safe_ranges.any? { |s| s[0] < i && s[1] > i } }
|
20
20
|
end
|
21
21
|
|
22
|
-
def
|
23
|
-
|
22
|
+
def custom_functions_indexes
|
23
|
+
# Code adapted from https://github.com/puppetlabs/puppet-lint/blob/dcff4a1b8d3bf5c15762db826967dd03200626be/lib/puppet-lint/data.rb#L298
|
24
|
+
type = :FUNCTION
|
25
|
+
result = []
|
26
|
+
tokens.each_with_index do |token, i|
|
27
|
+
next unless token.type == type
|
28
|
+
|
29
|
+
brace_depth = 0
|
30
|
+
paren_depth = 0
|
31
|
+
in_params = false
|
32
|
+
return_type = nil
|
33
|
+
tokens[i + 1..-1].each_with_index do |definition_token, j|
|
34
|
+
case definition_token.type
|
35
|
+
when :LPAREN
|
36
|
+
in_params = true if paren_depth.zero? && brace_depth.zero?
|
37
|
+
paren_depth += 1
|
38
|
+
when :RPAREN
|
39
|
+
in_params = false if paren_depth == 1 && brace_depth.zero?
|
40
|
+
paren_depth -= 1
|
41
|
+
when :RSHIFT
|
42
|
+
return_type = definition_token.next_code_token unless definition_token.next_code_token.nil? || definition_token.next_code_token.type != :TYPE
|
43
|
+
when :LBRACE
|
44
|
+
brace_depth += 1
|
45
|
+
when :RBRACE
|
46
|
+
brace_depth -= 1
|
47
|
+
if brace_depth.zero? && !in_params && (token.next_code_token.type != :LBRACE)
|
48
|
+
result << {
|
49
|
+
start: i,
|
50
|
+
end: i + j + 1,
|
51
|
+
tokens: tokens[i..(i + j + 1)],
|
52
|
+
param_tokens: PuppetLint::Data.param_tokens(tokens[i..(i + j + 1)]),
|
53
|
+
type: type,
|
54
|
+
name_token: token.next_code_token,
|
55
|
+
return_type: return_type
|
56
|
+
}
|
57
|
+
break
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
result
|
63
|
+
end
|
64
|
+
|
65
|
+
def safe_ranges
|
66
|
+
return @safe_ranges if @safe_ranges
|
24
67
|
|
25
|
-
@
|
68
|
+
@safe_ranges = []
|
26
69
|
|
27
|
-
class_indexes.each { |c| @
|
28
|
-
defined_type_indexes.each { |d| @
|
29
|
-
node_indexes.each { |n| @
|
70
|
+
class_indexes.each { |c| @safe_ranges << [c[:start], c[:end]] }
|
71
|
+
defined_type_indexes.each { |d| @safe_ranges << [d[:start], d[:end]] }
|
72
|
+
node_indexes.each { |n| @safe_ranges << [n[:start], n[:end]] }
|
73
|
+
custom_functions_indexes.each { |cf| @safe_ranges << [cf[:start], cf[:end]] }
|
30
74
|
|
31
|
-
@
|
75
|
+
@safe_ranges
|
32
76
|
end
|
33
77
|
end
|
34
78
|
|
@@ -44,7 +88,7 @@ PuppetLint.new_check(:global_resource) do
|
|
44
88
|
|
45
89
|
def check_for_global_resources
|
46
90
|
resource_indexes.each do |r|
|
47
|
-
next if
|
91
|
+
next if safe_ranges.any? { |s| s[0] < r[:start] && s[1] > r[:end] }
|
48
92
|
|
49
93
|
notify :error,
|
50
94
|
message: "resource #{r[:type].value} in global space",
|
@@ -59,7 +103,7 @@ PuppetLint.new_check(:global_function) do
|
|
59
103
|
|
60
104
|
def check
|
61
105
|
check_for_global_token(:FUNCTION_NAME) do |token|
|
62
|
-
|
106
|
+
"function call #{token.value}(...)"
|
63
107
|
end
|
64
108
|
end
|
65
109
|
end
|
@@ -11,7 +11,7 @@ describe "global_function" do
|
|
11
11
|
end
|
12
12
|
|
13
13
|
it "should not detect any problems" do
|
14
|
-
expect(problems).to
|
14
|
+
expect(problems.size).to eq(0)
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
@@ -27,29 +27,21 @@ describe "global_function" do
|
|
27
27
|
end
|
28
28
|
|
29
29
|
it "should detect a problem" do
|
30
|
-
expect(problems).to
|
30
|
+
expect(problems.size).to eq(1)
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
context "
|
34
|
+
context "custom function definition with function call" do
|
35
35
|
let(:code) do
|
36
36
|
<<-EOS
|
37
|
-
|
38
|
-
|
39
|
-
Hash $hash,
|
40
|
-
) >> Hash {
|
41
|
-
$hash.filter |$key, $value| {
|
42
|
-
case $value {
|
43
|
-
Collection: { $value =~ NotUndef and !$value.empty }
|
44
|
-
default: { $value =~ NotUndef }
|
45
|
-
}
|
46
|
-
}
|
37
|
+
function test_module::test_function() >> Any {
|
38
|
+
function_call()
|
47
39
|
}
|
48
40
|
EOS
|
49
41
|
end
|
50
42
|
|
51
43
|
it "should not detect any problems" do
|
52
|
-
expect(problems).to
|
44
|
+
expect(problems.size).to eq(0)
|
53
45
|
end
|
54
46
|
end
|
55
47
|
end
|
@@ -5,7 +5,7 @@ describe "global_resource" do
|
|
5
5
|
let(:code) { "class test { file { 'file': } }" }
|
6
6
|
|
7
7
|
it "should not detect any problems" do
|
8
|
-
expect(problems).to
|
8
|
+
expect(problems.size).to eq(0)
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
@@ -13,7 +13,7 @@ describe "global_resource" do
|
|
13
13
|
let(:code) { "define test ($param = undef) { file { 'file': } }" }
|
14
14
|
|
15
15
|
it "should not detect any problems" do
|
16
|
-
expect(problems).to
|
16
|
+
expect(problems.size).to eq(0)
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
@@ -21,7 +21,7 @@ describe "global_resource" do
|
|
21
21
|
let(:code) { "node 'test' { file { 'file': } }" }
|
22
22
|
|
23
23
|
it "should not detect any problems" do
|
24
|
-
expect(problems).to
|
24
|
+
expect(problems.size).to eq(0)
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
@@ -31,7 +31,7 @@ describe "global_resource" do
|
|
31
31
|
end
|
32
32
|
|
33
33
|
it "should detect a problem" do
|
34
|
-
expect(problems).to
|
34
|
+
expect(problems.size).to eq(1)
|
35
35
|
end
|
36
36
|
end
|
37
37
|
|
@@ -39,7 +39,7 @@ describe "global_resource" do
|
|
39
39
|
let(:code) { "class test { file { 'file': } } \ninclude testclass" }
|
40
40
|
|
41
41
|
it "should detect a problem" do
|
42
|
-
expect(problems).to
|
42
|
+
expect(problems.size).to eq(1)
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
@@ -53,7 +53,7 @@ describe "global_resource" do
|
|
53
53
|
end
|
54
54
|
|
55
55
|
it "should not detect any problems" do
|
56
|
-
expect(problems).to
|
56
|
+
expect(problems.size).to eq(0)
|
57
57
|
end
|
58
58
|
end
|
59
59
|
end
|
metadata
CHANGED
@@ -1,29 +1,35 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puppet-lint-global_definition-check
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nine Internet Solutions AG
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-10-
|
11
|
+
date: 2023-10-23 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
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.2'
|
20
|
+
- - "<"
|
18
21
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
22
|
+
version: '5'
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
|
-
- - "
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '2.2'
|
30
|
+
- - "<"
|
25
31
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
32
|
+
version: '5'
|
27
33
|
- !ruby/object:Gem::Dependency
|
28
34
|
name: rspec
|
29
35
|
requirement: !ruby/object:Gem::Requirement
|