puppet-doc-lint 0.0.1 → 0.1.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
2
  SHA1:
3
- metadata.gz: 3869048bc78f3c9a1f104bcaf28111130e6d0511
4
- data.tar.gz: aef6d72342b140b4b1444e08a80fc123eaeb7cb6
3
+ metadata.gz: cfba85bcbbcadad148909ef3260b5b76d5b4854f
4
+ data.tar.gz: 32824c2b9f5e90e179a801abaaa66ef08db7889c
5
5
  SHA512:
6
- metadata.gz: 622affc112e5377071b2a8ec6a2455ecbfa8626e8e98846e1ca2f8fef425156da38a51571d1cecb6d913e4fc23c2614d2302da13c36060ad11f92fe39b20d25f
7
- data.tar.gz: 866228c5ebe8d5bb982cba81e2487b142b473657331f976e46d22ecfc431a0476c3b94037a34fa755180e78c21562e3ce8f219803e2cfd131e8153e6efcb5f08
6
+ metadata.gz: a9b268671e92354301d0cf53608980e51a9d50046107d41e5a4aa05121ffeadf254faf82ac5b825e685c88d390d5d0ec6f9e1ffc9cd587034a1c4f263a5c03dc
7
+ data.tar.gz: 2c289d5f34666d5aa7ee7a8b8206ef3ff906d99c7817d21a67c156962c22a14e835c6a4d836af1409ee6c758252aafbb09075ee78fe51186db8a8fcf2f09505b
data/README.md CHANGED
@@ -1,4 +1,5 @@
1
1
  # puppet-doc-lint
