puppet-lint 0.0.1 → 0.0.2

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.
@@ -2,12 +2,14 @@ require 'puppet-lint/plugin'
2
2
  require 'puppet-lint/plugins'
3
3
 
4
4
  class PuppetLint
5
- VERSION = '0.0.1'
5
+ VERSION = '0.0.2'
6
6
 
7
7
  attr_reader :code, :file
8
8
 
9
9
  def initialize
10
10
  @data = nil
11
+ @errors = 0
12
+ @warnings = 0
11
13
  end
12
14
 
13
15
  def file=(path)
@@ -20,11 +22,29 @@ class PuppetLint
20
22
  @data = value
21
23
  end
22
24
 
25
+ def report(kind, message)
26
+ if kind == :warnings
27
+ @warnings += 1
28
+ puts "WARNING: #{message}"
29
+ else
30
+ @errors += 1
31
+ puts "ERROR: #{message}"
32
+ end
33
+ end
34
+
35
+ def errors?
36
+ @errors != 0
37
+ end
38
+
39
+ def warnings?
40
+ @warnings != 0
41
+ end
42
+
23
43
  def run
24
44
  PuppetLint::CheckPlugin.repository.each do |plugin|
25
45
  problems = plugin.new.run(@data)
26
- problems[:errors].each { |error| puts "ERROR: #{error}" }
27
- problems[:warnings].each { |warning| puts "WARNING: #{warning}" }
46
+ problems[:errors].each { |error| report :errors, error }
47
+ problems[:warnings].each { |warning| report :warnings, warning }
28
48
  end
29
49
  end
30
50
  end
@@ -4,3 +4,5 @@ class PuppetLint
4
4
  end
5
5
 
6
6
  require 'puppet-lint/plugins/check_strings'
7
+ require 'puppet-lint/plugins/check_whitespace'
8
+ require 'puppet-lint/plugins/check_resources'
@@ -0,0 +1,52 @@
1
+ # Resources
2
+ # http://docs.puppetlabs.com/guides/style_guide.html#resources
3
+
4
+ class PuppetLint::Plugins::CheckResources < PuppetLint::CheckPlugin
5
+ def test(data)
6
+ line_no = 0
7
+ in_resource = true
8
+ first_attribute = false
9
+ data.split("\n").each do |line|
10
+ line_no += 1
11
+
12
+ if line.include? "{"
13
+ in_resource = true
14
+ first_attribute = true
15
+ line = line.slice(line.index('{')..-1)
16
+ end
17
+
18
+ if in_resource
19
+ # Resource titles SHOULD be quoted
20
+ line.scan(/[^'"]\s*:/) do |match|
21
+ unless line =~ /\$[\w:]+\s*:/
22
+ warn "unquoted resource title on line #{line_no}"
23
+ end
24
+ end
25
+
26
+ line.scan(/(\w+)\s*=>\s*([^\n,;]+)/) do |attr, value|
27
+ # Ensure SHOULD be the first attribute listed
28
+ if attr == 'ensure'
29
+ unless first_attribute
30
+ warn "ensure found on line #{line_no} but it's not the first attribute"
31
+ end
32
+ end
33
+
34
+ # File modes SHOULD be represented as a 4 digits instead of 3, to
35
+ # explicitly show that they are octal values.
36
+ if attr == 'mode'
37
+ unless value =~ /'\d{4}'/
38
+ warn "mode should be represented as a 4 digit octal value on line #{line_no}"
39
+ end
40
+ end
41
+
42
+ first_attribute = false
43
+ end
44
+ first_attribute = false
45
+ end
46
+
47
+ if line.include? "}"
48
+ in_resource = false
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,44 @@
1
+ # Spacing, Identation & Whitespace
2
+ # http://http://docs.puppetlabs.com/guides/style_guide.html#spacing-indentation--whitespace
3
+
4
+ class PuppetLint::Plugins::CheckWhitespace < PuppetLint::CheckPlugin
5
+ def test(data)
6
+ line_no = 0
7
+ in_block = false
8
+ prefix_length = 0
9
+ data.split("\n").each do |line|
10
+ line_no += 1
11
+
12
+ # MUST NOT use literal tab characters
13
+ error "tab character found on line #{line_no}" if line.include? "\t"
14
+
15
+ # MUST NOT contain trailing white space
16
+ error "trailing whitespace found on line #{line_no}" if line.end_with? " "
17
+
18
+ # SHOULD NOT exceed an 80 character line width
19
+ warn "line #{line_no} has more than 80 characters" if line.length > 80
20
+
21
+ # MUST use two-space soft tabs
22
+ line.scan(/^ +/) do |prefix|
23
+ unless prefix.length % 2 == 0
24
+ error "two-space soft tabs not used on line #{line_no}"
25
+ end
26
+ end
27
+
28
+ # SHOULD align fat comma arrows (=>) within blocks of attributes
29
+ if line =~ /^( +\w+ +)=>/
30
+ if in_block
31
+ unless $1.length == prefix_length
32
+ warn "=> on line #{line_no} isn't aligned with the previous line"
33
+ end
34
+ else
35
+ prefix_length = $1.length
36
+ in_block = true
37
+ end
38
+ else
39
+ in_block = false
40
+ prefix_length = 0
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,12 @@
1
+ require 'rubygems'
2
+ require 'puppet-lint'
3
+
4
+ task :lint do
5
+ linter = PuppetLint.new
6
+ Dir.glob('**/*.pp').each do |puppet_file|
7
+ puts "Evaluating #{puppet_file}"
8
+ linter.file = puppet_file
9
+ linter.run
10
+ end
11
+ fail if linter.errors?
12
+ end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'puppet-lint'
3
- s.version = '0.0.1'
3
+ s.version = '0.0.2'
4
4
  s.homepage = 'https://github.com/rodjek/puppet-lint/'
5
5
  s.summary = 'Ensure your Puppet manifests conform with the Puppetlabs style guide'
6
6
  s.description = 'Checks your Puppet manifests against the Puppetlabs
@@ -10,9 +10,12 @@ Gem::Specification.new do |s|
10
10
  s.files = [
11
11
  'bin/puppet-lint',
12
12
  'lib/puppet-lint/plugin.rb',
13
+ 'lib/puppet-lint/plugins/check_resources.rb',
13
14
  'lib/puppet-lint/plugins/check_strings.rb',
15
+ 'lib/puppet-lint/plugins/check_whitespace.rb',
14
16
  'lib/puppet-lint/plugins.rb',
15
17
  'lib/puppet-lint.rb',
18
+ 'lib/tasks/puppet-lint.rake',
16
19
  'puppet-lint.gemspec',
17
20
  'README.md',
18
21
  ]
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppet-lint
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Tim Sharpe
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-08-15 00:00:00 Z
18
+ date: 2011-08-17 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rspec
@@ -44,9 +44,12 @@ extra_rdoc_files: []
44
44
  files:
45
45
  - bin/puppet-lint
46
46
  - lib/puppet-lint/plugin.rb
47
+ - lib/puppet-lint/plugins/check_resources.rb
47
48
  - lib/puppet-lint/plugins/check_strings.rb
49
+ - lib/puppet-lint/plugins/check_whitespace.rb
48
50
  - lib/puppet-lint/plugins.rb
49
51
  - lib/puppet-lint.rb
52
+ - lib/tasks/puppet-lint.rake
50
53
  - puppet-lint.gemspec
51
54
  - README.md
52
55
  homepage: https://github.com/rodjek/puppet-lint/