puppet-lint-param-docs 1.6.0 → 1.7.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +64 -3
- data/lib/puppet-lint/plugins/check_parameter_documentation.rb +52 -21
- data/spec/puppet-lint/plugins/check_parameter_documentation_spec.rb +100 -0
- data/spec/spec_helper.rb +23 -0
- metadata +19 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4eb142c68d835142b195284909d9537589ed309072ddaa0a5ba1613422f3588e
|
4
|
+
data.tar.gz: 7eb0c3cde4c9772b8d54078de3a7598294545e4de5d4b61509a634d3a4984fae
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0fc8365176cd4916883c7e0734a71dab1f38d0a507241df4b2479772127d6293c52c4d236ff21e74fba51e0b2994dcee22f2cad34d617ee1a7df088a34076246
|
7
|
+
data.tar.gz: 925331d48264d7787f8874c96db4cdcfb5b2b4f616f7addfacfcdd3a2ee7b8daf05b1886e57adbd17768d6200250a0d136968808c0cde2f24b20294910788ca4
|
data/README.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
# puppet-lint parameter documentation check
|
2
2
|
|
3
|
+
[![License](https://img.shields.io/github/license/voxpupuli/puppet-lint-trailing_comma-check.svg)](https://github.com/voxpupuli/puppet-lint-trailing_comma-check/blob/master/LICENSE)
|
4
|
+
[![Test](https://github.com/voxpupuli/puppet-lint-param-docs/actions/workflows/test.yml/badge.svg)](https://github.com/voxpupuli/puppet-lint-param-docs/actions/workflows/test.yml)
|
5
|
+
[![codecov](https://codecov.io/gh/voxpupuli/puppet-lint-param-docs/branch/master/graph/badge.svg?token=Mypkl78hvK)](https://codecov.io/gh/voxpupuli/puppet-lint-param-docs)
|
6
|
+
[![Release](https://github.com/voxpupuli/puppet-lint-param-docs/actions/workflows/release.yml/badge.svg)](https://github.com/voxpupuli/puppet-lint-param-docs/actions/workflows/release.yml)
|
7
|
+
[![RubyGem Version](https://img.shields.io/gem/v/puppet-lint-param-docs.svg)](https://rubygems.org/gems/puppet-lint-param-docs)
|
8
|
+
[![RubyGem Downloads](https://img.shields.io/gem/dt/puppet-lint-param-docs.svg)](https://rubygems.org/gems/puppet-lint-param-docs)
|
9
|
+
[![Donated by Dominic Cleal](https://img.shields.io/badge/donated%20by-Dominic%20Cleal-fb7047.svg)](#transfer-notice)
|
10
|
+
|
3
11
|
Adds a new puppet-lint check to verify all class and defined type parameters
|
4
12
|
have been documented.
|
5
13
|
|
@@ -15,6 +23,21 @@ base and run `bundle install`.
|
|
15
23
|
gem 'puppet-lint-param-docs'
|
16
24
|
```
|
17
25
|
|
26
|
+
This gem is not only available on rubygems, but also as [GitHub Package](https://github.com/voxpupuli/puppet-lint-param-docs/packages/)
|
27
|
+
You can install it from GitHub like this:
|
28
|
+
|
29
|
+
```
|
30
|
+
$ gem install puppet-lint-param-docs --source "https://rubygems.pkg.github.com/voxpupuli"
|
31
|
+
```
|
32
|
+
|
33
|
+
Or in a Gemfile:
|
34
|
+
|
35
|
+
```
|
36
|
+
source "https://rubygems.pkg.github.com/voxpupuli" do
|
37
|
+
gem "puppet-lint-param-docs", "1.7.4"
|
38
|
+
end
|
39
|
+
```
|
40
|
+
|
18
41
|
## Usage
|
19
42
|
|
20
43
|
This plugin provides a new check to `puppet-lint`.
|
@@ -46,9 +69,25 @@ WARNING No matching class parameter for documentation of foo::bar
|
|
46
69
|
|
47
70
|
### Documentation styles
|
48
71
|
|
72
|
+
By default, the check will allow all known documentation styles.
|
73
|
+
You can, however, specify a list of accepted formats:
|
74
|
+
|
75
|
+
```ruby
|
76
|
+
# Limit to a single style
|
77
|
+
PuppetLint.configuration.docs_allowed_styles = 'strings'
|
78
|
+
# Limit to multiple styles
|
79
|
+
PuppetLint.configuration.docs_allowed_styles = ['strings', 'doc']
|
80
|
+
```
|
81
|
+
|
82
|
+
It will raise a warning if the documentation style does not match.
|
83
|
+
|
84
|
+
```
|
85
|
+
WARNING: invalid documentation style for class parameter foo::bar (doc) on line 4
|
86
|
+
```
|
87
|
+
|
49
88
|
The check will accept any of the following styles:
|
50
89
|
|
51
|
-
#### Puppet Strings
|
90
|
+
#### Puppet Strings: `strings`
|
52
91
|
|
53
92
|
Used by [Puppet Strings](https://github.com/puppetlabs/puppetlabs-strings).
|
54
93
|
|
@@ -59,7 +98,7 @@ Used by [Puppet Strings](https://github.com/puppetlabs/puppetlabs-strings).
|
|
59
98
|
define example($foo) { }
|
60
99
|
```
|
61
100
|
|
62
|
-
#### Puppet Doc style
|
101
|
+
#### Puppet Doc style: `doc`
|
63
102
|
|
64
103
|
Used by the [puppet-doc](https://puppet.com/docs/puppet/6.18/man/doc.html)
|
65
104
|
command, deprecated in favour of Puppet Strings.
|
@@ -74,7 +113,7 @@ command, deprecated in favour of Puppet Strings.
|
|
74
113
|
class example($foo) { }
|
75
114
|
```
|
76
115
|
|
77
|
-
#### Kafo rdoc style
|
116
|
+
#### Kafo rdoc style: `kafo`
|
78
117
|
|
79
118
|
Used in [kafo](https://github.com/theforeman/kafo#documentation) following an
|
80
119
|
rdoc style.
|
@@ -108,3 +147,25 @@ given in `config.pattern`.
|
|
108
147
|
|
109
148
|
The [Puppet Strings](#puppet_strings) `@api private` directive can also be used
|
110
149
|
to disable checks on that file.
|
150
|
+
|
151
|
+
## Transfer Notice
|
152
|
+
|
153
|
+
This plugin was originally authored by [Dominic Cleal](https://github.com/domcleal).
|
154
|
+
The maintainer preferred that Puppet Community take ownership of the module for future improvement and maintenance.
|
155
|
+
Existing pull requests and issues were transferred over, please fork and continue to contribute here.
|
156
|
+
|
157
|
+
Previously: https://github.com/domcleal/puppet-lint-absolute_classname-check
|
158
|
+
|
159
|
+
## License
|
160
|
+
|
161
|
+
This gem is licensed under the MIT license.
|
162
|
+
|
163
|
+
## Release information
|
164
|
+
|
165
|
+
To make a new release, please do:
|
166
|
+
* update the version in the gemspec file
|
167
|
+
* Install gems with `bundle install --with release --path .vendor`
|
168
|
+
* generate the changelog with `bundle exec rake changelog`
|
169
|
+
* Check if the new version matches the closed issues/PRs in the changelog
|
170
|
+
* Create a PR with it
|
171
|
+
* After it got merged, push a tag. GitHub actions will do the actual release to rubygems and GitHub Packages
|
@@ -1,27 +1,33 @@
|
|
1
1
|
PuppetLint.new_check(:parameter_documentation) do
|
2
2
|
def check
|
3
|
+
allowed_styles = PuppetLint.configuration.docs_allowed_styles || ['doc', 'kafo', 'strings']
|
4
|
+
allowed_styles = [ allowed_styles ].flatten
|
5
|
+
|
3
6
|
class_indexes.concat(defined_type_indexes).each do |idx|
|
4
7
|
doc_params = {}
|
8
|
+
doc_params_styles = {}
|
5
9
|
doc_params_duplicates = Hash.new { |hash, key| hash[key] = [doc_params[key]] }
|
6
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
13
|
if dtok.type == :COMMENT
|
10
|
-
if dtok.value =~ /\A\s
|
11
|
-
|
12
|
-
|
13
|
-
parameter = $1
|
14
|
-
parameter = 'name/title' if idx[:type] == :DEFINE && ['name','title'].include?(parameter)
|
15
|
-
if doc_params.include? parameter
|
16
|
-
doc_params_duplicates[parameter] << dtok
|
17
|
-
else
|
18
|
-
doc_params[parameter] = dtok
|
19
|
-
end
|
14
|
+
if dtok.value =~ /\A\s*@api +private\s*$/
|
15
|
+
is_private = true
|
16
|
+
next
|
20
17
|
end
|
21
18
|
|
22
|
-
|
23
|
-
|
24
|
-
|
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
|
25
31
|
end
|
26
32
|
end
|
27
33
|
|
@@ -52,12 +58,22 @@ PuppetLint.new_check(:parameter_documentation) do
|
|
52
58
|
|
53
59
|
unless is_private
|
54
60
|
params.each do |p|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
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
|
61
77
|
end
|
62
78
|
end
|
63
79
|
end
|
@@ -83,9 +99,9 @@ PuppetLint.new_check(:parameter_documentation) do
|
|
83
99
|
while true
|
84
100
|
ptok = e.next
|
85
101
|
case ptok.type
|
86
|
-
when :LPAREN
|
102
|
+
when :LPAREN, :LBRACK
|
87
103
|
nesting += 1
|
88
|
-
when :RPAREN
|
104
|
+
when :RPAREN, :RBRACK
|
89
105
|
nesting -= 1
|
90
106
|
when :COMMA
|
91
107
|
break unless nesting > 0
|
@@ -97,4 +113,19 @@ PuppetLint.new_check(:parameter_documentation) do
|
|
97
113
|
|
98
114
|
params
|
99
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'
|
128
|
+
end
|
129
|
+
[ style, * $~ ]
|
130
|
+
end
|
100
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) { }' }
|
@@ -355,6 +357,62 @@ define foreman (
|
|
355
357
|
end
|
356
358
|
end
|
357
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
|
+
|
358
416
|
context 'define with all parameters documented ($foo::)' do
|
359
417
|
let(:code) do
|
360
418
|
<<-EOS
|
@@ -855,4 +913,46 @@ define foreman (
|
|
855
913
|
expect(problems).to contain_warning('Duplicate defined type parameter documentation for example::name/title').on_line(5).in_column(10)
|
856
914
|
end
|
857
915
|
end
|
916
|
+
|
917
|
+
context 'class with array defaults containing variables' do
|
918
|
+
# Example taken from https://github.com/voxpupuli/puppet-lint-param-docs/issues/30
|
919
|
+
let(:code) do
|
920
|
+
<<-EOS.gsub(/^\s+/, '')
|
921
|
+
# @summary example class
|
922
|
+
#
|
923
|
+
# @param parameter_1
|
924
|
+
# @param parameter_2
|
925
|
+
# @param parameter_3
|
926
|
+
# @param parameter_4
|
927
|
+
# @param parameter_5
|
928
|
+
# @param parameter_6
|
929
|
+
# @param parameter_7
|
930
|
+
# @param parameter_8
|
931
|
+
#
|
932
|
+
class example (
|
933
|
+
Array $parameter_1 = $variable1,
|
934
|
+
Array $parameter_2 = [ $variable2, ],
|
935
|
+
Array $parameter_3 = [ $variable3, 'string1', ],
|
936
|
+
Array $parameter_4 = [
|
937
|
+
$variable4,
|
938
|
+
'string1',
|
939
|
+
],
|
940
|
+
Array $parameter_5 = [ $variable5, $variable6, 'string1', ],
|
941
|
+
Array $parameter_6 = [ $variable7, 'string1', $variable8, ],
|
942
|
+
Array $parameter_7 = [ 'string1', $variable9, ],
|
943
|
+
Array $parameter_8 = [
|
944
|
+
'string1',
|
945
|
+
$variable10,
|
946
|
+
'string2',
|
947
|
+
],
|
948
|
+
) {
|
949
|
+
# foo
|
950
|
+
}
|
951
|
+
EOS
|
952
|
+
end
|
953
|
+
|
954
|
+
it 'should not detect any problems' do
|
955
|
+
expect(problems).to have(0).problems
|
956
|
+
end
|
957
|
+
end
|
858
958
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,3 +1,26 @@
|
|
1
|
+
if ENV['COVERAGE'] == 'yes'
|
2
|
+
require 'simplecov'
|
3
|
+
require 'simplecov-console'
|
4
|
+
require 'codecov'
|
5
|
+
|
6
|
+
SimpleCov.start do
|
7
|
+
track_files 'lib/**/*.rb'
|
8
|
+
|
9
|
+
add_filter '/spec'
|
10
|
+
|
11
|
+
enable_coverage :branch
|
12
|
+
|
13
|
+
# do not track vendored files
|
14
|
+
add_filter '/vendor'
|
15
|
+
add_filter '/.vendor'
|
16
|
+
end
|
17
|
+
|
18
|
+
SimpleCov.formatters = [
|
19
|
+
SimpleCov::Formatter::Console,
|
20
|
+
SimpleCov::Formatter::Codecov,
|
21
|
+
]
|
22
|
+
end
|
23
|
+
|
1
24
|
require 'puppet-lint'
|
2
25
|
|
3
26
|
PuppetLint::Plugins.load_spec_helper
|
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.
|
4
|
+
version: 1.7.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vox Pupuli
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-07-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: puppet-lint
|
@@ -87,7 +87,21 @@ dependencies:
|
|
87
87
|
- !ruby/object:Gem::Version
|
88
88
|
version: '0'
|
89
89
|
- !ruby/object:Gem::Dependency
|
90
|
-
name: simplecov
|
90
|
+
name: simplecov-console
|
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
|
+
- !ruby/object:Gem::Dependency
|
104
|
+
name: codecov
|
91
105
|
requirement: !ruby/object:Gem::Requirement
|
92
106
|
requirements:
|
93
107
|
- - ">="
|
@@ -132,10 +146,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
132
146
|
- !ruby/object:Gem::Version
|
133
147
|
version: '0'
|
134
148
|
requirements: []
|
135
|
-
rubygems_version: 3.
|
149
|
+
rubygems_version: 3.2.22
|
136
150
|
signing_key:
|
137
151
|
specification_version: 4
|
138
152
|
summary: puppet-lint check to validate all parameters are documented
|
139
153
|
test_files:
|
140
|
-
- spec/spec_helper.rb
|
141
154
|
- spec/puppet-lint/plugins/check_parameter_documentation_spec.rb
|
155
|
+
- spec/spec_helper.rb
|