puppet-lint-param-docs 1.5.0 → 1.7.3

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
2
  SHA256:
3
- metadata.gz: 8f8b9401c298a02b66324e5ef2db75b5e1e498d19a0a64e0e4d05208003da40b
4
- data.tar.gz: 0ddfcd5cf79cbd88e60b59c5645e636e60092efcf305fe5c71ecc73d3580ca84
3
+ metadata.gz: 7043ab55d7f283428996acd506f7cd463b394b1bed232374a3a2c77b60d92ce6
4
+ data.tar.gz: 6f59047d0b5fab0d4996a9bfc38e6f41bb38e5fae0069a94e14f5d360e1b5b9e
5
5
  SHA512:
6
- metadata.gz: 50e90eccc7fd99371a2d59d125b0e6483f2b0a2b002f018339d81320aee9b44b89627b5c1178e710341c8cb2ca31d4893bda414e53a0b5b2530d83476726676f
7
- data.tar.gz: c1038644ed09895de383ed28d87e5041afd3fd7efc665f3dabf58c53aa89f9b2fc51f54e9ae5d35b725b71ac75d8fea1c1bc84c47b6610cfe7bb48c0639ed198
6
+ metadata.gz: 1e7eeb3cb591dba8762176e2c07dea23f074dd2e5da7686408b8facc70764c439226b0dfcfc0cc45fa233771aae86169a73feee5d075f1bd3383825b1f928294
7
+ data.tar.gz: f481eba19695f32c19dcb77c91fdecdbae8e49195f14ab4a405863ec1052b9d722a19c0f8b1cbad22077907326e09893f144d70cf08b7f0f9e0cfbd6ae0fd966
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,7 +118,7 @@ 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`.
89
124
 
@@ -1,51 +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]] }
7
10
  is_private = false
8
11
  tokens[0..idx[:start]].reverse_each do |dtok|
9
12
  next if [:CLASS, :DEFINE, :NEWLINE, :WHITESPACE, :INDENT].include?(dtok.type)
10
- if [:COMMENT, :MLCOMMENT, :SLASH_COMMENT].include?(dtok.type)
11
- if dtok.value =~ /\A\s*\[\*([a-zA-Z0-9_]+)\*\]/ or
12
- dtok.value =~ /\A\s*\$([a-zA-Z0-9_]+):: +/ or
13
- dtok.value =~ /\A\s*@param (?:\[.+\] )?([a-zA-Z0-9_]+)(?: +|$)/
14
- doc_params << $1
13
+ if dtok.type == :COMMENT
14
+ if dtok.value =~ /\A\s*@api +private\s*$/
15
+ is_private = true
16
+ next
15
17
  end
16
18
 
17
- is_private = true if dtok.value =~ /\A\s*@api +private\s*$/
18
- else
19
- break
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]
30
+ end
20
31
  end
21
32
  end
22
33
 
23
- next if is_private
24
-
25
- params = []
26
- e = idx[:param_tokens].each
27
- begin
28
- while (ptok = e.next)
29
- if ptok.type == :VARIABLE
30
- params << ptok
31
- # skip to the next parameter to avoid finding default values of variables
32
- while true
33
- ptok = e.next
34
- break if ptok.type == :COMMA
35
- end
36
- 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
+ }
37
44
  end
38
- 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 }
39
51
 
40
- params.each do |p|
41
- next if doc_params.include? p.value
42
- idx_type = idx[:type] == :CLASS ? "class" : "defined type"
43
52
  notify :warning, {
44
- :message => "missing documentation for #{idx_type} parameter #{idx[:name_token].value}::#{p.value}",
45
- :line => p.line,
46
- :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
47
56
  }
48
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'
49
128
  end
129
+ [ style, * $~ ]
50
130
  end
51
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
@@ -343,6 +357,62 @@ define foreman (
343
357
  end
344
358
  end
345
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
+
346
416
  context 'define with all parameters documented ($foo::)' do
347
417
  let(:code) do
348
418
  <<-EOS
@@ -443,6 +513,42 @@ define foreman (
443
513
  end
444
514
  end
445
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
+
446
552
  context 'class without parameters' do
447
553
  let(:code) { 'class example { }' }
448
554
 
@@ -496,4 +602,315 @@ define foreman (
496
602
  expect(problems).to contain_warning(class_msg % :foo).on_line(7).in_column(15)
497
603
  end
498
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
499
916
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppet-lint-param-docs
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.0
4
+ version: 1.7.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vox Pupuli
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-11 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
@@ -132,7 +132,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
132
132
  - !ruby/object:Gem::Version
133
133
  version: '0'
134
134
  requirements: []
135
- rubygems_version: 3.0.2
135
+ rubygems_version: 3.1.6
136
136
  signing_key:
137
137
  specification_version: 4
138
138
  summary: puppet-lint check to validate all parameters are documented