puppet-lint-wmf_styleguide-check 1.1.0 → 1.1.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: 7980b85ac1476eb1cfd7107a024a8d01f56d3aaa13bc4adf6542b52edeb862a8
4
- data.tar.gz: f5b71a6c23db3e26deec5d4f2a2d036ad4dbaeb26e0aa80d2049bf6e95e830eb
3
+ metadata.gz: '0996980289ea98e58b4da21e94d46732a5fec1cda561ddcd979ec647c91db633'
4
+ data.tar.gz: d8b5d617cb4ba1f1765670171cf157b723d73428410b8f1e564d8f160f20a046
5
5
  SHA512:
6
- metadata.gz: 814e0b269f85a970e883534f42a12f201e0afaf530f47474e7bbfaf685dd0ae549a529de9c639768c6e34f11d53bb66425e7c31a4a25cf0d6bb6d60f9c614238
7
- data.tar.gz: 8b85af51045fc558202c404ce87f20c0ca14dc76538ea30bde1abd68c3eac4ac154e1a77a309ff08b9e96ed93aca6945e870d117553259a68aa09d45d7b68b91
6
+ metadata.gz: c8056b429179de7156ecdb3ccb09bad40c9c4ae0c487a2177ca8073b204e4de935da30ac993b3c94ebf896f0140f9bee36707cf045cfeb5e3617c34142debeb2
7
+ data.tar.gz: 96531a80875d9aa641a8a34ac3a541ab1ad75c0b4fb37228324c6312e2ba736749e3532de77bb6d8412ea5b3c5d973977f69f09a83d2ec10310d9cd3f028f9b4
@@ -280,7 +280,6 @@ end
280
280
 
281
281
  def lookup_not_in_params(klass)
282
282
  # Checks if a lookup call is not in a parameter declaration. Used to check profiles
283
-
284
283
  # Any lookup call that is not inside a parameter declaration is a violation
285
284
  tokens = klass.lookup_calls.reject do |token|
286
285
  maybe_param = token.prev_code_token.prev_code_token
@@ -493,6 +492,17 @@ PuppetLint.new_check(:wmf_styleguide) do
493
492
  # If we're not within a node definition, skip this token
494
493
  next unless in_node_def
495
494
  case token.type
495
+ when :REGEX
496
+ if !token.value.start_with?('^') || !token.value.end_with?('$')
497
+ msg = {
498
+ message: "wmf-style: regex node matching must match the whole string (^...$), got: #{token.value}",
499
+ line: token.line,
500
+ column: token.column,
501
+ token: token,
502
+ problem: 'node_regex'
503
+ }
504
+ notify :error, msg
505
+ end
496
506
  when :LBRACE
497
507
  title_tokens = tokens[start + 1..(i - 1)].select(&:node_def?) if braces_level.zero?
498
508
  braces_level += 1
@@ -538,4 +548,15 @@ PuppetLint.new_check(:wmf_styleguide) do
538
548
  check_node node
539
549
  end
540
550
  end
551
+
552
+ def fix_node_regex(problem)
553
+ problem[:token].value.insert(0, '^') unless problem[:token].value.start_with?('^')
554
+ problem[:token].value << '$' unless problem[:token].value.end_with?('$')
555
+ end
556
+
557
+ def fix(problem)
558
+ raise PuppetLint::NoFix unless problem[:problem] == 'node_regex'
559
+ method = "fix_#{problem[:problem]}"
560
+ send(method, problem) if respond_to? method
561
+ end
541
562
  end
