puppet-lint-wmf_styleguide-check 1.0.4 → 1.0.5

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: 841557991f772264b442e532575961497bd111672ae7b189429039dd238f7c87
4
- data.tar.gz: bda8b8d669e285f045f4f5074c111d4c507ebf4b1e4c125cbb5b61c789c055ac
3
+ metadata.gz: e71f6f797e858faf231fa273cb2aba57df48623a6e57cbd6089b030f1df2b49e
4
+ data.tar.gz: c206e2c526caadff5946d59bc772dd1ac3180587b4a79cdf9a2ba8ac87cb1cbf
5
5
  SHA512:
6
- metadata.gz: 0b1d6a0c2718108fb86a2275789643ce26fa757cb7cd009d258f1bc23cc7d05bd7c0383a97c105149c3528b3b6f15ecbff35853ad9b04622d5f811b96fb5cc6e
7
- data.tar.gz: 414bd06e086fce65860ec383886c954b7eb3e16b9ff2c4fbdce4ef431e855e4ced465ef127eda8dc113cd432085e6125fbb2b0a543b8c47d81b919f11292b683
6
+ metadata.gz: f79402564c3e8b07dfabbb434e0ffe781a97c366e52b8fe9e72c58e2a3da40dd1a5bb17ccf6b134897362f968a8dc105b825273575ffc6eb27a419a8fd9510c0
7
+ data.tar.gz: a2bd4bc48788639d2c8ec7795c39697a01e97510adf24b8a13050ece8672982d20f70b8efa6aa0188f61987c508804e8d4617cbe9718796c9ed10a10e7c611eb
@@ -145,9 +145,14 @@ class PuppetLint
145
145
  function? && ['hiera', 'hiera_array', 'hiera_hash', 'lookup'].include?(@value)
146
146
  end
147
147
 
148
+ def lookup?
149
+ # A function call specifically calling lookup
150
+ function? && ['lookup'].include?(@value)
151
+ end
152
+
148
153
  def class_include?
149
- # Object is either "include" or "require", and the next token is not a =>
150
- @type == :NAME && ['include', 'require'].include?(@value) && @next_code_token.type != :FARROW
154
+ # Check for include-like objects
155
+ @type == :NAME && ['include', 'require', 'contain'].include?(@value) && @next_code_token.type != :FARROW
151
156
  end
152
157
 
153
158
  def included_class
@@ -184,7 +189,7 @@ end
184
189
  # Checks and functions
185
190
  def check_profile(klass)
186
191
  # All parameters of profiles should have a default value that is a hiera lookup
187
- params_without_hiera_defaults klass
192
+ params_without_lookup_defaults klass
188
193
  # All hiera lookups should be in parameters
189
194
  hiera_not_in_params klass
190
195
  # Only a few selected classes should be included in a profile
@@ -228,16 +233,18 @@ def hiera(klass)
228
233
  hiera_errors(klass.hiera_calls, klass)
229
234
  end
230
235
 
231
- def params_without_hiera_defaults(klass)
236
+ def params_without_lookup_defaults(klass)
232
237
  # Finds parameters that have no hiera-defined default value.
233
238
  klass.params.each do |name, data|
234
- next unless data[:value].select(&:hiera?).empty?
239
+ next unless data[:value].select(&:lookup?).empty?
240
+ common = "wmf-style: Parameter '#{name}' of class '#{klass.name}'"
241
+ message = if data[:value].select(&:hiera?).empty?
242
+ "#{common} has no call to lookup"
243
+ else
244
+ "#{common}: hiera is deprecated use lookup"
245
+ end
235
246
  token = data[:param]
236
- msg = {
237
- message: "wmf-style: Parameter '#{name}' of class '#{klass.name}' has no call to hiera",
238
- line: token.line,
239
- column: token.column
240
- }
247
+ msg = { message: message, line: token.line, column: token.column }
241
248
  notify :error, msg
242
249
  end
243
250
  end
@@ -304,8 +311,8 @@ def class_illegal_include(klass)
304
311
  end
305
312
 
306
313
  def include_not_profile(klass)
307
- # Checks that a role only includes other roles, profiles and/or the special class "standard"
308
- modules_include_ok = ['role', 'profile', 'standard']
314
+ # Checks that a role only includes other roles and profiles
315
+ modules_include_ok = ['role', 'profile']
309
316
  klass.included_classes.each do |token|
310
317
  class_name = token.value.gsub(/^::/, '')
311
318
  module_name = class_name.split('::')[0]
@@ -24,8 +24,7 @@ EOF
24
24
 
