puppet-lint-wmf_styleguide-check 1.0.5 → 1.0.7

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: e71f6f797e858faf231fa273cb2aba57df48623a6e57cbd6089b030f1df2b49e
4
- data.tar.gz: c206e2c526caadff5946d59bc772dd1ac3180587b4a79cdf9a2ba8ac87cb1cbf
3
+ metadata.gz: 02e709fa4e38aa92929077506d5cacdb8e3f17114bb75596224444f385f18aab
4
+ data.tar.gz: a392eead1036bdd3d1bcfd0546291d9c5f154b7a7b3797a30d0a8b7e70efa340
5
5
  SHA512:
6
- metadata.gz: f79402564c3e8b07dfabbb434e0ffe781a97c366e52b8fe9e72c58e2a3da40dd1a5bb17ccf6b134897362f968a8dc105b825273575ffc6eb27a419a8fd9510c0
7
- data.tar.gz: a2bd4bc48788639d2c8ec7795c39697a01e97510adf24b8a13050ece8672982d20f70b8efa6aa0188f61987c508804e8d4617cbe9718796c9ed10a10e7c611eb
6
+ metadata.gz: 51814c0df70fe7e80edff7c97bd89e9478a4dbc886ddff1d1bf82a536fa4a6a08759fce975826cc1d2fca0b100e3e66378f60ce07fb320cbc7536f6413b1dc8d
7
+ data.tar.gz: 18ad1c6221aca98d187ee93898d5aad4e820769a007e77332625bdbbb6418d47816b7002b89035e94f5b26daf3484f340b9f35b76ca6e443f378a6730c128b38
@@ -107,6 +107,11 @@ class PuppetResource
107
107
  @resource[:tokens].select(&:hiera?)
108
108
  end
109
109
 
110
+ def legacy_validate_calls
111
+ # Returns an array of all the tokens referencing calls to a stdlib legacy validate function
112
+ @resource[:tokens].select(&:legacy_validate?)
113
+ end
114
+
110
115
  def included_classes
111
116
  # Returns an array of all the classes included (with require/include)
112
117
  @resource[:tokens].map(&:included_class).compact
@@ -150,6 +155,11 @@ class PuppetLint
150
155
  function? && ['lookup'].include?(@value)
151
156
  end
152
157
 
158
+ def legacy_validate?
159
+ # A function calling one of the legacy stdlib validate functions
160
+ function? && @value.start_with?('validate_')
161
+ end
162
+
153
163
  def class_include?
154
164
  # Check for include-like objects
155
165
  @type == :NAME && ['include', 'require', 'contain'].include?(@value) && @next_code_token.type != :FARROW
@@ -274,6 +284,18 @@ def hiera_errors(tokens, klass)
274
284
  end
275
285
  end
276
286
 
287
+ def legacy_validate_errors(klass)
288
+ # Helper for printing errors nicely
289
+ klass.legacy_validate_calls.each do |token|
290
+ msg = {
291
+ message: "wmf-style: Found legacy function (#{token.value}) call in #{klass.type} '#{klass.name}'",
292
+ line: token.line,
293
+ column: token.column
294
+ }
295
+ notify :error, msg
296
+ end
297
+ end
298
+
277
299
  def profile_illegal_include(klass)
278
300
  # Check if a profile includes any class that's not allowed there.
279
301
  # Allowed are: any other profile, or a class from the passwords module,
@@ -379,6 +401,7 @@ end
379
401
 
380
402
  def check_deprecations(resource)
381
403
  # Check the resource for declarations of deprecated defines
404
+ legacy_validate_errors resource
382
405
  deprecated_defines = ['base::service_unit']
383
406
  deprecated_defines.each do |deprecated|
384
407
  resource.resource?(deprecated).each do |token|
@@ -19,6 +19,8 @@ class foo($t=hiera('foo::title')) {
19
19
  notice($t)
20
20
  include ::passwords::redis
21
21
  class { 'bar': }
22
+ validate_foobar($param)
23
+ validate_re($param, '^.*$')
22
24
  }
23
25
  EOF
24
26
 
@@ -74,6 +76,8 @@ define_ko = <<-EOF
74
76
  define foo::fixme ($a=hiera('something')) {
75
77
  include ::foo
76
78
  class { '::bar': }
79
+ validate_foobar($param)
80
+ validate_re($param, '^.*$')
77
81
  }
78
82
  EOF
79
83
 
@@ -131,6 +135,10 @@ describe 'wmf_styleguide' do
131
135
  expect(problems).to contain_error("wmf-style: class 'foo' includes passwords::redis from another module").on_line(5).in_column(16)
132
136
  expect(problems).to contain_error("wmf-style: class 'foo' declares class bar from another module").on_line(6).in_column(16)
133
137
  end
138
+ it 'should create errors for validate_function' do
139
+ expect(problems).to contain_error("wmf-style: Found legacy function (validate_foobar) call in class 'foo'").on_line(7).in_column(8)
140
+ expect(problems).to contain_error("wmf-style: Found legacy function (validate_re) call in class 'foo'").on_line(8).in_column(8)
141
+ end
134
142
  end
135
143
 
136
144
  context 'profile with errors' do
@@ -172,6 +180,10 @@ describe 'wmf_styleguide' do
172
180
  it 'should not include or define any class' do
173
181
  expect(problems).to contain_error("wmf-style: defined type 'foo::fixme' declares class bar from another module").on_line(3)
174
182
  end
183
+ it 'should create errors for validate_function' do
184
+ expect(problems).to contain_error("wmf-style: Found legacy function (validate_foobar) call in defined type 'foo::fixme'").on_line(4).in_column(8)
185
+ expect(problems).to contain_error("wmf-style: Found legacy function (validate_re) call in defined type 'foo::fixme'").on_line(5).in_column(8)
186
+ end
175
187
  end
176
188
 
177
189
  context 'node with no errors' do
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.5
4
+ version: 1.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Giuseppe Lavagetto
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-16 00:00:00.000000000 Z
11
+ date: 2020-10-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: puppet-lint
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '2.0'
19
+ version: 2.4.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '2.0'
26
+ version: 2.4.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: git
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -119,6 +119,7 @@ description: |2
119
119
  * Check for cross-module class inclusion
120
120
  * Check for the use of the include keyword in profiles
121
121
  * Check for wmf-deprecated resources usage
122
+ * Check for deprecated validate_* functions
122
123
  email: lavagetto@gmail.com
123
124
  executables: []
124
125
  extensions: []
@@ -148,8 +149,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
148
149
  - !ruby/object:Gem::Version
149
150
  version: '0'
150
151
  requirements: []
151
- rubyforge_project:
152
- rubygems_version: 2.7.6.2
152
+ rubygems_version: 3.0.3
153
153
  signing_key:
154
154
  specification_version: 4
155
155
  summary: A puppet-lint plugin to check code adheres to the WMF coding guidelines