puppet-lint 0.1.1 → 0.1.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.
- data/README.md +2 -2
- data/lib/puppet-lint.rb +1 -1
- data/lib/puppet-lint/plugins/check_strings.rb +48 -27
- data/puppet-lint.gemspec +1 -1
- data/spec/puppet-lint/check_strings_spec.rb +21 -0
- metadata +4 -4
data/README.md
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# Puppet-lint
|
2
2
|
|
3
3
|
The goal of this project is to implement as many of the recommended Puppet
|
4
|
-
style guidelines from the [
|
4
|
+
style guidelines from the [Puppet Labs style
|
5
5
|
guide](http://docs.puppetlabs.com/guides/style_guide.html) as practical.
|
6
6
|
|
7
7
|
## Installation
|
@@ -67,7 +67,7 @@ At the moment, the following tests have been implemented:
|
|
67
67
|
* Classes should not inherit between namespaces.
|
68
68
|
* Required parameters in class & defined type definitions should be listed
|
69
69
|
before optional parameters.
|
70
|
-
|
70
|
+
* When using top-scope variables, including facts, Puppet modules should
|
71
71
|
explicitly specify the empty namespace.
|
72
72
|
|
73
73
|
## Reporting bugs or incorrect results
|
data/lib/puppet-lint.rb
CHANGED
@@ -1,40 +1,61 @@
|
|
1
|
+
require 'puppet'
|
2
|
+
|
1
3
|
class PuppetLint::Plugins::CheckStrings < PuppetLint::CheckPlugin
|
4
|
+
class ::Puppet::Parser::Lexer
|
5
|
+
class TokenList
|
6
|
+
def del_token(token)
|
7
|
+
@tokens.delete(token)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
TOKENS.add_tokens("<single quotes string>" => :SSTRING)
|
12
|
+
TOKENS.del_token(:SQUOTE)
|
13
|
+
|
14
|
+
TOKENS.add_token :SQUOTE, "'" do |lexer, value|
|
15
|
+
[TOKENS[:SSTRING], lexer.slurpstring(value,["'"],:ignore_invalid_escapes).first ]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
2
19
|
def test(data)
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
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
|
-
if s =~ /^"\$\{[\w\:]+\}"$/
|
22
|
-
warn "string containing only a variable on line #{line_no}"
|
23
|
-
end
|
20
|
+
l = Puppet::Parser::Lexer.new
|
21
|
+
l.string = data
|
22
|
+
tokens = l.fullscan
|
23
|
+
|
24
|
+
tokens.each_index do |token_idx|
|
25
|
+
token = tokens[token_idx]
|
26
|
+
|
27
|
+
if token.first == :STRING
|
28
|
+
warn "double quoted string containing no variables on line #{token.last[:line]}"
|
29
|
+
end
|
24
30
|
|
25
|
-
|
31
|
+
if token.first == :DQPRE and token.last[:value] == ""
|
32
|
+
if tokens[token_idx + 1].first == :VARIABLE
|
33
|
+
if tokens[token_idx + 2].first == :DQPOST and tokens[token_idx + 2].last[:value] == ""
|
34
|
+
warn "string containing only a variable on line #{tokens[token_idx + 1].last[:line]}"
|
35
|
+
end
|
26
36
|
end
|
27
37
|
end
|
28
38
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
39
|
+
if token.first == :DQPRE
|
40
|
+
end_of_string_idx = tokens[token_idx..-1].index { |r| r.first == :DQPOST }
|
41
|
+
tokens[token_idx..end_of_string_idx].each do |t|
|
42
|
+
if t.first == :VARIABLE
|
43
|
+
line = data.split("\n")[t.last[:line] - 1]
|
44
|
+
if line.is_a? String and line.include? "$#{t.last[:value]}"
|
45
|
+
warn "variable not enclosed in {} on line #{t.last[:line]}"
|
34
46
|
end
|
35
47
|
end
|
36
48
|
end
|
37
49
|
end
|
50
|
+
|
51
|
+
if token.first == :SSTRING
|
52
|
+
contents = token.last[:value]
|
53
|
+
line_no = token.last[:line]
|
54
|
+
|
55
|
+
if contents.include? '${'
|
56
|
+
error "single quoted string containing a variable found on line #{token.last[:line]}"
|
57
|
+
end
|
58
|
+
end
|
38
59
|
end
|
39
60
|
end
|
40
61
|
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.1.
|
3
|
+
s.version = '0.1.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
|
@@ -27,4 +27,25 @@ describe PuppetLint::Plugins::CheckStrings do
|
|
27
27
|
its(:warnings) { should include "string containing only a variable on line 1" }
|
28
28
|
its(:errors) { should be_empty }
|
29
29
|
end
|
30
|
+
|
31
|
+
describe 'variable not enclosed in {}' do
|
32
|
+
let(:code) { '" $gronk"' }
|
33
|
+
|
34
|
+
its(:warnings) { should include "variable not enclosed in {} on line 1" }
|
35
|
+
its(:errors) { should be_empty }
|
36
|
+
end
|
37
|
+
|
38
|
+
describe 'double quoted string nested in a single quoted string' do
|
39
|
+
let(:code) { "'grep \"status=sent\" /var/log/mail.log'" }
|
40
|
+
|
41
|
+
its(:warnings) { should be_empty }
|
42
|
+
its(:errors) { should be_empty }
|
43
|
+
end
|
44
|
+
|
45
|
+
describe 'double quoted string after a comment' do
|
46
|
+
let(:code) { "service { 'foo': } # \"bar\"" }
|
47
|
+
|
48
|
+
its(:warnings) { should be_empty }
|
49
|
+
its(:errors) { should be_empty }
|
50
|
+
end
|
30
51
|
end
|
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: 31
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 2
|
10
|
+
version: 0.1.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-09-
|
18
|
+
date: 2011-09-09 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: rspec
|