puppet-lint 0.0.5 → 0.0.6
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/lib/puppet-lint.rb
CHANGED
@@ -4,8 +4,10 @@
|
|
4
4
|
class PuppetLint::Plugins::CheckWhitespace < PuppetLint::CheckPlugin
|
5
5
|
def test(data)
|
6
6
|
line_no = 0
|
7
|
-
|
8
|
-
|
7
|
+
in_resource = false
|
8
|
+
in_selector = false
|
9
|
+
resource_indent_length = 0
|
10
|
+
selector_indent_length = 0
|
9
11
|
data.split("\n").each do |line|
|
10
12
|
line_no += 1
|
11
13
|
|
@@ -16,7 +18,9 @@ class PuppetLint::Plugins::CheckWhitespace < PuppetLint::CheckPlugin
|
|
16
18
|
error "trailing whitespace found on line #{line_no}" if line.end_with? " "
|
17
19
|
|
18
20
|
# SHOULD NOT exceed an 80 character line width
|
19
|
-
|
21
|
+
unless line =~ /puppet:\/\//
|
22
|
+
warn "line #{line_no} has more than 80 characters" if line.length > 80
|
23
|
+
end
|
20
24
|
|
21
25
|
# MUST use two-space soft tabs
|
22
26
|
line.scan(/^ +/) do |prefix|
|
@@ -27,17 +31,33 @@ class PuppetLint::Plugins::CheckWhitespace < PuppetLint::CheckPlugin
|
|
27
31
|
|
28
32
|
# SHOULD align fat comma arrows (=>) within blocks of attributes
|
29
33
|
if line =~ /^( +\w+ +)=>/
|
30
|
-
|
31
|
-
|
32
|
-
|
34
|
+
line_indent = $1
|
35
|
+
if in_resource
|
36
|
+
if in_selector
|
37
|
+
unless line_indent.length == selector_indent_length
|
38
|
+
warn "=> on line #{line_no} isn't aligned with the previous line"
|
39
|
+
end
|
40
|
+
|
41
|
+
if line.strip =~ /\}[,;]?$/
|
42
|
+
in_selector = false
|
43
|
+
selector_indent_length = 0
|
44
|
+
end
|
45
|
+
else
|
46
|
+
if line.strip.end_with? "{"
|
47
|
+
in_selector = true
|
48
|
+
selector_indent_length = resource_indent_length + 2
|
49
|
+
end
|
50
|
+
unless line_indent.length == resource_indent_length
|
51
|
+
warn "=> on line #{line_no} isn't aligned with the previous line"
|
52
|
+
end
|
33
53
|
end
|
34
54
|
else
|
35
|
-
|
36
|
-
|
55
|
+
resource_indent_length = line_indent.length
|
56
|
+
in_resource = true
|
37
57
|
end
|
38
58
|
else
|
39
|
-
|
40
|
-
|
59
|
+
in_resource = false
|
60
|
+
resource_indent_length = 0
|
41
61
|
end
|
42
62
|
end
|
43
63
|
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.6'
|
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
|
@@ -22,6 +22,7 @@ Gem::Specification.new do |s|
|
|
22
22
|
'README.md',
|
23
23
|
'spec/puppet-lint/check_resources_spec.rb',
|
24
24
|
'spec/puppet-lint/check_strings_spec.rb',
|
25
|
+
'spec/puppet-lint/check_whitespace_spec.rb',
|
25
26
|
'spec/spec_helper.rb',
|
26
27
|
]
|
27
28
|
|
@@ -17,7 +17,7 @@ describe PuppetLint::Plugins::CheckStrings do
|
|
17
17
|
describe 'multiple strings in a line' do
|
18
18
|
let(:code) { "\"aoeu\" '${foo}'" }
|
19
19
|
|
20
|
-
its(:warnings) { should
|
20
|
+
its(:warnings) { should include "double quoted string containing no variables on line 1" }
|
21
21
|
its(:errors) { should include "single quoted string containing a variable found on line 1" }
|
22
22
|
end
|
23
23
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe PuppetLint::Plugins::CheckWhitespace do
|
4
|
+
subject do
|
5
|
+
klass = described_class.new
|
6
|
+
klass.test(code)
|
7
|
+
klass
|
8
|
+
end
|
9
|
+
|
10
|
+
describe 'selectors inside a resource' do
|
11
|
+
let(:code) { "
|
12
|
+
file { 'foo':
|
13
|
+
ensure => $ensure,
|
14
|
+
require => $ensure ? {
|
15
|
+
present => Class['tomcat::install'],
|
16
|
+
absent => undef,
|
17
|
+
},
|
18
|
+
}"
|
19
|
+
}
|
20
|
+
|
21
|
+
its(:warnings) { should be_empty }
|
22
|
+
its(:errors) { should be_empty }
|
23
|
+
end
|
24
|
+
|
25
|
+
describe 'file resource with a source line > 80c' do
|
26
|
+
let(:code) { "
|
27
|
+
file {
|
28
|
+
source => 'puppet:///modules/certificates/etc/ssl/private/wildcard.example.com.crt',
|
29
|
+
}"
|
30
|
+
}
|
31
|
+
|
32
|
+
its(:warnings) { should be_empty }
|
33
|
+
its(:errors) { should be_empty }
|
34
|
+
end
|
35
|
+
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: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 6
|
10
|
+
version: 0.0.6
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Tim Sharpe
|
@@ -56,6 +56,7 @@ files:
|
|
56
56
|
- README.md
|
57
57
|
- spec/puppet-lint/check_resources_spec.rb
|
58
58
|
- spec/puppet-lint/check_strings_spec.rb
|
59
|
+
- spec/puppet-lint/check_whitespace_spec.rb
|
59
60
|
- spec/spec_helper.rb
|
60
61
|
homepage: https://github.com/rodjek/puppet-lint/
|
61
62
|
licenses: []
|