25
25
  profile_ok = <<-EOF
26
26
  class profile::foobar (
27
- $test=hiera('profile::foobar::test'),
28
- $foo=hiera_array('profile::foobar::foo')
27
+ $test=lookup('profile::foobar::test'),
29
28
  ) {
30
29
  require ::profile::foo
31
30
  include ::passwords::redis
@@ -35,7 +34,10 @@ EOF
35
34
 
36
35
  profile_ko = <<-EOF
37
36
  class profile::fixme (
38
- $test,
37
+ $test1,
38
+ $test2=hiera('profile::foobar::foo')
39
+ $test3=hiera_array('profile::foobar::foo')
40
+ $test4=hiera_hash('profile::foobar::foo')
39
41
  ) {
40
42
  include ::apache2::common
41
43
  $role = hiera('role')
@@ -45,7 +47,6 @@ EOF
45
47
 
46
48
  role_ok = <<-EOF
47
49
  class role::fizzbuz {
48
- include standard
49
50
  include ::profile::base
50
51
  include ::profile::bar
51
52
  system::role { 'fizzbuzz': }
@@ -135,16 +136,19 @@ describe 'wmf_styleguide' do
135
136
  context 'profile with errors' do
136
137
  let(:code) { profile_ko }
137
138
  it 'should create errors for parameters without hiera defaults' do
138
- expect(problems).to contain_error("wmf-style: Parameter 'test' of class 'profile::fixme' has no call to hiera").on_line(2).in_column(7)
139
+ expect(problems).to contain_error("wmf-style: Parameter 'test1' of class 'profile::fixme' has no call to lookup").on_line(2).in_column(7)
140
+ expect(problems).to contain_error("wmf-style: Parameter 'test2' of class 'profile::fixme': hiera is deprecated use lookup").on_line(3).in_column(7)
141
+ expect(problems).to contain_error("wmf-style: Parameter 'test3' of class 'profile::fixme': hiera is deprecated use lookup").on_line(4).in_column(7)
142
+ expect(problems).to contain_error("wmf-style: Parameter 'test4' of class 'profile::fixme': hiera is deprecated use lookup").on_line(5).in_column(7)
139
143
  end
140
144
  it 'should create errors for hiera calls in body' do
141
- expect(problems).to contain_error("wmf-style: Found hiera call in class 'profile::fixme' for 'role'").on_line(5).in_column(13)
145
+ expect(problems).to contain_error("wmf-style: Found hiera call in class 'profile::fixme' for 'role'").on_line(8).in_column(13)
142
146
  end
143
147
  it 'should create errors for use of system::role' do
144
- expect(problems).to contain_error("wmf-style: class 'profile::fixme' declares system::role, which should only be used in roles").on_line(6).in_column(5)
148
+ expect(problems).to contain_error("wmf-style: class 'profile::fixme' declares system::role, which should only be used in roles").on_line(9).in_column(5)
145
149
  end
146
150
  it 'should create errors for non-explicit class inclusion' do
147
- expect(problems).to contain_error("wmf-style: profile 'profile::fixme' includes non-profile class apache2::common").on_line(4).in_column(13)
151
+ expect(problems).to contain_error("wmf-style: profile 'profile::fixme' includes non-profile class apache2::common").on_line(7).in_column(13)
148
152
  end
149
153
  end
150
154
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppet-lint-wmf_styleguide-check
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Giuseppe Lavagetto
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-09 00:00:00.000000000 Z
11
+ date: 2020-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: puppet-lint
@@ -16,20 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '2.3'
20
- - - ">="
21
- - !ruby/object:Gem::Version
22
- version: 2.3.0
19
+ version: '2.0'
23
20
  type: :runtime
24
21
  prerelease: false
25
22
  version_requirements: !ruby/object:Gem::Requirement
26
23
  requirements:
27
24
  - - "~>"
28
25
  - !ruby/object:Gem::Version
29
- version: '2.3'
30
- - - ">="
31
- - !ruby/object:Gem::Version
32
- version: 2.3.0
26
+ version: '2.0'
33
27
  - !ruby/object:Gem::Dependency
34
28
  name: git
35
29
  requirement: !ruby/object:Gem::Requirement
@@ -155,7 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
155
149
  version: '0'
156
150
  requirements: []
157
151
  rubyforge_project:
158
- rubygems_version: 2.7.6
152
+ rubygems_version: 2.7.6.2
159
153
  signing_key:
160
154
  specification_version: 4
161
155
  summary: A puppet-lint plugin to check code adheres to the WMF coding guidelines