2
+ [![Build Status](https://travis-ci.org/petems/puppet-doc-lint.png?branch=master)](https://travis-ci.org/petems/puppet-doc-lint)
2
3
 
3
4
  Lint your Puppet files for RDoc coverage
4
5
 
@@ -15,6 +15,33 @@ else
15
15
  results = runner.run(ARGV)
16
16
  end
17
17
 
18
+ parameters_total = 0
19
+ parameters_documented_total = 0
20
+ parameters_undocumented_total = 0
21
+ parameters_missing_total = 0
22
+ tally = 0
23
+
18
24
  results.each do |result|
25
+ tally = tally + 1
19
26
  result.result_report
27
+ parameters_undocumented_total = parameters_undocumented_total + result.undocumented_parameters.size
28
+ parameters_total = parameters_total + result.parameters.size
29
+ parameters_documented_total = parameters_documented_total + result.documented_parameters.size
30
+ parameters_missing_total = parameters_missing_total + result.documented_parameter_no_assignment.size
31
+ end
32
+
33
+ coverage = 100
34
+
35
+ coverage = parameters_documented_total.percent_of(parameters_total) unless parameters_total == 0
36
+
37
+ puts "\n\n"
38
+ puts "Number of files: #{tally}"
39
+ puts "Total variables: #{parameters_total}"
40
+ puts "Total missing variables: #{parameters_total}"
41
+ puts "Documented variables: #{parameters_documented_total}"
42
+ puts "Documentation coverage: #{coverage.round(2)}%"
43
+
44
+ if (parameters_missing_total + parameters_undocumented_total) > 0
45
+ puts "Issues found!".bold.green.bg_red
46
+ exit 1
20
47
  end
@@ -5,6 +5,7 @@ require 'puppet-doc-lint/runner'
5
5
  require 'puppet-doc-lint/doc_runner'
6
6
  require 'puppet-doc-lint/result'
7
7
  require 'puppet-doc-lint/hash'
8
+ require 'puppet-doc-lint/string'
8
9
  require 'puppet-doc-lint/configuration'
9
10
  require 'rdoc'
10
11
 
@@ -57,5 +57,24 @@ class PuppetDocLint
57
57
  docs
58
58
  end # if nil?
59
59
  end # def docs
60
+
61
+ def authors
62
+ if !@object.doc.nil?
63
+ rdoc = RDoc::Markup.parse(@object.doc)
64
+ authors = []
65
+
66
+ author_docs = rdoc.parts.chunk{|i|i.class == RDoc::Markup::Heading && i.text == 'Authors'}.reject{|sep,ans| sep}.map{|sep,ans| ans}
67
+
68
+ author_docs.each do | doc_chunk |
69
+ unless doc_chunk[1].class == RDoc::Markup::BlankLine || doc_chunk[1].class == RDoc::Markup::Heading
70
+ doc_chunk[1].items.each do |chunk|
71
+ authors << chunk.parts.first.parts
72
+ end
73
+ end
74
+ end
75
+
76
+ authors
77
+ end # if nil?
78
+ end # def authors
60
79
  end # class Parser
61
80
  end # module PuppetDocLint
@@ -1,5 +1,11 @@
1
1
  require 'virtus'
2
2
 
3
+ class Numeric
4
+ def percent_of(n)
5
+ self.to_f / n.to_f * 100.0
6
+ end
7
+ end
8
+
3
9
  class PuppetDocLint
4
10
  class Result
5
11
  include Virtus.model
@@ -9,14 +15,32 @@ class PuppetDocLint
9
15
  attribute :no_documentation, Boolean, :default => false
10
16
  attribute :documented_parameters, String, :default => []
11
17
  attribute :undocumented_parameters, String, :default => []
18
+ attribute :documented_parameter_no_assignment, String, :default => []
19
+ attribute :authors, String, :default => []
12
20
 
13
21
  def result_report
14
- puts "Class name was: #{class_name}"
15
- puts "File name #{file_name}"
22
+ puts "===================================="
23
+ puts "Class #{class_name} ( #{file_name} )".bg_blue
16
24
  puts "Parameters found #{parameters}"
17
- puts "No documentation error: #{no_documentation}"
18
- puts "Documented parameters found: #{documented_parameters}"
19
- puts "Undocumented parameters found: #{undocumented_parameters}\n\n"
25
+ if no_documentation
26
+ puts "No documentation found."
27
+ puts "If there is documentation, this may be a bug with the Puppet parser"
28
+ puts "Puppet files with newer features such as the use of hashes can cause this\n\n"
29
+ else
30
+ puts "Documented parameters found: #{documented_parameters}".green
31
+ puts "Undocumented parameters found: #{undocumented_parameters}".red
32
+ puts "Parameters with Documentation but no defintion: #{documented_parameter_no_assignment}".red unless documented_parameter_no_assignment.empty?
33
+ puts "Documentation Coverage: #{percent_documented}%"
34
+ puts "Authors: #{authors}" unless authors.empty?
35
+ end
36
+ end
37
+
38
+ def percent_documented
39
+ if documented_parameters.size == 0
40
+ 100
41
+ else
42
+ documented_parameters.size.percent_of(parameters.size).round(2)
43
+ end
20
44
  end
21
45
 
22
46
  end #class Result
@@ -9,7 +9,7 @@ class PuppetDocLint
9
9
  next if content.instance_variable_get('@object').nil?
10
10
  parameters = (defined? content.parameters) ? content.parameters.paramflat : nil
11
11
  puppet_file_result.class_name = content.klass
12
- puppet_file_result.no_documentation = true if content.docs == {}
12
+ puppet_file_result.no_documentation = true if content.docs == {} && content.authors == []
13
13
  result = {
14
14
  content.klass => {
15
15
  'parameters' => parameters,
@@ -21,9 +21,12 @@ class PuppetDocLint
21
21
 
22
22
  undocumented = parameters.keys - content.docs.keys
23
23
  documented = parameters.keys - undocumented
24
+ documented_parameter_no_assignment = content.docs.keys - parameters.keys
24
25
 
25
26
  puppet_file_result.documented_parameters = documented unless documented.empty?
26
27
  puppet_file_result.undocumented_parameters = undocumented unless undocumented.empty?
28
+ puppet_file_result.documented_parameter_no_assignment = documented_parameter_no_assignment unless documented_parameter_no_assignment.empty?
29
+ puppet_file_result.authors = content.authors
27
30
 
28
31
  runner_results << puppet_file_result
29
32
  end
@@ -0,0 +1,20 @@
1
+ class String
2
+ def black; "\033[30m#{self}\033[0m" end
3
+ def red; "\033[31m#{self}\033[0m" end
4
+ def green; "\033[32m#{self}\033[0m" end
5
+ def brown; "\033[33m#{self}\033[0m" end
6
+ def blue; "\033[34m#{self}\033[0m" end
7
+ def magenta; "\033[35m#{self}\033[0m" end
8
+ def cyan; "\033[36m#{self}\033[0m" end
9
+ def gray; "\033[37m#{self}\033[0m" end
10
+ def bg_black; "\033[40m#{self}\0330m" end
11
+ def bg_red; "\033[41m#{self}\033[0m" end
12
+ def bg_green; "\033[42m#{self}\033[0m" end
13
+ def bg_brown; "\033[43m#{self}\033[0m" end
14
+ def bg_blue; "\033[44m#{self}\033[0m" end
15
+ def bg_magenta; "\033[45m#{self}\033[0m" end
16
+ def bg_cyan; "\033[46m#{self}\033[0m" end
17
+ def bg_gray; "\033[47m#{self}\033[0m" end
18
+ def bold; "\033[1m#{self}\033[22m" end
19
+ def reverse_color; "\033[7m#{self}\033[27m" end
20
+ end
@@ -1,3 +1,3 @@
1
1
  class PuppetDocLint
2
- PUPPETDOCLINT_VERSION = "0.0.1"
2
+ PUPPETDOCLINT_VERSION = "0.1.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppet-doc-lint
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Souter
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-11 00:00:00.000000000 Z
11
+ date: 2014-02-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -125,6 +125,7 @@ files:
125
125
  - lib/puppet-doc-lint/rake_task.rb
126
126
  - lib/puppet-doc-lint/result.rb
127
127
  - lib/puppet-doc-lint/runner.rb
128
+ - lib/puppet-doc-lint/string.rb
128
129
  - lib/puppet-doc-lint/version.rb
129
130
  - puppet-doc-lint.gemspec
130
131
  - spec/manifests/define_nordoc.pp
@@ -156,7 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
156
157
  version: '0'
157
158
  requirements: []
158
159
  rubyforge_project:
159
- rubygems_version: 2.0.3
160
+ rubygems_version: 2.0.14
160
161
  signing_key:
161
162
  specification_version: 4
162
163
  summary: Doc Parser for Puppet Modules. Returns Information about documentation.