puppet-lint-hiera 0.0.1 → 0.0.2

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: ca0a683393755155dc9b77047a86910ae4e249731bafcf4373e32cb34078cec9
4
- data.tar.gz: cdd44ed624b0d996e5ce045be413fd5ca1e94511b8ff8fdcd8d26fef60e56644
3
+ metadata.gz: 9b99396c72c814e8d1ba03e82198c36be022d8491c2d912c7cda8ca52a10b0e2
4
+ data.tar.gz: cd2fe399a7f41994e7e2d9d625952dcb92b159788f3ea673799d7b63184d824d
5
5
  SHA512:
6
- metadata.gz: 9609186ce6b65883b2912a8e20e2c7fc7ef65fe9b7c882d3d0977acda1767c0fa51619315bb67222ccb72ed4526b23ab5a2e93f88c68e15af16c914804ded34b
7
- data.tar.gz: ffb90799218ec423b58cc842219197db5510182e352b92c02f99e90959dae0de5be685753fc34e90d0d1c30f81a885fc9418bfe786857fde244e07b2be1ea62a
6
+ metadata.gz: 2f1cb7fdd099b858c8044953e33160050db25223440303814dfdf2528b857e1418689dc0dc586c694d261b556a394b860c3d3e0d7ac11a7fcf11799daa56451a
7
+ data.tar.gz: 652fe5bf8b8626d987796a8c9490754b0b6c7dd8b7377fb10448251ef979aab1d2bd9642669deec50fb5545fbcedadf734b26dd0eed5bc47271c25e06881240c
data/README.md CHANGED
@@ -10,7 +10,6 @@ To add the provided lint checks into a module utilizing the PDK:
10
10
  optional:
11
11
  ':development':
12
12
  - gem: 'puppet-lint-hiera'
13
- git: 'git@github.com:garrettrowell/puppet-lint-hiera.git'
14
13
  ```
15
14
  2. Run `pdk update` from the root of the module
16
15
  3. `pdk validate` will now also use the lint checks provided by this plugin
@@ -26,12 +25,26 @@ This check raises an error if the `hiera()` function is used.
26
25
  error: hiera() function call. Use lookup() instead.
27
26
  ```
28
27
 
29
- ### **lookup**
28
+ ### **lookup_in_class**
30
29
  `--fix` support: No
31
30
 
32
- This check raises an error if the `lookup()` function is used outside of profile parameters.
31
+ This check raises an error if the `lookup()` function is used within a class body.
33
32
  ```
34
- error: lookup() function call found in profile class. Only use in profile params.
35
- error: lookup() function call found in class params.
36
33
  error: lookup() function call found in class.
37
34
  ```
35
+
36
+ ### **lookup_in_class_params**
37
+ `--fix` support: No
38
+
39
+ This check raises an error if the `lookup()` function is used inside a classes parameters.
40
+ ```
41
+ error: lookup() function call found in class params.
42
+ ```
43
+
44
+ ### **lookup_in_profile_class**
45
+ `--fix` support: No
46
+
47
+ This check raises an error if the `lookup()` function is used within a profile body.
48
+ ```
49
+ error: lookup() function call found in profile class. Only use in profile params.
50
+ ```
@@ -1,9 +1,9 @@
1
- PuppetLint.new_check(:lookup) do
1
+ PuppetLint.new_check(:lookup_in_class) do
2
2
  def check
3
3
  functions = ['lookup']
4
4
 
5
- lookups_in_parameters = Array.new
6
- parent_class = String.new
5
+ lookups_in_parameters = []
6
+ parent_class = ''
7
7
  class_indexes.each do |class_idx|
8
8
  parent_class = class_idx[:name_token]
9
9
  # return early if no params
@@ -20,22 +20,14 @@ PuppetLint.new_check(:lookup) do
20
20
  is_profile = parent_class_name.match(/^profile::.*/)
21
21
  in_params = lookups_in_parameters.include? function_token
22
22
  next unless function_token.next_code_token.type == :LPAREN
23
- next if in_params && is_profile
23
+ next if is_profile
24
+ next if in_params
24
25
 
25
26
  key_token = function_token.next_code_token.next_code_token
26
- lookup_key_token = function_token.prev_code_token.prev_code_token
27
27
 