@@ -88,7 +88,7 @@ define foo::fixme ($a=hiera('something')) {
88
88
  EOF
89
89
 
90
90
  node_ok = <<-EOF
91
- node /^test1.*\.example\.com$/ {
91
+ node /^test1.*\\.example\\.com$/ {
92
92
  role(spare::system)
93
93
  }
94
94
  EOF
@@ -106,6 +106,30 @@ node 'fixme' {
106
106
  }
107
107
  EOF
108
108
 
109
+ node_regex_missing_start = <<-EOF
110
+ node /test1.*\\.example\\.com$/ {
111
+ role(spare::system)
112
+ }
113
+ EOF
114
+
115
+ node_regex_missing_end = <<-EOF
116
+ node /^test1.*\\.example\\.com/ {
117
+ role(spare::system)
118
+ }
119
+ EOF
120
+
121
+ node_regex_missing_both = <<-EOF
122
+ node /test1.*\\.example\\.com/ {
123
+ role(spare::system)
124
+ }
125
+ EOF
126
+
127
+ node_regex_fixed = <<-EOF
128
+ node /^test1.*\\.example\\.com$/ {
129
+ role(spare::system)
130
+ }
131
+ EOF
132
+
109
133
  deprecation_ko = <<-EOF
110
134
  define test() {
111
135
  base::service_unit{ 'test2': }
@@ -240,10 +264,52 @@ describe 'wmf_styleguide' do
240
264
  end
241
265
  end
242
266
 
267
+ context 'node regex with start violation' do
268
+ let(:code) { node_regex_missing_start }
269
+ it 'should start the regex with ^' do
270
+ expect(problems).to contain_error('wmf-style: regex node matching must match the whole string (^...$), got: test1.*\\.example\\.com$')
271
+ end
272
+ end
273
+ context 'node regex with end violation' do
274
+ let(:code) { node_regex_missing_end }
275
+ it 'should end the regex with $' do
276
+ expect(problems).to contain_error('wmf-style: regex node matching must match the whole string (^...$), got: ^test1.*\\.example\\.com')
277
+ end
278
+ end
279
+ context 'node regex with start and end violations' do
280
+ let(:code) { node_regex_missing_both }
281
+ it 'should start the regex with ^ and end it with $' do
282
+ expect(problems).to contain_error('wmf-style: regex node matching must match the whole string (^...$), got: test1.*\\.example\\.com')
283
+ end
284
+ end
285
+
243
286
  context 'defined type with deprecations' do
244
287
  let(:code) { deprecation_ko }
245
288
  it 'should not' do
246
289
  expect(problems).to contain_error("wmf-style: 'test' should not include the deprecated define 'base::service_unit'")
247
290
  end
248
291
  end
292
+
293
+ context 'with fix enabled' do
294
+ before do
295
+ PuppetLint.configuration.fix = true
296
+ end
297
+
298
+ after do
299
+ PuppetLint.configuration.fix = false
300
+ end
301
+
302
+ context 'node regex with start violation' do
303
+ let(:code) { node_regex_missing_start }
304
+ it { expect(manifest).to eq(node_regex_fixed) }
305
+ end
306
+ context 'node regex with end violation' do
307
+ let(:code) { node_regex_missing_end }
308
+ it { expect(manifest).to eq(node_regex_fixed) }
309
+ end
310
+ context 'node regex with start and end violations' do
311
+ let(:code) { node_regex_missing_both }
312
+ it { expect(manifest).to eq(node_regex_fixed) }
313
+ end
314
+ end
249
315
  end
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.1.0
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Giuseppe Lavagetto
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-15 00:00:00.000000000 Z
11
+ date: 2023-08-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: puppet-lint
@@ -163,11 +163,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
163
163
  - !ruby/object:Gem::Version
164
164
  version: '0'
165
165
  requirements: []
166
- rubyforge_project:
167
- rubygems_version: 2.7.6.2
166
+ rubygems_version: 3.2.5
168
167
  signing_key:
169
168
  specification_version: 4
170
169
  summary: A puppet-lint plugin to check code adheres to the WMF coding guidelines
171
170
  test_files:
172
- - spec/puppet-lint/plugins/check_wmf_styleguide_check_spec.rb
173
171
  - spec/spec_helper.rb
172
+ - spec/puppet-lint/plugins/check_wmf_styleguide_check_spec.rb