puppet-lint 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
File without changes
@@ -0,0 +1,47 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
4
+
5
+ help = <<HELP
6
+ Puppet-lint
7
+
8
+ Basic Command Line Usage:
9
+ puppet-lint [OPTIONS] [PATH]
10
+
11
+ PATH The path to the Puppet manifest.
12
+
13
+ Options:
14
+ HELP
15
+
16
+ require 'optparse'
17
+ require 'rubygems'
18
+ require 'puppet-lint'
19
+
20
+ opts = OptionParser.new do |opts|
21
+ opts.banner = help
22
+
23
+ opts.on("--version", "Display current version.") do
24
+ puts "Puppet-lint " + PuppetLint::VERSION
25
+ exit 0
26
+ end
27
+ end
28
+
29
+ # Read command line options into `options` hash
30
+ begin
31
+ opts.parse!
32
+ rescue OptionParser::InvalidOption
33
+ puts "puppet-lint: #{$!.message}"
34
+ puts "puppet-lint: try 'puppet-lint --help' for more information"
35
+ exit
36
+ end
37
+
38
+ if ARGV[0].nil?
39
+ puts "puppet-lint: no file specified"
40
+ puts "puppet-lint: try 'puppet-lint --help' for more information"
41
+ exit
42
+ end
43
+
44
+ l = PuppetLint.new
45
+ l.file = ARGV[0]
46
+ l.run
47
+
@@ -0,0 +1,30 @@
1
+ require 'puppet-lint/plugin'
2
+ require 'puppet-lint/plugins'
3
+
4
+ class PuppetLint
5
+ VERSION = '0.0.1'
6
+
7
+ attr_reader :code, :file
8
+
9
+ def initialize
10
+ @data = nil
11
+ end
12
+
13
+ def file=(path)
14
+ if File.exist? path
15
+ @data = File.read(path)
16
+ end
17
+ end
18
+
19
+ def code=(value)
20
+ @data = value
21
+ end
22
+
23
+ def run
24
+ PuppetLint::CheckPlugin.repository.each do |plugin|
25
+ problems = plugin.new.run(@data)
26
+ problems[:errors].each { |error| puts "ERROR: #{error}" }
27
+ problems[:warnings].each { |warning| puts "WARNING: #{warning}" }
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,45 @@
1
+ class PuppetLint
2
+ module Plugin
3
+ module ClassMethods
4
+ def repository
5
+ @repository ||= []
6
+ end
7
+
8
+ def inherited(klass)
9
+ repository << klass
10
+ end
11
+ end
12
+
13
+ def self.included(klass)
14
+ klass.extend ClassMethods
15
+ end
16
+ end
17
+ end
18
+
19
+ class PuppetLint::CheckPlugin
20
+ include PuppetLint::Plugin
21
+
22
+ def initialize
23
+ @warnings = []
24
+ @errors = []
25
+ end
26
+
27
+ def warn(message)
28
+ @warnings << message
29
+ end
30
+
31
+ def error(message)
32
+ @errors << message
33
+ end
34
+
35
+ def run(data)
36
+ test(data)
37
+
38
+ {:warnings => @warnings, :errors => @errors}
39
+ end
40
+
41
+ def test(data)
42
+ raise NotImplementedError.new "Oh no"
43
+ end
44
+ end
45
+
@@ -0,0 +1,6 @@
1
+ class PuppetLint
2
+ class Plugins
3
+ end
4
+ end
5
+
6
+ require 'puppet-lint/plugins/check_strings'
@@ -0,0 +1,35 @@
1
+ class PuppetLint::Plugins::CheckStrings < PuppetLint::CheckPlugin
2
+ def test(data)
3
+ line_no = 0
4
+ data.each_line do |line|
5
+ line_no += 1
6
+ line.match(/"([^\\"]|\\\\|\\")*"/).to_a.each do |s|
7
+ if s.start_with? '"'
8
+ variable_found = false
9
+ s.scan(/.\$./) do |w|
10
+ if w.start_with? '\\'
11
+ next
12
+ elsif w.end_with? '{'
13
+ variable_found = true
14
+ else
15
+ warn "variable not enclosed in {} on line #{line_no}"
16
+ end
17
+ end
18
+ unless variable_found
19
+ warn "double quoted string containing no variables on line #{line_no}"
20
+ end
21
+ end
22
+ end
23
+
24
+ line.match(/'.+?'/).to_a.each do |s|
25
+ if s.start_with? "'"
26
+ s.scan(/\$./) do |w|
27
+ if w.end_with? '{'
28
+ error "single quoted string containing a variable found on line #{line_no}"
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,24 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'puppet-lint'
3
+ s.version = '0.0.1'
4
+ s.homepage = 'https://github.com/rodjek/puppet-lint/'
5
+ s.summary = 'Ensure your Puppet manifests conform with the Puppetlabs style guide'
6
+ s.description = 'Checks your Puppet manifests against the Puppetlabs
7
+ style guide and alerts you to any discrepancies.'
8
+
9
+ s.executables = ['puppet-lint']
10
+ s.files = [
11
+ 'bin/puppet-lint',
12
+ 'lib/puppet-lint/plugin.rb',
13
+ 'lib/puppet-lint/plugins/check_strings.rb',
14
+ 'lib/puppet-lint/plugins.rb',
15
+ 'lib/puppet-lint.rb',
16
+ 'puppet-lint.gemspec',
17
+ 'README.md',
18
+ ]
19
+
20
+ s.add_development_dependency 'rspec'
21
+
22
+ s.authors = ['Tim Sharpe']
23
+ s.email = 'tim@sharpe.id.au'
24
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: puppet-lint
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Tim Sharpe
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-08-15 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: rspec
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 0
31
+ version: "0"
32
+ type: :development
33
+ version_requirements: *id001
34
+ description: |-
35
+ Checks your Puppet manifests against the Puppetlabs
36
+ style guide and alerts you to any discrepancies.
37
+ email: tim@sharpe.id.au
38
+ executables:
39
+ - puppet-lint
40
+ extensions: []
41
+
42
+ extra_rdoc_files: []
43
+
44
+ files:
45
+ - bin/puppet-lint
46
+ - lib/puppet-lint/plugin.rb
47
+ - lib/puppet-lint/plugins/check_strings.rb
48
+ - lib/puppet-lint/plugins.rb
49
+ - lib/puppet-lint.rb
50
+ - puppet-lint.gemspec
51
+ - README.md
52
+ homepage: https://github.com/rodjek/puppet-lint/
53
+ licenses: []
54
+
55
+ post_install_message:
56
+ rdoc_options: []
57
+
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ hash: 3
66
+ segments:
67
+ - 0
68
+ version: "0"
69
+ required_rubygems_version: !ruby/object:Gem::Requirement
70
+ none: false
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ hash: 3
75
+ segments:
76
+ - 0
77
+ version: "0"
78
+ requirements: []
79
+
80
+ rubyforge_project:
81
+ rubygems_version: 1.8.6
82
+ signing_key:
83
+ specification_version: 3
84
+ summary: Ensure your Puppet manifests conform with the Puppetlabs style guide
85
+ test_files: []
86
+