28
- error_message = "#{function_token.value}() function call found in"
29
- if in_params && !is_profile
30
- error_message = error_message + " class params."
31
- elsif is_profile && !in_params
32
- error_message = error_message + " profile class. Only use in profile params."
33
- else
34
- error_message = error_message + " class."
35
- end
28
+ error_message = "#{function_token.value}() function call found in class."
36
29
 
37
30
  notify :error, {
38
- # message: "#{function_token.value}() function call found in class. Only use in class params.",
39
31
  message: error_message,
40
32
  line: key_token.line,
41
33
  column: key_token.column,
@@ -0,0 +1,37 @@
1
+ PuppetLint.new_check(:lookup_in_class_params) do
2
+ def check
3
+ functions = ['lookup']
4
+
5
+ lookups_in_parameters = []
6
+ parent_class = ''
7
+ class_indexes.each do |class_idx|
8
+ parent_class = class_idx[:name_token]
9
+ # return early if no params
10
+ next if class_idx[:param_tokens].nil?
11
+
12
+ # iterate over each parameter token
13
+ class_idx[:param_tokens].each do |p_token|
14
+ lookups_in_parameters << p_token if ((p_token.type == :NAME or p_token.type == :FUNCTION_NAME) and functions.include? p_token.value)
15
+ end
16
+ end
17
+
18
+ tokens.select { |t| (t.type == :NAME or t.type == :FUNCTION_NAME) and functions.include? t.value }.each do |function_token|
19
+ parent_class_name = parent_class.value
20
+ is_profile = parent_class_name.match(/^profile::.*/)
21
+ in_params = lookups_in_parameters.include? function_token
22
+ next unless function_token.next_code_token.type == :LPAREN
23
+ next if is_profile
24
+ next unless in_params
25
+
26
+ key_token = function_token.next_code_token.next_code_token
27
+
28
+ error_message = "#{function_token.value}() function call found in class params."
29
+
30
+ notify :error, {
31
+ message: error_message,
32
+ line: key_token.line,
33
+ column: key_token.column,
34
+ }
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,37 @@
1
+ PuppetLint.new_check(:lookup_in_profile_class) do
2
+ def check
3
+ functions = ['lookup']
4
+
5
+ lookups_in_parameters = []
6
+ parent_class = ''
7
+ class_indexes.each do |class_idx|
8
+ parent_class = class_idx[:name_token]
9
+ # return early if no params
10
+ next if class_idx[:param_tokens].nil?
11
+
12
+ # iterate over each parameter token
13
+ class_idx[:param_tokens].each do |p_token|
14
+ lookups_in_parameters << p_token if ((p_token.type == :NAME or p_token.type == :FUNCTION_NAME) and functions.include? p_token.value)
15
+ end
16
+ end
17
+
18
+ tokens.select { |t| (t.type == :NAME or t.type == :FUNCTION_NAME) and functions.include? t.value }.each do |function_token|
19
+ parent_class_name = parent_class.value
20
+ is_profile = parent_class_name.match(/^profile::.*/)
21
+ in_params = lookups_in_parameters.include? function_token
22
+ next unless function_token.next_code_token.type == :LPAREN
23
+ next if is_profile && in_params
24
+ next unless is_profile
25
+
26
+ key_token = function_token.next_code_token.next_code_token
27
+
28
+ error_message = "#{function_token.value}() function call found in profile class. Only use in profile params."
29
+
30
+ notify :error, {
31
+ message: error_message,
32
+ line: key_token.line,
33
+ column: key_token.column,
34
+ }
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,98 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'lookup_in_class_params' do
4
+ context 'class with no lookup calls' do
5
+ let(:code) do
6
+ <<-EOS
7
+ class no_lookup_calls {
8
+ file { '/tmp/foo':
9
+ content => 'bar',
10
+ }
11
+ }
12
+ EOS
13
+ end
14
+
15
+ it 'should not detect any problems' do
16
+ expect(problems).to have(0).problems
17
+ end
18
+ end
19
+
20
+ context 'profile with a lookup call in params' do
21
+ let(:code) do
22
+ <<-EOS
23
+ class profile::lookup_call_params (
24
+ $content = lookup('some_key')
25
+ ) {
26
+ file { '/tmp/foo':
27
+ content => $content,
28
+ }
29
+ }
30
+ EOS
31
+ end
32
+
33
+ it 'should not detect any problems' do
34
+ expect(problems).to have(0).problems
35
+ end
36
+ end
37
+
38
+ context 'class with a lookup call in class' do
39
+ let(:msg) { 'lookup() function call found in class.' }
40
+
41
+ let(:code) do
42
+ <<-EOS
43
+ class lookup_call_class {
44
+ file { '/tmp/foo':
45
+ content => lookup('some_key'),
46
+ }
47
+ }
48
+ EOS
49
+ end
50
+
51
+ it 'should not detect any problems' do
52
+ expect(problems).to have(0).problem
53
+ end
54
+ end
55
+
56
+ context 'profile with a lookup call in class' do
57
+ let(:msg) { 'lookup() function call found in profile class. Only use in profile params.' }
58
+
59
+ let(:code) do
60
+ <<-EOS
61
+ class profile::lookup_call_class {
62
+ file { '/tmp/foo':
63
+ content => lookup('some_key'),
64
+ }
65
+ }
66
+ EOS
67
+ end
68
+
69
+ it 'should not detect any problems' do
70
+ expect(problems).to have(0).problems
71
+ end
72
+ end
73
+
74
+ # and these should cause failiures
75
+ context 'class with a lookup call in params' do
76
+ let(:msg) { 'lookup() function call found in class params.' }
77
+
78
+ let(:code) do
79
+ <<-EOS
80
+ class lookup_call_params (
81
+ $content = lookup('some_key')
82
+ ) {
83
+ file { '/tmp/foo':
84
+ content => $content,
85
+ }
86
+ }
87
+ EOS
88
+ end
89
+
90
+ it 'should detect a single problem' do
91
+ expect(problems).to have(1).problems
92
+ end
93
+
94
+ it 'should create an error' do
95
+ expect(problems).to contain_error(msg).on_line(2).in_column(29)
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,98 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'lookup_in_class' do
4
+ context 'class with no lookup calls' do
5
+ let(:code) do
6
+ <<-EOS
7
+ class no_lookup_calls {
8
+ file { '/tmp/foo':
9
+ content => 'bar',
10
+ }
11
+ }
12
+ EOS
13
+ end
14
+
15
+ it 'should not detect any problems' do
16
+ expect(problems).to have(0).problems
17
+ end
18
+ end
19
+
20
+ context 'profile with a lookup call in params' do
21
+ let(:code) do
22
+ <<-EOS
23
+ class profile::lookup_call_params (
24
+ $content = lookup('some_key')
25
+ ) {
26
+ file { '/tmp/foo':
27
+ content => $content,
28
+ }
29
+ }
30
+ EOS
31
+ end
32
+
33
+ it 'should not detect any problems' do
34
+ expect(problems).to have(0).problems
35
+ end
36
+ end
37
+
38
+ context 'profile with a lookup call in class' do
39
+ let(:msg) { 'lookup() function call found in profile class. Only use in profile params.' }
40
+
41
+ let(:code) do
42
+ <<-EOS
43
+ class profile::lookup_call_class {
44
+ file { '/tmp/foo':
45
+ content => lookup('some_key'),
46
+ }
47
+ }
48
+ EOS
49
+ end
50
+
51
+ it 'should not detect any problems' do
52
+ expect(problems).to have(0).problems
53
+ end
54
+ end
55
+
56
+ context 'class with a lookup call in params' do
57
+ let(:msg) { 'lookup() function call found in class params.' }
58
+
59
+ let(:code) do
60
+ <<-EOS
61
+ class lookup_call_params (
62
+ $content = lookup('some_key')
63
+ ) {
64
+ file { '/tmp/foo':
65
+ content => $content,
66
+ }
67
+ }
68
+ EOS
69
+ end
70
+
71
+ it 'should not detect any problems' do
72
+ expect(problems).to have(0).problems
73
+ end
74
+ end
75
+
76
+ # and these should cause failiures
77
+ context 'class with a lookup call in class' do
78
+ let(:msg) { 'lookup() function call found in class.' }
79
+
80
+ let(:code) do
81
+ <<-EOS
82
+ class lookup_call_class {
83
+ file { '/tmp/foo':
84
+ content => lookup('some_key'),
85
+ }
86
+ }
87
+ EOS
88
+ end
89
+
90
+ it 'should detect a single problem' do
91
+ expect(problems).to have(1).problem
92
+ end
93
+
94
+ it 'should create an error' do
95
+ expect(problems).to contain_error(msg).on_line(3).in_column(31)
96
+ end
97
+ end
98
+ end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe 'lookup' do
3
+ describe 'lookup_in_profile_class' do
4
4
  context 'class with no lookup calls' do
5
5
  let(:code) do
6
6
  <<-EOS
@@ -35,13 +35,12 @@ describe 'lookup' do
35
35
  end
36
36
  end
37
37
 
38
- # and these should cause failiures
39
- context 'profile with a lookup call in class' do
40
- let(:msg) { 'lookup() function call found in profile class. Only use in profile params.' }
38
+ context 'class with a lookup call in class' do
39
+ let(:msg) { 'lookup() function call found in class.' }
41
40
 
42
41
  let(:code) do
43
42
  <<-EOS
44
- class profile::lookup_call_class {
43
+ class lookup_call_class {
45
44
  file { '/tmp/foo':
46
45
  content => lookup('some_key'),
47
46
  }
@@ -49,12 +48,8 @@ describe 'lookup' do
49
48
  EOS
50
49
  end
51
50
 
52
- it 'should detect a single problem' do
53
- expect(problems).to have(1).problems
54
- end
55
-
56
- it 'should create an error' do
57
- expect(problems).to contain_error(msg).on_line(3).in_column(31)
51
+ it 'should not detect any problems' do
52
+ expect(problems).to have(0).problem
58
53
  end
59
54
  end
60
55
 
@@ -73,21 +68,19 @@ describe 'lookup' do
73
68
  EOS
74
69
  end
75
70
 
76
- it 'should detect a single problem' do
77
- expect(problems).to have(1).problems
71
+ it 'should not detect any problems' do
72
+ expect(problems).to have(0).problems
78
73
  end
79
74
 
80
- it 'should create an error' do
81
- expect(problems).to contain_error(msg).on_line(2).in_column(29)
82
- end
83
75
  end
84
76
 
85
- context 'class with a lookup call in class' do
86
- let(:msg) { 'lookup() function call found in class.' }
77
+ # and these should cause failiures
78
+ context 'profile with a lookup call in class' do
79
+ let(:msg) { 'lookup() function call found in profile class. Only use in profile params.' }
87
80
 
88
81
  let(:code) do
89
82
  <<-EOS
90
- class lookup_call_class {
83
+ class profile::lookup_call_class {
91
84
  file { '/tmp/foo':
92
85
  content => lookup('some_key'),
93
86
  }
@@ -96,7 +89,7 @@ describe 'lookup' do
96
89
  end
97
90
 
98
91
  it 'should detect a single problem' do
99
- expect(problems).to have(1).problem
92
+ expect(problems).to have(1).problems
100
93
  end
101
94
 
102
95
  it 'should create an error' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppet-lint-hiera
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Garrett Rowell
@@ -137,9 +137,13 @@ extra_rdoc_files: []
137
137
  files:
138
138
  - LICENSE
139
139
  - README.md
140
- - lib/puppet-lint/plugins/lookup.rb
140
+ - lib/puppet-lint/plugins/lookup_in_class.rb
141
+ - lib/puppet-lint/plugins/lookup_in_class_params.rb
142
+ - lib/puppet-lint/plugins/lookup_in_profile_class.rb
141
143
  - lib/puppet-lint/plugins/no_hiera.rb
142
- - spec/puppet-lint/plugins/lookup_spec.rb
144
+ - spec/puppet-lint/plugins/lookup_in_class_params_spec.rb
145
+ - spec/puppet-lint/plugins/lookup_in_class_spec.rb
146
+ - spec/puppet-lint/plugins/lookup_in_profile_class_spec.rb
143
147
  - spec/puppet-lint/plugins/no_hiera_spec.rb
144
148
  - spec/spec_helper.rb
145
149
  homepage:
@@ -167,5 +171,7 @@ specification_version: 4
167
171
  summary: puppet-lint hiera and lookup function checks
168
172
  test_files:
169
173
  - spec/spec_helper.rb
174
+ - spec/puppet-lint/plugins/lookup_in_class_params_spec.rb
170
175
  - spec/puppet-lint/plugins/no_hiera_spec.rb
171
- - spec/puppet-lint/plugins/lookup_spec.rb
176
+ - spec/puppet-lint/plugins/lookup_in_profile_class_spec.rb
177
+ - spec/puppet-lint/plugins/lookup_in_class_spec.rb