puppet-lint-param-docs 1.0.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 5b51934ae6df0b664bc963b8366a37b7e6ec3a4f
4
+ data.tar.gz: ad409a86b6778a747ea42cfa6ec1dc50172aba27
5
+ SHA512:
6
+ metadata.gz: 07878556ff5e6f8a738115afa9b274561114624c29a85ccb48061f21a50531667fc7ab0e3dcc6c67167e30851a41a681dcc2344826d02d865de6d3b5ec4ce1c1
7
+ data.tar.gz: c931d62386aa49bb75c57862c321d953b5e64823ebac846b48a9c088d5551a5eecd136c8fcda6dcd3a8fc64f769af8f545ccc30e3453a7cad90794bc9d41d67b
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Tim Sharpe
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # puppet-lint parameter documentation check
2
+
3
+ Adds a new puppet-lint check to verify all class parameters have been
4
+ documented.
5
+
6
+ Particularly useful with [kafo](https://github.com/theforeman/kafo), as its
7
+ default behaviour is to throw an error when a parameter is undocumented.
8
+
9
+ ## Installation
10
+
11
+ To use this plugin, add the following like to the Gemfile in your Puppet code
12
+ base and run `bundle install`.
13
+
14
+ ```ruby
15
+ gem 'puppet-lint-param-docs'
16
+ ```
17
+
18
+ ## Usage
19
+
20
+ This plugin provides a new check to `puppet-lint`.
21
+
22
+ ### parameter_documentation
23
+
24
+ **--fix support: No**
25
+
26
+ This check will raise a warning for any class parameters that don't have an
27
+ RDoc description.
28
+
29
+ ```
30
+ WARNING: missing documentation for class parameter foo::bar
31
+ ```
@@ -0,0 +1,41 @@
1
+ PuppetLint.new_check(:parameter_documentation) do
2
+ def check
3
+ class_indexes.each do |klass|
4
+ next if klass[:param_tokens].nil?
5
+
6
+ doc_params = []
7
+ tokens[0..klass[:start]].reverse_each do |dtok|
8
+ next if [:CLASS, :NEWLINE, :WHITESPACE, :INDENT].include?(dtok.type)
9
+ if [:COMMENT, :MLCOMMENT, :SLASH_COMMENT].include?(dtok.type)
10
+ doc_params << $1 if dtok.value =~ /\A\s*\$([a-zA-Z0-9_]+)::/
11
+ else
12
+ break
13
+ end
14
+ end
15
+
16
+ params = []
17
+ e = klass[:param_tokens].each
18
+ e.each do |ptok|
19
+ params << ptok if ptok.type == :VARIABLE
20
+ # skip to the next parameter to avoid finding default values of variables
21
+ begin
22
+ while true
23
+ ptok = e.next
24
+ break if ptok == :COMMA
25
+ end
26
+ rescue StopIteration
27
+ break
28
+ end
29
+ end
30
+
31
+ params.each do |p|
32
+ next if doc_params.include? p.value
33
+ notify :warning, {
34
+ :message => "missing documentation for class parameter #{klass[:name_token].value}::#{p.value}",
35
+ :line => p.line,
36
+ :column => p.column,
37
+ }
38
+ end
39
+ end
40
+ end
41
+ end
@@ -0,0 +1,86 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'parameter_documentation' do
4
+ let(:msg) { 'missing documentation for class parameter example::foo' }
5
+
6
+ context 'class missing any documentation' do
7
+ let(:code) { 'class example($foo) { }' }
8
+
9
+ it 'should detect a single problem' do
10
+ expect(problems).to have(1).problem
11
+ end
12
+
13
+ it 'should create a warning' do
14
+ expect(problems).to contain_warning(msg).on_line(1).in_column(15)
15
+ end
16
+ end
17
+
18
+ context 'class with param defaults' do
19
+ let(:code) { 'class example($foo = $example::params::foo) { }' }
20
+
21
+ it 'should detect a single problem' do
22
+ expect(problems).to have(1).problem
23
+ end
24
+
25
+ it 'should create a warning' do
26
+ expect(problems).to contain_warning(msg).on_line(1).in_column(15)
27
+ end
28
+ end
29
+
30
+ context 'class missing documentation for a parameter' do
31
+ let(:code) do
32
+ <<-EOS
33
+ # Example class
34
+ #
35
+ # === Parameters:
36
+ #
37
+ # $bar:: example
38
+ #
39
+ class example($foo, $bar) { }
40
+ EOS
41
+ end
42
+
43
+ it 'should detect a single problem' do
44
+ expect(problems).to have(1).problem
45
+ end
46
+
47
+ it 'should create a warning' do
48
+ # column looks wrong, maybe the parser's out
49
+ expect(problems).to contain_warning(msg).on_line(7).in_column(21)
50
+ end
51
+ end
52
+
53
+ context 'class with all parameters documented' do
54
+ let(:code) do
55
+ <<-EOS
56
+ # Example class
57
+ #
58
+ # === Parameters:
59
+ #
60
+ # $foo:: example
61
+ #
62
+ class example($foo) { }
63
+ EOS
64
+ end
65
+
66
+ it 'should not detect any problems' do
67
+ expect(problems).to have(0).problems
68
+ end
69
+ end
70
+
71
+ context 'class without parameters' do
72
+ let(:code) { 'class example { }' }
73
+
74
+ it 'should not detect any problems' do
75
+ expect(problems).to have(0).problems
76
+ end
77
+ end
78
+
79
+ context 'class without parameters and a function call' do
80
+ let(:code) { 'class example { a($foo::bar) }' }
81
+
82
+ it 'should not detect any problems' do
83
+ expect(problems).to have(0).problems
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,3 @@
1
+ require 'puppet-lint'
2
+
3
+ PuppetLint::Plugins.load_spec_helper
metadata ADDED
@@ -0,0 +1,122 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: puppet-lint-param-docs
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Dominic Cleal
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: puppet-lint
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '3.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '3.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec-its
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: '1.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: '1.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec-collection_matchers
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '1.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ~>
67
+ - !ruby/object:Gem::Version
68
+ version: '1.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: |2
84
+ A new check for puppet-lint that validates all class parameters are
85
+ documented.
86
+ email: dcleal@redhat.com
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - LICENSE
92
+ - README.md
93
+ - lib/puppet-lint/plugins/check_parameter_documentation.rb
94
+ - spec/puppet-lint/plugins/check_parameter_documentation_spec.rb
95
+ - spec/spec_helper.rb
96
+ homepage: https://github.com/domcleal/puppet-lint-param-docs
97
+ licenses:
98
+ - MIT
99
+ metadata: {}
100
+ post_install_message:
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - '>='
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - '>='
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ requirements: []
115
+ rubyforge_project:
116
+ rubygems_version: 2.2.2
117
+ signing_key:
118
+ specification_version: 4
119
+ summary: puppet-lint check to validate all parameters are documented
120
+ test_files:
121
+ - spec/puppet-lint/plugins/check_parameter_documentation_spec.rb
122
+ - spec/spec_helper.rb