puppet-lint-param-docs 1.4.1 → 1.7.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
- SHA1:
3
- metadata.gz: e9c071b35fbded596e9cc62dbd7c632eb5ef0e55
4
- data.tar.gz: c8cc121248dd81d35397897d22bec9813f3085f0
2
+ SHA256:
3
+ metadata.gz: ca78318c1175f2885dcffee1d275f71edc78bb91a0624dc32e84fd949c03a841
4
+ data.tar.gz: d38343fa7170f7cdc1ae94c10aa3e809be6e61a30ce5f25d1c147e191782744f
5
5
  SHA512:
6
- metadata.gz: 8d69ff35bfbf3523499a5f2ff00daedd515c9552fe746f39e72d40e42ad804b2067bf40f60a2aedeeabfca15c49bf3c9359b858e15387a8ebd15d0cd61ca5261
7
- data.tar.gz: fb201326d0298f9b8e4193b0754d1a362273ea59da66d92f21fffbc9441d9c0c38fbae17d0bb3b9031de6345f77dccf4b369abe016e71dea238ff837453ffe3c
6
+ metadata.gz: 6c960b3b0f25548ff75c5597ac10ed27164a1230db2ab223272ad43dae88c223ca1653ef2c8e9c0ae416c98a8f4a8ba139c1501d920e3d6cbd521b6a49f8c058
7
+ data.tar.gz: 7433e3dee1f9055b53332dd4b3d080e154d2be067f70fb9db1a98317f2bb3a217f4548ead7db47dba081cd7b11b1e2a9038c0163d27d2a00775d1d69c54c89c1
data/README.md CHANGED
@@ -19,56 +19,91 @@ gem 'puppet-lint-param-docs'
19
19
 
20
20
  This plugin provides a new check to `puppet-lint`.
21
21
 
22
- ### parameter_documentation
22
+ ### parameter\_documentation
23
23
 
24
24
  **--fix support: No**
25
25
 
26
26
  This check will raise a warning for any class or defined type parameters that
27
- don't have an RDoc description.
27
+ don't have a description.
28
28
 
29
29
  ```
30
30
  WARNING: missing documentation for class parameter foo::bar
31
31
  WARNING: missing documentation for defined type parameter foo::baz
32
32
  ```
33
33
 
34
+ It will also raise warnings for parameters documented more than once.
35
+
36
+ ```
37
+ WARNING Duplicate class parameter documentation for foo::bar on line 5
38
+ WARNING Duplicate class parameter documentation for foo::bar on line 6
39
+ ```
40
+
41
+ A warning will also be raised if you document a parameter that doesn't exist in the class or defined type.
42
+
43
+ ```
44
+ WARNING No matching class parameter for documentation of foo::bar
45
+ ```
46
+
34
47
  ### Documentation styles
35
48
 
49
+ By default, the check will allow all known documentation styles.
50
+ You can, however, specify a list of accepted formats:
51
+
52
+ ```ruby
53
+ # Limit to a single style
54
+ PuppetLint.configuration.docs_allowed_styles = 'strings'
55
+ # Limit to multiple styles
56
+ PuppetLint.configuration.docs_allowed_styles = ['strings', 'doc']
57
+ ```
58
+
59
+ It will raise a warning if the documentation style does not match.
60
+
61
+ ```
62
+ WARNING: invalid documentation style for class parameter foo::bar (doc) on line 4
63
+ ```
64
+
36
65
  The check will accept any of the following styles:
37
66
 
38
- #### Puppet Strings
67
+ #### Puppet Strings: `strings`
39
68
 
