puppet-lint 0.0.3 → 0.0.4
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.
- data/bin/puppet-lint +9 -3
- data/lib/puppet-lint.rb +9 -1
- data/lib/puppet-lint/plugin.rb +1 -0
- data/lib/puppet-lint/plugins/check_resources.rb +42 -34
- data/puppet-lint.gemspec +1 -1
- metadata +4 -4
data/bin/puppet-lint
CHANGED
@@ -41,7 +41,13 @@ if ARGV[0].nil?
|
|
41
41
|
exit
|
42
42
|
end
|
43
43
|
|
44
|
-
|
45
|
-
l
|
46
|
-
l.
|
44
|
+
begin
|
45
|
+
l = PuppetLint.new
|
46
|
+
l.file = ARGV[0]
|
47
|
+
l.run
|
48
|
+
rescue PuppetLint::NoCodeError
|
49
|
+
puts "puppet-lint: no file specified or specified file does not exist"
|
50
|
+
puts "puppet-lint: try 'puppet-lint --help' for more information"
|
51
|
+
exit
|
52
|
+
end
|
47
53
|
|
data/lib/puppet-lint.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
1
|
require 'puppet-lint/plugin'
|
2
2
|
require 'puppet-lint/plugins'
|
3
|
+
require 'puppet'
|
4
|
+
|
5
|
+
class PuppetLint::NoCodeError < StandardError; end
|
3
6
|
|
4
7
|
class PuppetLint
|
5
|
-
VERSION = '0.0.
|
8
|
+
VERSION = '0.0.4'
|
6
9
|
|
7
10
|
attr_reader :code, :file
|
8
11
|
|
@@ -41,6 +44,10 @@ class PuppetLint
|
|
41
44
|
end
|
42
45
|
|
43
46
|
def run
|
47
|
+
if @data.nil?
|
48
|
+
raise PuppetLint::NoCodeError
|
49
|
+
end
|
50
|
+
|
44
51
|
PuppetLint::CheckPlugin.repository.each do |plugin|
|
45
52
|
problems = plugin.new.run(@data)
|
46
53
|
problems[:errors].each { |error| report :errors, error }
|
@@ -48,3 +55,4 @@ class PuppetLint
|
|
48
55
|
end
|
49
56
|
end
|
50
57
|
end
|
58
|
+
|
data/lib/puppet-lint/plugin.rb
CHANGED
@@ -3,50 +3,58 @@
|
|
3
3
|
|
4
4
|
class PuppetLint::Plugins::CheckResources < PuppetLint::CheckPlugin
|
5
5
|
def test(data)
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
data.split("\n").each do |line|
|
10
|
-
line_no += 1
|
6
|
+
lexer = Puppet::Parser::Lexer.new
|
7
|
+
lexer.string = data
|
8
|
+
tokens = lexer.fullscan
|
11
9
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
10
|
+
title_tokens = []
|
11
|
+
resource_indexes = []
|
12
|
+
tokens.each_index do |token_idx|
|
13
|
+
if tokens[token_idx].first == :COLON
|
14
|
+
# gather a list of tokens that are resource titles
|
15
|
+
if tokens[token_idx-1].first == :RBRACK
|
16
|
+
title_array_tokens = tokens[tokens.rindex { |r| r.first == :LBRACK }+1..token_idx-2]
|
17
|
+
title_tokens += title_array_tokens.select { |token| [:STRING, :NAME].include? token.first }
|
18
|
+
else
|
19
|
+
title_tokens << tokens[token_idx-1]
|
20
|
+
end
|
21
|
+
|
22
|
+
# gather a list of start and end indexes for resource attribute blocks
|
23
|
+
resource_indexes << {:start => token_idx+1, :end => tokens[token_idx+1..-1].index { |r| [:SEMIC, :RBRACE].include? r.first }+token_idx}
|
16
24
|
end
|
25
|
+
end
|
17
26
|
|
18
|
-
|
19
|
-
|
20
|
-
line.
|
21
|
-
|
22
|
-
|
23
|
-
|
27
|
+
title_tokens.each do |token|
|
28
|
+
if token.first == :NAME
|
29
|
+
warn "unquoted resource title on line #{token.last[:line]}"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
resource_indexes.each do |resource|
|
34
|
+
resource_tokens = tokens[resource[:start]..resource[:end]]
|
35
|
+
ensure_attr_index = resource_tokens.index { |token| token.first == :NAME and token.last[:value] == 'ensure' }
|
36
|
+
unless ensure_attr_index.nil?
|
37
|
+
if ensure_attr_index > 1
|
38
|
+
ensure_attr_line_no = resource_tokens[ensure_attr_index].last[:line]
|
39
|
+
warn "ensure found on line #{ensure_attr_line_no} but it's not the first attribute"
|
24
40
|
end
|
41
|
+
end
|
25
42
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
43
|
+
resource_type_token = tokens[tokens[0..resource[:start]].rindex { |r| r.first == :LBRACE } - 1]
|
44
|
+
if resource_type_token.last[:value] == "file"
|
45
|
+
resource_tokens.each_index do |resource_token_idx|
|
46
|
+
attr_token = resource_tokens[resource_token_idx]
|
47
|
+
if attr_token.first == :NAME and attr_token.last[:value] == 'mode'
|
48
|
+
value_token = resource_tokens[resource_token_idx + 2]
|
49
|
+
if value_token.first == :NAME
|
50
|
+
warn "unquoted file mode on line #{value_token.last[:line]}"
|
31
51
|
end
|
32
|
-
|
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}"
|
52
|
+
if value_token.last[:value] !~ /\d{4}/
|
53
|
+
warn "mode should be represented as a 4 digit octal value on line #{value_token.last[:line]}"
|
39
54
|
end
|
40
55
|
end
|
41
|
-
|
42
|
-
first_attribute = false
|
43
56
|
end
|
44
57
|
end
|
45
|
-
|
46
|
-
if line.include? "}"
|
47
|
-
in_resource = false
|
48
|
-
first_attribute = false
|
49
|
-
end
|
50
58
|
end
|
51
59
|
end
|
52
60
|
end
|
data/puppet-lint.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'puppet-lint'
|
3
|
-
s.version = '0.0.
|
3
|
+
s.version = '0.0.4'
|
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
|
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:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 4
|
10
|
+
version: 0.0.4
|
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-
|
18
|
+
date: 2011-08-18 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: rspec
|