puppet-lint 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/puppet-lint.rb +1 -1
- data/lib/puppet-lint/bin.rb +7 -3
- data/lib/puppet-lint/lexer.rb +18 -5
- data/lib/puppet-lint/plugin.rb +11 -2
- data/lib/puppet-lint/plugins/check_classes.rb +2 -2
- data/lib/puppet-lint/version.rb +1 -1
- data/spec/fixtures/test/manifests/malformed.pp +1 -0
- data/spec/puppet-lint/bin_spec.rb +7 -0
- data/spec/puppet-lint/lexer_spec.rb +8 -0
- data/spec/puppet-lint/plugins/check_classes/class_parameter_defaults_spec.rb +27 -2
- data/spec/puppet-lint_spec.rb +10 -0
- metadata +64 -76
data/lib/puppet-lint.rb
CHANGED
data/lib/puppet-lint/bin.rb
CHANGED
@@ -67,10 +67,14 @@ class PuppetLint::Bin
|
|
67
67
|
end
|
68
68
|
|
69
69
|
opts.load('/etc/puppet-lint.rc')
|
70
|
-
|
71
|
-
if
|
72
|
-
|
70
|
+
|
71
|
+
if ENV['HOME']
|
72
|
+
opts.load(File.expand_path('~/.puppet-lint.rc'))
|
73
|
+
if opts.load(File.expand_path('~/.puppet-lintrc'))
|
74
|
+
$stderr.puts 'Depreciated: Found ~/.puppet-lintrc instead of ~/.puppet-lint.rc'
|
75
|
+
end
|
73
76
|
end
|
77
|
+
|
74
78
|
opts.load('.puppet-lint.rc')
|
75
79
|
if opts.load('.puppet-lintrc')
|
76
80
|
$stderr.puts 'Depreciated: Read .puppet-lintrc instead of .puppet-lint.rc'
|
data/lib/puppet-lint/lexer.rb
CHANGED
@@ -4,7 +4,20 @@ require 'puppet-lint/lexer/token'
|
|
4
4
|
require 'set'
|
5
5
|
|
6
6
|
class PuppetLint
|
7
|
-
class LexerError <
|
7
|
+
class LexerError < StandardError
|
8
|
+
attr_reader :line_no, :column
|
9
|
+
def initialize(code, offset)
|
10
|
+
chunk = code[0..offset]
|
11
|
+
@line_no = chunk.count("\n") + 1
|
12
|
+
if @line_no == 1
|
13
|
+
@column = chunk.length
|
14
|
+
else
|
15
|
+
@column = chunk.length - chunk.rindex("\n") - 1
|
16
|
+
end
|
17
|
+
@column = 1 if @column == 0
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
8
21
|
class Lexer
|
9
22
|
KEYWORDS = {
|
10
23
|
'class' => true,
|
@@ -126,12 +139,12 @@ class PuppetLint
|
|
126
139
|
i += var_name.size + 1
|
127
140
|
|
128
141
|
elsif chunk.match(/\A'(.*?)'/m)
|
129
|
-
str_content = StringScanner.new(code[i+1..-1]).scan_until(/(\A
|
142
|
+
str_content = StringScanner.new(code[i+1..-1]).scan_until(/(\A|[^\\])(\\\\)*'/m)
|
130
143
|
tokens << new_token(:SSTRING, str_content[0..-2], :chunk => code[0..i])
|
131
144
|
i += str_content.size + 1
|
132
145
|
|
133
146
|
elsif chunk.match(/\A"/)
|
134
|
-
str_contents = StringScanner.new(code[i+1..-1]).scan_until(/(\A
|
147
|
+
str_contents = StringScanner.new(code[i+1..-1]).scan_until(/(\A|[^\\])(\\\\)*"/m)
|
135
148
|
_ = code[0..i].split("\n")
|
136
149
|
interpolate_string(str_contents, _.count, _.last.length)
|
137
150
|
i += str_contents.size + 1
|
@@ -159,7 +172,7 @@ class PuppetLint
|
|
159
172
|
i += mlcomment_size
|
160
173
|
|
161
174
|
elsif chunk.match(/\A\/.*?\//) && possible_regex?
|
162
|
-
str_content = StringScanner.new(code[i+1..-1]).scan_until(/(\A
|
175
|
+
str_content = StringScanner.new(code[i+1..-1]).scan_until(/(\A|[^\\])(\\\\)*\//m)
|
163
176
|
tokens << new_token(:REGEX, str_content[0..-2], :chunk => code[0..i])
|
164
177
|
i += str_content.size + 1
|
165
178
|
|
@@ -181,7 +194,7 @@ class PuppetLint
|
|
181
194
|
i += 1
|
182
195
|
|
183
196
|
else
|
184
|
-
raise PuppetLint::LexerError,
|
197
|
+
raise PuppetLint::LexerError.new(code, i)
|
185
198
|
end
|
186
199
|
end
|
187
200
|
end
|
data/lib/puppet-lint/plugin.rb
CHANGED
@@ -4,7 +4,7 @@ class PuppetLint::Checks
|
|
4
4
|
|
5
5
|
def initialize
|
6
6
|
@problems = []
|
7
|
-
@default_info = {:check => 'unknown', :linenumber => 0}
|
7
|
+
@default_info = {:check => 'unknown', :linenumber => 0, :column => 0}
|
8
8
|
|
9
9
|
PuppetLint.configuration.checks.each do |check|
|
10
10
|
method = PuppetLint.configuration.check_method[check]
|
@@ -36,7 +36,16 @@ class PuppetLint::Checks
|
|
36
36
|
|
37
37
|
def load_data(fileinfo, data)
|
38
38
|
lexer = PuppetLint::Lexer.new
|
39
|
-
|
39
|
+
begin
|
40
|
+
@tokens = lexer.tokenise(data)
|
41
|
+
rescue PuppetLint::LexerError => e
|
42
|
+
notify :error, {
|
43
|
+
:message => 'Syntax error (try running `puppet parser validate <file>`)',
|
44
|
+
:linenumber => e.line_no,
|
45
|
+
:column => e.column,
|
46
|
+
}
|
47
|
+
@tokens = []
|
48
|
+
end
|
40
49
|
@fileinfo = fileinfo
|
41
50
|
@data = data
|
42
51
|
end
|
@@ -116,8 +116,8 @@ class PuppetLint::Plugins::CheckClasses < PuppetLint::CheckPlugin
|
|
116
116
|
paren_stack = []
|
117
117
|
param_tokens.each_index do |param_tokens_idx|
|
118
118
|
this_token = param_tokens[param_tokens_idx]
|
119
|
-
next_token =
|
120
|
-
prev_token =
|
119
|
+
next_token = this_token.next_code_token
|
120
|
+
prev_token = this_token.prev_code_token
|
121
121
|
|
122
122
|
if this_token.type == :LPAREN
|
123
123
|
paren_stack.push(true)
|
data/lib/puppet-lint/version.rb
CHANGED
@@ -0,0 +1 @@
|
|
1
|
+
class { 'apacheds': master => true' }
|
@@ -67,6 +67,13 @@ describe PuppetLint::Bin do
|
|
67
67
|
].join("\n") }
|
68
68
|
end
|
69
69
|
|
70
|
+
context 'when passed a malformed file' do
|
71
|
+
let(:args) { 'spec/fixtures/test/manifests/malformed.pp' }
|
72
|
+
|
73
|
+
its(:exitstatus) { should == 1 }
|
74
|
+
its(:stdout) { should == 'ERROR: Syntax error (try running `puppet parser validate <file>`) on line 1' }
|
75
|
+
end
|
76
|
+
|
70
77
|
context 'when limited to errors only' do
|
71
78
|
let(:args) { [
|
72
79
|
'--error-level', 'error',
|
@@ -741,4 +741,12 @@ describe PuppetLint::Lexer do
|
|
741
741
|
tokens.select { |r| r.type == :REGEX }.should == []
|
742
742
|
end
|
743
743
|
end
|
744
|
+
|
745
|
+
context ':STRING' do
|
746
|
+
it 'should parse strings with \\\\\\' do
|
747
|
+
expect {
|
748
|
+
@lexer.tokenise("exec { \"/bin/echo \\\\\\\"${environment}\\\\\\\"\": }")
|
749
|
+
}.to_not raise_error(PuppetLint::LexerError)
|
750
|
+
end
|
751
|
+
end
|
744
752
|
end
|
@@ -6,14 +6,39 @@ describe 'class_parameter_defaults' do
|
|
6
6
|
|
7
7
|
its(:problems) {
|
8
8
|
should only_have_problem({
|
9
|
-
:kind
|
10
|
-
:message
|
9
|
+
:kind => :warning,
|
10
|
+
:message => 'parameterised class parameter without a default value',
|
11
11
|
:linenumber => 1,
|
12
12
|
:column => 11,
|
13
13
|
})
|
14
14
|
}
|
15
15
|
end
|
16
16
|
|
17
|
+
describe 'parameterised class with multiple params with a default value' do
|
18
|
+
let(:code) { "class foo($bar, $baz, $gronk) { }" }
|
19
|
+
|
20
|
+
its(:problems) do
|
21
|
+
should have_problem({
|
22
|
+
:kind => :warning,
|
23
|
+
:message => 'parameterised class parameter without a default value',
|
24
|
+
:linenumber => 1,
|
25
|
+
:column => 11,
|
26
|
+
})
|
27
|
+
should have_problem({
|
28
|
+
:kind => :warning,
|
29
|
+
:message => 'parameterised class parameter without a default value',
|
30
|
+
:linenumber => 1,
|
31
|
+
:column => 17,
|
32
|
+
})
|
33
|
+
should have_problem({
|
34
|
+
:kind => :warning,
|
35
|
+
:message => 'parameterised class parameter without a default value',
|
36
|
+
:linenumber => 1,
|
37
|
+
:column => 23,
|
38
|
+
})
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
17
42
|
describe 'class without parameters' do
|
18
43
|
let(:code) {"
|
19
44
|
class myclass {
|
data/spec/puppet-lint_spec.rb
CHANGED
@@ -7,4 +7,14 @@ describe PuppetLint do
|
|
7
7
|
subject.code = "class foo { }"
|
8
8
|
subject.data.should_not be_nil
|
9
9
|
end
|
10
|
+
|
11
|
+
it 'should have support for % with a hash' do
|
12
|
+
string = 'replace %{hash}' % {:hash => 'replaced'}
|
13
|
+
string.should match 'replace replaced'
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'should not break regular % support' do
|
17
|
+
string = 'replace %s %s' % ['get','replaced']
|
18
|
+
string.should match 'replace get replaced'
|
19
|
+
end
|
10
20
|
end
|
metadata
CHANGED
@@ -1,76 +1,72 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: puppet-lint
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.2
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 3
|
9
|
-
- 1
|
10
|
-
version: 0.3.1
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Tim Sharpe
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
dependencies:
|
21
|
-
- !ruby/object:Gem::Dependency
|
12
|
+
date: 2012-10-19 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
22
15
|
name: rspec
|
23
|
-
|
24
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
25
17
|
none: false
|
26
|
-
requirements:
|
27
|
-
- -
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
|
30
|
-
segments:
|
31
|
-
- 0
|
32
|
-
version: "0"
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
33
22
|
type: :development
|
34
|
-
version_requirements: *id001
|
35
|
-
- !ruby/object:Gem::Dependency
|
36
|
-
name: rdoc
|
37
23
|
prerelease: false
|
38
|
-
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
39
25
|
none: false
|
40
|
-
requirements:
|
41
|
-
- -
|
42
|
-
- !ruby/object:Gem::Version
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rdoc
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
47
38
|
type: :development
|
48
|
-
version_requirements: *id002
|
49
|
-
- !ruby/object:Gem::Dependency
|
50
|
-
name: rcov
|
51
39
|
prerelease: false
|
52
|
-
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
53
41
|
none: false
|
54
|
-
requirements:
|
55
|
-
- -
|
56
|
-
- !ruby/object:Gem::Version
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rcov
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '0'
|
61
54
|
type: :development
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
description: ! "Checks your Puppet manifests against the Puppetlabs\n style guide
|
63
|
+
and alerts you to any discrepancies."
|
66
64
|
email: tim@sharpe.id.au
|
67
|
-
executables:
|
65
|
+
executables:
|
68
66
|
- puppet-lint
|
69
67
|
extensions: []
|
70
|
-
|
71
68
|
extra_rdoc_files: []
|
72
|
-
|
73
|
-
files:
|
69
|
+
files:
|
74
70
|
- .gitignore
|
75
71
|
- .travis.yml
|
76
72
|
- Gemfile
|
@@ -98,6 +94,7 @@ files:
|
|
98
94
|
- puppet-lint.gemspec
|
99
95
|
- spec/fixtures/test/manifests/fail.pp
|
100
96
|
- spec/fixtures/test/manifests/init.pp
|
97
|
+
- spec/fixtures/test/manifests/malformed.pp
|
101
98
|
- spec/fixtures/test/manifests/warning.pp
|
102
99
|
- spec/puppet-lint/bin_spec.rb
|
103
100
|
- spec/puppet-lint/configuration_spec.rb
|
@@ -136,43 +133,34 @@ files:
|
|
136
133
|
- spec/puppet-lint/plugins/check_whitespace/trailing_whitespace_spec.rb
|
137
134
|
- spec/puppet-lint_spec.rb
|
138
135
|
- spec/spec_helper.rb
|
139
|
-
has_rdoc: true
|
140
136
|
homepage: https://github.com/rodjek/puppet-lint/
|
141
137
|
licenses: []
|
142
|
-
|
143
138
|
post_install_message:
|
144
139
|
rdoc_options: []
|
145
|
-
|
146
|
-
require_paths:
|
140
|
+
require_paths:
|
147
141
|
- lib
|
148
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
142
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
149
143
|
none: false
|
150
|
-
requirements:
|
151
|
-
- -
|
152
|
-
- !ruby/object:Gem::Version
|
153
|
-
|
154
|
-
|
155
|
-
- 0
|
156
|
-
version: "0"
|
157
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
144
|
+
requirements:
|
145
|
+
- - ! '>='
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: '0'
|
148
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
158
149
|
none: false
|
159
|
-
requirements:
|
160
|
-
- -
|
161
|
-
- !ruby/object:Gem::Version
|
162
|
-
|
163
|
-
segments:
|
164
|
-
- 0
|
165
|
-
version: "0"
|
150
|
+
requirements:
|
151
|
+
- - ! '>='
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: '0'
|
166
154
|
requirements: []
|
167
|
-
|
168
155
|
rubyforge_project:
|
169
|
-
rubygems_version: 1.
|
156
|
+
rubygems_version: 1.8.23
|
170
157
|
signing_key:
|
171
158
|
specification_version: 3
|
172
159
|
summary: Ensure your Puppet manifests conform with the Puppetlabs style guide
|
173
|
-
test_files:
|
160
|
+
test_files:
|
174
161
|
- spec/fixtures/test/manifests/fail.pp
|
175
162
|
- spec/fixtures/test/manifests/init.pp
|
163
|
+
- spec/fixtures/test/manifests/malformed.pp
|
176
164
|
- spec/fixtures/test/manifests/warning.pp
|
177
165
|
- spec/puppet-lint/bin_spec.rb
|
178
166
|
- spec/puppet-lint/configuration_spec.rb
|