40
69
  Used by [Puppet Strings](https://github.com/puppetlabs/puppetlabs-strings).
41
70
 
42
- # Example class
43
- #
44
- # @param foo example
45
- define example($foo) { }
71
+ ```puppet
72
+ # @summary Example class
73
+ #
74
+ # @param foo example
75
+ define example($foo) { }
76
+ ```
46
77
 
47
- #### Puppet Doc style
78
+ #### Puppet Doc style: `doc`
48
79
 
49
- Used by the [puppet-doc](https://docs.puppetlabs.com/puppet/latest/reference/man/doc.html)
50
- command, generally deprecated in favour of Puppet Strings.
80
+ Used by the [puppet-doc](https://puppet.com/docs/puppet/6.18/man/doc.html)
81
+ command, deprecated in favour of Puppet Strings.
51
82
 
52
- # Example class
53
- #
54
- # === Parameters:
55
- #
56
- # [*foo*] example
57
- #
58
- class example($foo) { }
83
+ ```puppet
84
+ # Example class
85
+ #
86
+ # === Parameters:
87
+ #
88
+ # [*foo*] example
89
+ #
90
+ class example($foo) { }
91
+ ```
59
92
 
60
- #### Kafo rdoc style
93
+ #### Kafo rdoc style: `kafo`
61
94
 
62
95
  Used in [kafo](https://github.com/theforeman/kafo#documentation) following an
63
96
  rdoc style.
64
97
 
65
- # Example class
66
- #
67
- # === Parameters:
68
- #
69
- # $foo:: example
70
- #
71
- class example($foo) { }
98
+ ```puppet
99
+ # Example class
100
+ #
101
+ # === Parameters:
102
+ #
103
+ # $foo:: example
104
+ #
105
+ class example($foo) { }
106
+ ```
72
107
 
73
108
  ### Selective rake task
74
109
 
@@ -83,6 +118,9 @@ helper to customise the lint rake task:
83
118
  config.pattern = ['manifests/init.pp', 'manifests/other/**/*.pp']
84
119
  end
85
120
 
86
- This would disable the parameter_documentation check by default, but then
121
+ This would disable the parameter\_documentation check by default, but then
87
122
  defines a new rake task (which runs after `lint`) specifically for the files
88
123
  given in `config.pattern`.
124
+
125
+ The [Puppet Strings](#puppet_strings) `@api private` directive can also be used
126
+ to disable checks on that file.
@@ -1,46 +1,131 @@
1
1
  PuppetLint.new_check(:parameter_documentation) do
2
2
  def check
3
- class_indexes.concat(defined_type_indexes).each do |idx|
4
- next if idx[:param_tokens].nil?
3
+ allowed_styles = PuppetLint.configuration.docs_allowed_styles || ['doc', 'kafo', 'strings']
4
+ allowed_styles = [ allowed_styles ].flatten
5
5
 
6
- doc_params = []
6
+ class_indexes.concat(defined_type_indexes).each do |idx|
7
+ doc_params = {}
8
+ doc_params_styles = {}
9
+ doc_params_duplicates = Hash.new { |hash, key| hash[key] = [doc_params[key]] }
10
+ is_private = false
7
11
  tokens[0..idx[:start]].reverse_each do |dtok|
8
12
  next if [:CLASS, :DEFINE, :NEWLINE, :WHITESPACE, :INDENT].include?(dtok.type)
9
- if [:COMMENT, :MLCOMMENT, :SLASH_COMMENT].include?(dtok.type)
10
- if dtok.value =~ /\A\s*\[\*([a-zA-Z0-9_]+)\*\]/ or
11
- dtok.value =~ /\A\s*\$([a-zA-Z0-9_]+):: +/ or
12
- dtok.value =~ /\A\s*@param ([a-zA-Z0-9_]+) +/
13
- doc_params << $1
13
+ if dtok.type == :COMMENT
14
+ if dtok.value =~ /\A\s*@api +private\s*$/
15
+ is_private = true
16
+ next
17
+ end
18
+
19
+ style = detect_style(dtok)
20
+ # not a doc parameter if style has not been detected
21
+ next if style[0].nil?
22
+
23
+ parameter = style[2]
24
+ parameter = 'name/title' if idx[:type] == :DEFINE && ['name','title'].include?(parameter)
25
+ if doc_params.include? parameter
26
+ doc_params_duplicates[parameter] << dtok
27
+ else
28
+ doc_params[parameter] = dtok
29
+ doc_params_styles[parameter] = style[0]
14
30
  end
15
- else
16
- break
17
31
  end
18
32
  end
19
33
 
20
- params = []
21
- e = idx[:param_tokens].each
22
- begin
23
- while (ptok = e.next)
24
- if ptok.type == :VARIABLE
25
- params << ptok
26
- # skip to the next parameter to avoid finding default values of variables
27
- while true
28
- ptok = e.next
29
- break if ptok.type == :COMMA
30
- end
31
- end
34
+ params = extract_params(idx)
35
+
36
+ # warn about duplicates
37
+ doc_params_duplicates.each do |parameter, tokens|
38
+ tokens.each do |token|
39
+ notify :warning, {
40
+ :message => "Duplicate #{type_str(idx)} parameter documentation for #{idx[:name_token].value}::#{parameter}",
41
+ :line => token.line,
42
+ :column => token.column + token.value.match(/\A\s*(@param\s*)?/)[0].length + 1 # `+ 1` is to account for length of the `#` COMMENT token.
43
+ }
32
44
  end
33
- rescue StopIteration; end
45
+ end
46
+
47
+ # warn about documentation for parameters that don't exist
48
+ doc_params.each do |parameter, token|
49
+ next if parameter == 'name/title' && idx[:type] == :DEFINE
50
+ next if params.find { |p| p.value == parameter }
34
51
 
35
- params.each do |p|
36
- next if doc_params.include? p.value
37
- idx_type = idx[:type] == :CLASS ? "class" : "defined type"
38
52
  notify :warning, {
39
- :message => "missing documentation for #{idx_type} parameter #{idx[:name_token].value}::#{p.value}",
40
- :line => p.line,
41
- :column => p.column,
53
+ :message => "No matching #{type_str(idx)} parameter for documentation of #{idx[:name_token].value}::#{parameter}",
54
+ :line => token.line,
55
+ :column => token.column + token.value.match(/\A\s*(@param\s*)?/)[0].length + 1
42
56
  }
43
57
  end
58
+
59
+ unless is_private
60
+ params.each do |p|
61
+ if doc_params.has_key? p.value
62
+ style = doc_params_styles[p.value] || 'unknown'
63
+ unless allowed_styles.include?(style)
64
+ notify :warning, {
65
+ :message => "invalid documentation style for #{type_str(idx)} parameter #{idx[:name_token].value}::#{p.value} (#{doc_params_styles[p.value]})",
66
+ :line => p.line,
67
+ :column => p.column,
68
+ }
69
+ end
70
+ else
71
+ notify :warning, {
72
+ :message => "missing documentation for #{type_str(idx)} parameter #{idx[:name_token].value}::#{p.value}",
73
+ :line => p.line,
74
+ :column => p.column,
75
+ }
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
81
+
82
+ private
83
+
84
+ def type_str(idx)
85
+ idx[:type] == :CLASS ? "class" : "defined type"
86
+ end
87
+
88
+ def extract_params(idx)
89
+ params = []
90
+ return params if idx[:param_tokens].nil?
91
+
92
+ e = idx[:param_tokens].each
93
+ begin
94
+ while (ptok = e.next)
95
+ if ptok.type == :VARIABLE
96
+ params << ptok
97
+ nesting = 0
98
+ # skip to the next parameter to avoid finding default values of variables
99
+ while true
100
+ ptok = e.next
101
+ case ptok.type
102
+ when :LPAREN
103
+ nesting += 1
104
+ when :RPAREN
105
+ nesting -= 1
106
+ when :COMMA
107
+ break unless nesting > 0
108
+ end
109
+ end
110
+ end
111
+ end
112
+ rescue StopIteration; end
113
+
114
+ params
115
+ end
116
+
117
+ # returns an array [<detected_style>, <complete match>, <param name>, <same-line-docs>]
118
+ # [nil, nil] if this is not a parameter.
119
+ def detect_style(dtok)
120
+ style = nil
121
+ case dtok.value
122
+ when %r{\A\s*\[\*([a-zA-Z0-9_]+)\*\]\s*(.*)\z}
123
+ style = 'doc'
124
+ when %r{\A\s*\$([a-zA-Z0-9_]+):: +(.*)\z}
125
+ style = 'kafo'
126
+ when %r{\A\s*@param (?:\[.+\] )?([a-zA-Z0-9_]+)(?: +|$)(.*)\z}
127
+ style = 'strings'
44
128
  end
129
+ [ style, * $~ ]
45
130
  end
46
131
  end
@@ -3,6 +3,8 @@ require 'spec_helper'
3
3
  describe 'parameter_documentation' do
4
4
  let(:class_msg) { 'missing documentation for class parameter example::%s' }
5
5
  let(:define_msg) { 'missing documentation for defined type parameter example::%s' }
6
+ let(:class_style_msg) { 'invalid documentation style for class parameter example::%s (%s)' }
7
+ let(:define_style_msg) { 'invalid documentation style for defined type parameter example::%s (%s)' }
6
8
 
7
9
  context 'class missing any documentation' do
8
10
  let(:code) { 'class example($foo) { }' }
@@ -52,6 +54,18 @@ describe 'parameter_documentation' do
52
54
  end
53
55
  end
54
56
 
57
+ context 'define with param defaults using a function' do
58
+ let(:code) { 'define example($foo = min(8, $facts["processors"]["count"])) { }' }
59
+
60
+ it 'should detect a single problem' do
61
+ expect(problems).to have(1).problem
62
+ end
63
+
64
+ it 'should create a warning' do
65
+ expect(problems).to contain_warning(define_msg % :foo).on_line(1).in_column(16)
66
+ end
67
+ end
68
+
55
69
  context 'class with many param defaults' do
56
70
  let(:code) do
57
71
  <<-EOS
@@ -149,6 +163,27 @@ define foreman (
149
163
  end
150
164
  end
151
165
 
166
+ context 'private class missing documentation (@param bar) for a parameter' do
167
+ let(:code) do
168
+ <<-EOS.gsub(/^\s+/, '')
169
+ # Example class
170
+ #
171
+ # @api private
172
+ #
173
+ # @param bar example
174
+ class example($foo, $bar) { }
175
+ EOS
176
+ end
177
+
178
+ it 'should detect no single problems' do
179
+ expect(problems).to have(0).problems
180
+ end
181
+
182
+ it 'should not create a warning' do
183
+ expect(problems).not_to contain_info(class_msg % :foo)
184
+ end
185
+ end
186
+
152
187
  context 'define missing documentation (@param bar) for a parameter' do
153
188
  let(:code) do
154
189
  <<-EOS.gsub(/^\s+/, '')
@@ -322,6 +357,62 @@ define foreman (
322
357
  end
323
358
  end
324
359
 
360
+ context 'check style' do
361
+ let(:code) do
362
+ <<-EOS
363
+ # Example mixed style class
364
+ #
365
+ # Parameters:
366
+ #
367
+ # $foo:: example
368
+ #
369
+ # [*bar*] example
370
+ #
371
+ # @param foobar example
372
+ #
373
+ class example($foo, $bar, $foobar) { }
374
+ EOS
375
+ end
376
+
377
+ context 'detect all styles' do
378
+ before do
379
+ PuppetLint.configuration.docs_allowed_styles = ['noexist']
380
+ end
381
+ after do
382
+ PuppetLint.configuration.docs_allowed_styles = false
383
+ end
384
+
385
+ it 'should detect three problems' do
386
+ expect(problems).to have(3).problems
387
+ end
388
+
389
+ it 'should create three problems' do
390
+ expect(problems).to contain_warning(class_style_msg % [:foo, 'kafo']).on_line(11).in_column(21)
391
+ expect(problems).to contain_warning(class_style_msg % [:bar, 'doc']).on_line(11).in_column(27)
392
+ expect(problems).to contain_warning(class_style_msg % [:foobar, 'strings']).on_line(11).in_column(33)
393
+ end
394
+ end
395
+
396
+ context 'use configured style' do
397
+ before do
398
+ PuppetLint.configuration.docs_allowed_styles = 'strings'
399
+ end
400
+ after do
401
+ PuppetLint.configuration.docs_allowed_styles = nil
402
+ end
403
+
404
+ it 'should detect two problems' do
405
+ expect(problems).to have(2).problems
406
+ end
407
+
408
+ it 'should create three problems' do
409
+ expect(problems).to contain_warning(class_style_msg % [:foo, 'kafo']).on_line(11).in_column(21)
410
+ expect(problems).to contain_warning(class_style_msg % [:bar, 'doc']).on_line(11).in_column(27)
411
+ end
412
+ end
413
+ end
414
+
415
+
325
416
  context 'define with all parameters documented ($foo::)' do
326
417
  let(:code) do
327
418
  <<-EOS
@@ -376,6 +467,88 @@ define foreman (
376
467
  end
377
468
  end
378
469
 
470
+ context 'class with all parameters documented (@param)' do
471
+ let(:code) do
472
+ <<-EOS
473
+ # Example class
474
+ #
475
+ # === Parameters:
476
+ #
477
+ # @param foo example
478
+ # @param [Integer] bar example
479
+ # @param baz
480
+ # example
481
+ # @param [Integer] qux
482
+ # example
483
+ #
484
+ class example($foo, $bar, $baz, $qux) { }
485
+ EOS
486
+ end
487
+
488
+ it 'should not detect any problems' do
489
+ expect(problems).to have(0).problems
490
+ end
491
+ end
492
+
493
+ context 'define with all parameters documented (@param)' do
494
+ let(:code) do
495
+ <<-EOS
496
+ # Example define
497
+ #
498
+ # === Parameters:
499
+ #
500
+ # @param foo example
501
+ # @param [Integer] bar example
502
+ # @param baz
503
+ # example
504
+ # @param [Integer] qux
505
+ # example
506
+ #
507
+ define example($foo, $bar, $baz, $qux) { }
508
+ EOS
509
+ end
510
+
511
+ it 'should not detect any problems' do
512
+ expect(problems).to have(0).problems
513
+ end
514
+ end
515
+
516
+ context 'define with all parameters documented with defaults (@param)' do
517
+ let(:code) do
518
+ <<-EOS
519
+ # Example define
520
+ #
521
+ # @param foo example
522
+ #
523
+ define example($foo = $facts['networking']['fqdn']) { }
524
+ EOS
525
+ end
526
+
527
+ it 'should not detect any problems' do
528
+ expect(problems).to have(0).problems
529
+ end
530
+ end
531
+
532
+ context 'define with all parameters documented with defaults using functions (@param)' do
533
+ let(:code) do
534
+ <<-EOS
535
+ # Example define
536
+ #
537
+ # @param foo example
538
+ # @param multiple test nested function calls
539
+ #
540
+ define example(
541
+ $foo = min(8, $facts['processors']['count']),
542
+ $multiple = min(8, max(2, $facts['processors']['count'])),
543
+ ) { }
544
+ EOS
545
+ end
546
+
547
+ it 'should not detect any problems' do
548
+ expect(problems).to have(0).problems
549
+ end
550
+ end
551
+
379
552
  context 'class without parameters' do
380
553
  let(:code) { 'class example { }' }
381
554
 
@@ -429,4 +602,315 @@ define foreman (
429
602
  expect(problems).to contain_warning(class_msg % :foo).on_line(7).in_column(15)
430
603
  end
431
604
  end
605
+
606
+ describe 'Duplicated documentation' do
607
+ let(:class_msg) { 'Duplicate class parameter documentation for example::%s' }
608
+ let(:define_msg) { 'Duplicate defined type parameter documentation for example::%s' }
609
+
610
+ context 'class with parameters documented twice (@param)' do
611
+ let(:code) do
612
+ <<-EOS.gsub(/^\s+/, '')
613
+ # @summary Example class
614
+ #
615
+ # @param bar
616
+ # example
617
+ # @param foo example
618
+ # @param bar Duplicate/conflicting docs
619
+ #
620
+ class example($foo, $bar) { }
621
+ EOS
622
+ end
623
+
624
+ it 'should detect two problems' do
625
+ expect(problems).to have(2).problem
626
+ end
627
+
628
+ it 'should create a warning on line 3' do
629
+ expect(problems).to contain_warning(class_msg % :bar).on_line(3).in_column(10)
630
+ end
631
+
632
+ it 'should create a warning on line 6' do
633
+ expect(problems).to contain_warning(class_msg % :bar).on_line(6).in_column(10)
634
+ end
635
+ end
636
+
637
+ context 'define with parameters documented twice (@param)' do
638
+ let(:code) do
639
+ <<-EOS.gsub(/^\s+/, '')
640
+ # @summary Example define
641
+ #
642
+ # @param bar
643
+ # example
644
+ # @param foo example
645
+ # @param bar Duplicate/conflicting docs
646
+ #
647
+ define example($foo, $bar) { }
648
+ EOS
649
+ end
650
+
651
+ it 'should detect two problems' do
652
+ expect(problems).to have(2).problem
653
+ end
654
+
655
+ it 'should create a warning on line 3' do
656
+ expect(problems).to contain_warning(define_msg % :bar).on_line(3).in_column(10)
657
+ end
658
+
659
+ it 'should create a warning on line 6' do
660
+ expect(problems).to contain_warning(define_msg % :bar).on_line(6).in_column(10)
661
+ end
662
+ end
663
+
664
+ context 'class with parameters documented 3 times (@param)' do
665
+ let(:code) do
666
+ <<-EOS.gsub(/^\s+/, '')
667
+ # @summary Example class
668
+ #
669
+ # @param bar
670
+ # example
671
+ # @param foo example
672
+ # @param bar Duplicate/conflicting docs
673
+ #
674
+ # @param bar
675
+ # example
676
+ #
677
+ class example($foo, $bar) { }
678
+ EOS
679
+ end
680
+
681
+ it 'should detect three problems' do
682
+ expect(problems).to have(3).problem
683
+ end
684
+
685
+ it 'should create a warning on line 3' do
686
+ expect(problems).to contain_warning(class_msg % :bar).on_line(3).in_column(10)
687
+ end
688
+
689
+ it 'should create a warning on line 6' do
690
+ expect(problems).to contain_warning(class_msg % :bar).on_line(6).in_column(10)
691
+ end
692
+
693
+ it 'should create a warning on line 8' do
694
+ expect(problems).to contain_warning(class_msg % :bar).on_line(8).in_column(10)
695
+ end
696
+ end
697
+
698
+ context 'private class with parameters documented twice (@param)' do
699
+ let(:code) do
700
+ <<-EOS.gsub(/^\s+/, '')
701
+ # @summary Example class
702
+ #
703
+ # @param bar docs
704
+ # @param bar Duplicate/conflicting docs
705
+ #
706
+ # @api private
707
+ class example($bar) { }
708
+ EOS
709
+ end
710
+
711
+ it 'should detect two problems' do
712
+ expect(problems).to have(2).problem
713
+ end
714
+
715
+ it 'should create a warning on line 3' do
716
+ expect(problems).to contain_warning(class_msg % :bar).on_line(3).in_column(10)
717
+ end
718
+
719
+ it 'should create a warning on line 4' do
720
+ expect(problems).to contain_warning(class_msg % :bar).on_line(4).in_column(10)
721
+ end
722
+ end
723
+
724
+ context 'class with parameters documented twice ([*bar*])' do
725
+ let(:code) do
726
+ <<-EOS.gsub(/^\s+/, '')
727
+ # @summary Example class
728
+ #
729
+ # @param bar
730
+ # example
731
+ # @param foo example
732
+ # [*bar*] Duplicate/conflicting docs
733
+ #
734
+ class example($foo, $bar) { }
735
+ EOS
736
+ end
737
+
738
+ it 'should detect two problems' do
739
+ expect(problems).to have(2).problem
740
+ end
741
+
742
+ it 'should create a warning on line 3' do
743
+ expect(problems).to contain_warning(class_msg % :bar).on_line(3).in_column(10)
744
+ end
745
+
746
+ it 'should create a warning on line 6' do
747
+ expect(problems).to contain_warning(class_msg % :bar).on_line(6).in_column(3)
748
+ end
749
+ end
750
+ end
751
+
752
+ context 'class with documentation for parameters that don\'t exist' do
753
+ let(:code) do
754
+ <<-EOS.gsub(/^\s+/, '')
755
+ # @summary Example class
756
+ #
757
+ # @param foo
758
+ class example { }
759
+ EOS
760
+ end
761
+
762
+ it 'should detect a single problem' do
763
+ expect(problems).to have(1).problem
764
+ end
765
+
766
+ it 'should create a warning on line 3' do
767
+ expect(problems).to contain_warning('No matching class parameter for documentation of example::foo').on_line(3).in_column(10)
768
+ end
769
+ end
770
+
771
+ context 'private class with documentation for parameters that don\'t exist' do
772
+ let(:code) do
773
+ <<-EOS.gsub(/^\s+/, '')
774
+ # @summary Example class
775
+ #
776
+ # @param foo
777
+ # Example docs
778
+ #
779
+ # @api private
780
+ class example { }
781
+ EOS
782
+ end
783
+
784
+ it 'should detect a single problem' do
785
+ expect(problems).to have(1).problem
786
+ end
787
+
788
+ it 'should create a warning on line 3' do
789
+ expect(problems).to contain_warning('No matching class parameter for documentation of example::foo').on_line(3).in_column(10)
790
+ end
791
+ end
792
+
793
+ context 'define with documentation for parameters that don\'t exist' do
794
+ let(:code) do
795
+ <<-EOS.gsub(/^\s+/, '')
796
+ # @summary Example define
797
+ #
798
+ # @param bar Docs for bar
799
+ # @param foo
800
+ # Docs for foo
801
+ #
802
+ # @api private
803
+ define example::example(String[1] $bar) { }
804
+ EOS
805
+ end
806
+
807
+ it 'should detect a single problem' do
808
+ expect(problems).to have(1).problem
809
+ end
810
+
811
+ it 'should create a warning on line 4' do
812
+ expect(problems).to contain_warning('No matching defined type parameter for documentation of example::example::foo').on_line(4).in_column(10)
813
+ end
814
+ end
815
+
816
+ context 'define with documentation for parameter `name`' do
817
+ let(:code) do
818
+ <<-EOS.gsub(/^\s+/, '')
819
+ # @summary Example define
820
+ #
821
+ # @param name
822
+ # Docs for the $name
823
+ # @param bar Docs for bar
824
+ define example::example(String[1] $bar) { }
825
+ EOS
826
+ end
827
+
828
+ it 'should not detect any problems' do
829
+ expect(problems).to have(0).problems
830
+ end
831
+ end
832
+
833
+ context 'class with documentation for parameter `name`' do
834
+ let(:code) do
835
+ <<-EOS.gsub(/^\s+/, '')
836
+ # @summary Example class
837
+ #
838
+ # @param name
839
+ # Invalid docs
840
+ class example { }
841
+ EOS
842
+ end
843
+
844
+ it 'should detect a single problem' do
845
+ expect(problems).to have(1).problem
846
+ end
847
+
848
+ it 'should create a warning on line 3' do
849
+ expect(problems).to contain_warning('No matching class parameter for documentation of example::name').on_line(3).in_column(10)
850
+ end
851
+ end
852
+
853
+ context 'define with documentation for parameter `title`' do
854
+ let(:code) do
855
+ <<-EOS.gsub(/^\s+/, '')
856
+ # @summary Example define
857
+ #
858
+ # @param title
859
+ # Docs for the $title
860
+ # @param bar Docs for bar
861
+ define example::example(String[1] $bar) { }
862
+ EOS
863
+ end
864
+
865
+ it 'should not detect any problems' do
866
+ expect(problems).to have(0).problems
867
+ end
868
+ end
869
+
870
+ context 'class with documentation for parameter `title`' do
871
+ let(:code) do
872
+ <<-EOS.gsub(/^\s+/, '')
873
+ # @summary Example class
874
+ #
875
+ # @param title
876
+ # Invalid docs
877
+ class example { }
878
+ EOS
879
+ end
880
+
881
+ it 'should detect a single problem' do
882
+ expect(problems).to have(1).problem
883
+ end
884
+
885
+ it 'should create a warning on line 3' do
886
+ expect(problems).to contain_warning('No matching class parameter for documentation of example::title').on_line(3).in_column(10)
887
+ end
888
+ end
889
+
890
+ context 'define with documentation for both `title` and `name`' do
891
+ let(:code) do
892
+ <<-EOS.gsub(/^\s+/, '')
893
+ # @summary Example define
894
+ #
895
+ # @param title
896
+ # Docs for the $title
897
+ # @param name
898
+ # Docs for the $name
899
+ # @param bar Docs for bar
900
+ define example(String[1] $bar) { }
901
+ EOS
902
+ end
903
+
904
+ it 'should detect two problems' do
905
+ expect(problems).to have(2).problems
906
+ end
907
+
908
+ it 'should create a warning on line 3' do
909
+ expect(problems).to contain_warning('Duplicate defined type parameter documentation for example::name/title').on_line(3).in_column(10)
910
+ end
911
+
912
+ it 'should create a warning on line 5' do
913
+ expect(problems).to contain_warning('Duplicate defined type parameter documentation for example::name/title').on_line(5).in_column(10)
914
+ end
915
+ end
432
916
  end
metadata CHANGED
@@ -1,94 +1,107 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppet-lint-param-docs
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.1
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
- - Dominic Cleal
7
+ - Vox Pupuli
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-22 00:00:00.000000000 Z
11
+ date: 2021-06-05 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
18
  - !ruby/object:Gem::Version
19
19
  version: '1.1'
20
- - - <
20
+ - - "<"
21
21
  - !ruby/object:Gem::Version
22
22
  version: '3.0'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
- - - '>='
27
+ - - ">="
28
28
  - !ruby/object:Gem::Version
29
29
  version: '1.1'
30
- - - <
30
+ - - "<"
31
31
  - !ruby/object:Gem::Version
32
32
  version: '3.0'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: rspec
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
- - - ~>
37
+ - - "~>"
38
38
  - !ruby/object:Gem::Version
39
39
  version: '3.0'
40
40
  type: :development
41
41
  prerelease: false
42
42
  version_requirements: !ruby/object:Gem::Requirement
43
43
  requirements:
44
- - - ~>
44
+ - - "~>"
45
45
  - !ruby/object:Gem::Version
46
46
  version: '3.0'
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec-its
49
49
  requirement: !ruby/object:Gem::Requirement
50
50
  requirements:
51
- - - ~>
51
+ - - "~>"
52
52
  - !ruby/object:Gem::Version
53
53
  version: '1.0'
54
54
  type: :development
55
55
  prerelease: false
56
56
  version_requirements: !ruby/object:Gem::Requirement
57
57
  requirements:
58
- - - ~>
58
+ - - "~>"
59
59
  - !ruby/object:Gem::Version
60
60
  version: '1.0'
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: rspec-collection_matchers
63
63
  requirement: !ruby/object:Gem::Requirement
64
64
  requirements:
65
- - - ~>
65
+ - - "~>"
66
66
  - !ruby/object:Gem::Version
67
67
  version: '1.0'
68
68
  type: :development
69
69
  prerelease: false
70
70
  version_requirements: !ruby/object:Gem::Requirement
71
71
  requirements:
72
- - - ~>
72
+ - - "~>"
73
73
  - !ruby/object:Gem::Version
74
74
  version: '1.0'
75
75
  - !ruby/object:Gem::Dependency
76
76
  name: rake
77
77
  requirement: !ruby/object:Gem::Requirement
78
78
  requirements:
79
- - - '>='
79
+ - - ">="
80
80
  - !ruby/object:Gem::Version
81
81
  version: '0'
82
82
  type: :development
83
83
  prerelease: false
84
84
  version_requirements: !ruby/object:Gem::Requirement
85
85
  requirements:
86
- - - '>='
86
+ - - ">="
87
87
  - !ruby/object:Gem::Version
88
88
  version: '0'
89
- description: |2
90
- A new check for puppet-lint that validates all parameters are documented.
91
- email: dcleal@redhat.com
89
+ - !ruby/object:Gem::Dependency
90
+ name: simplecov
91
+ requirement: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - ">="
94
+ - !ruby/object:Gem::Version
95
+ version: '0'
96
+ type: :development
97
+ prerelease: false
98
+ version_requirements: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ description: " A new check for puppet-lint that validates all parameters are documented.\n"
104
+ email: voxpupuli@groups.io
92
105
  executables: []
93
106
  extensions: []
94
107
  extra_rdoc_files: []
@@ -100,7 +113,7 @@ files:
100
113
  - lib/puppet-lint/plugins/check_parameter_documentation.rb
101
114
  - spec/puppet-lint/plugins/check_parameter_documentation_spec.rb
102
115
  - spec/spec_helper.rb
103
- homepage: https://github.com/domcleal/puppet-lint-param-docs
116
+ homepage: https://github.com/voxpupuli/puppet-lint-param-docs
104
117
  licenses:
105
118
  - MIT
106
119
  metadata: {}
@@ -110,20 +123,19 @@ require_paths:
110
123
  - lib
111
124
  required_ruby_version: !ruby/object:Gem::Requirement
112
125
  requirements:
113
- - - '>='
126
+ - - ">="
114
127
  - !ruby/object:Gem::Version
115
128
  version: '0'
116
129
  required_rubygems_version: !ruby/object:Gem::Requirement
117
130
  requirements:
118
- - - '>='
131
+ - - ">="
119
132
  - !ruby/object:Gem::Version
120
133
  version: '0'
121
134
  requirements: []
122
- rubyforge_project:
123
- rubygems_version: 2.4.4
135
+ rubygems_version: 3.1.6
124
136
  signing_key:
125
137
  specification_version: 4
126
138
  summary: puppet-lint check to validate all parameters are documented
127
139
  test_files:
128
- - spec/puppet-lint/plugins/check_parameter_documentation_spec.rb
129
140
  - spec/spec_helper.rb
141
+ - spec/puppet-lint/plugins/check_parameter_documentation_spec.rb