puppet-lint 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2011 Tim Sharpe
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require 'rake'
2
+ require 'rspec/core/rake_task'
3
+
4
+ task :default => :test
5
+
6
+ RSpec::Core::RakeTask.new(:test)
data/lib/puppet-lint.rb CHANGED
@@ -5,7 +5,7 @@ require 'puppet'
5
5
  class PuppetLint::NoCodeError < StandardError; end
6
6
 
7
7
  class PuppetLint
8
- VERSION = '0.0.4'
8
+ VERSION = '0.0.5'
9
9
 
10
10
  attr_reader :code, :file
11
11
 
@@ -20,7 +20,9 @@ class PuppetLint::Plugins::CheckResources < PuppetLint::CheckPlugin
20
20
  end
21
21
 
22
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}
23
+ if tokens[token_idx+1].first != :LBRACE
24
+ resource_indexes << {:start => token_idx+1, :end => tokens[token_idx+1..-1].index { |r| [:SEMIC, :RBRACE].include? r.first }+token_idx}
25
+ end
24
26
  end
25
27
  end
26
28
 
@@ -18,6 +18,7 @@ class PuppetLint::Plugins::CheckStrings < PuppetLint::CheckPlugin
18
18
  unless variable_found
19
19
  warn "double quoted string containing no variables on line #{line_no}"
20
20
  end
21
+ line = line[line.index('"', line.index('"')+1)..-1]
21
22
  end
22
23
  end
23
24
 
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.4'
3
+ s.version = '0.0.5'
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
@@ -16,8 +16,13 @@ Gem::Specification.new do |s|
16
16
  'lib/puppet-lint/plugins.rb',
17
17
  'lib/puppet-lint.rb',
18
18
  'lib/tasks/puppet-lint.rake',
19
+ 'LICENSE',
19
20
  'puppet-lint.gemspec',
21
+ 'Rakefile',
20
22
  'README.md',
23
+ 'spec/puppet-lint/check_resources_spec.rb',
24
+ 'spec/puppet-lint/check_strings_spec.rb',
25
+ 'spec/spec_helper.rb',
21
26
  ]
22
27
 
23
28
  s.add_development_dependency 'rspec'
@@ -0,0 +1,145 @@
1
+ require 'spec_helper'
2
+
3
+ describe PuppetLint::Plugins::CheckResources do
4
+ subject do
5
+ klass = described_class.new
6
+ klass.test(code)
7
+ klass
8
+ end
9
+
10
+ describe '3 digit file mode' do
11
+ let(:code) { "file { 'foo': mode => 777 }" }
12
+
13
+ its(:warnings) { should include "mode should be represented as a 4 digit octal value on line 1" }
14
+ its(:errors) { should be_empty }
15
+ end
16
+
17
+ describe '4 digit file mode' do
18
+ let(:code) { "file { 'foo': mode => '0777' }" }
19
+
20
+ its(:warnings) { should be_empty }
21
+ its(:errors) { should be_empty }
22
+ end
23
+
24
+ describe 'ensure as only attr in a single line resource' do
25
+ let(:code) { "file { 'foo': ensure => present }" }
26
+
27
+ its(:warnings) { should be_empty }
28
+ its(:errors) { should be_empty }
29
+ end
30
+
31
+ describe 'ensure as only attr in a multi line resource' do
32
+ let(:code) { "
33
+ file { 'foo':
34
+ ensure => present,
35
+ }"
36
+ }
37
+
38
+ its(:warnings) { should be_empty }
39
+ its(:errors) { should be_empty }
40
+ end
41
+
42
+ describe 'ensure as second attr in a multi line resource' do
43
+ let(:code) { "
44
+ file { 'foo':
45
+ mode => '0000',
46
+ ensure => present,
47
+ }"
48
+ }
49
+
50
+ its(:warnings) { should include "ensure found on line 4 but it's not the first attribute" }
51
+ its(:errors) { should be_empty }
52
+ end
53
+
54
+ describe 'ensure as first attr in a multi line resource' do
55
+ let(:code) { "
56
+ file { 'foo':
57
+ ensure => present,
58
+ mode => '0000',
59
+ }"
60
+ }
61
+
62
+ its(:warnings) { should be_empty }
63
+ its(:errors) { should be_empty }
64
+ end
65
+
66
+ describe 'quoted resource title on single line resource' do
67
+ let(:code) { "file { 'foo': }" }
68
+
69
+ its(:warnings) { should be_empty }
70
+ its(:errors) { should be_empty }
71
+ end
72
+
73
+ describe 'unquoted resource title on single line resource' do
74
+ let(:code) { "file { foo: }" }
75
+
76
+ its(:warnings) { should include "unquoted resource title on line 1" }
77
+ its(:errors) { should be_empty }
78
+ end
79
+
80
+ describe 'quoted resource title on multi line resource' do
81
+ let(:code) { "
82
+ file { 'foo':
83
+ }"
84
+ }
85
+
86
+ its(:warnings) { should be_empty }
87
+ its(:errors) { should be_empty }
88
+ end
89
+
90
+ describe 'unquoted resource title on multi line resource' do
91
+ let(:code) { "
92
+ file { foo:
93
+ }"
94
+ }
95
+
96
+ its(:warnings) { should include "unquoted resource title on line 2" }
97
+ its(:errors) { should be_empty }
98
+ end
99
+
100
+ describe 'condensed resources with quoted titles' do
101
+ let(:code) { "
102
+ file {
103
+ 'foo': ;
104
+ 'bar': ;
105
+ }"
106
+ }
107
+
108
+ its(:warnings) { should be_empty }
109
+ its(:errors) { should be_empty }
110
+ end
111
+
112
+ describe 'condensed resources with an unquoted title' do
113
+ let(:code) { "
114
+ file {
115
+ 'foo': ;
116
+ bar: ;
117
+ }"
118
+ }
119
+
120
+ its(:warnings) { should include "unquoted resource title on line 4" }
121
+ its(:errors) { should be_empty }
122
+ end
123
+
124
+ describe 'single line resource with an array of titles (all quoted)' do
125
+ let(:code) { "file { ['foo', 'bar']: }" }
126
+
127
+ its(:warnings) { should be_empty }
128
+ its(:errors) { should be_empty }
129
+ end
130
+
131
+ describe 'resource inside a case statement' do
132
+ let(:code) { "
133
+ case $ensure {
134
+ 'absent': {
135
+ file { \"some_file_${name}\":
136
+ ensure => absent,
137
+ }
138
+ }
139
+ }"
140
+ }
141
+
142
+ its(:warnings) { should be_empty }
143
+ its(:errors) { should be_empty }
144
+ end
145
+ end
@@ -0,0 +1,23 @@
1
+ require 'spec_helper'
2
+
3
+ describe PuppetLint::Plugins::CheckStrings do
4
+ subject do
5
+ klass = described_class.new
6
+ klass.test(code)
7
+ klass
8
+ end
9
+
10
+ describe 'double quoted string containing a variable insinde single quotes' do
11
+ let(:code) { "exec { \"/usr/bin/wget -O - '${source}' | /usr/bin/apt-key add -\": }" }
12
+
13
+ its(:warnings) { should be_empty }
14
+ its(:errors) { should be_empty }
15
+ end
16
+
17
+ describe 'multiple strings in a line' do
18
+ let(:code) { "\"aoeu\" '${foo}'" }
19
+
20
+ its(:warnings) { should be_empty }
21
+ its(:errors) { should include "single quoted string containing a variable found on line 1" }
22
+ end
23
+ end
@@ -0,0 +1,11 @@
1
+ require 'puppet-lint'
2
+
3
+ #class PuppetLint::Warning < Exception; end
4
+ #class PuppetLint::Error < Exception; end
5
+ #PuppetLint::CheckPlugin.any_instance.stub(:warn) do |arg|
6
+ # raise PuppetLint::Warning
7
+ #end
8
+
9
+ #PuppetLint::CheckPlugin.any_instance.stub(:error) do |arg|
10
+ # raise PuppetLint::Error
11
+ #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: 23
4
+ hash: 21
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 4
10
- version: 0.0.4
9
+ - 5
10
+ version: 0.0.5
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 00:00:00 Z
18
+ date: 2011-08-19 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rspec
@@ -50,8 +50,13 @@ files:
50
50
  - lib/puppet-lint/plugins.rb
51
51
  - lib/puppet-lint.rb
52
52
  - lib/tasks/puppet-lint.rake
53
+ - LICENSE
53
54
  - puppet-lint.gemspec
55
+ - Rakefile
54
56
  - README.md
57
+ - spec/puppet-lint/check_resources_spec.rb
58
+ - spec/puppet-lint/check_strings_spec.rb
59
+ - spec/spec_helper.rb
55
60
  homepage: https://github.com/rodjek/puppet-lint/
56
61
  licenses: []
57
62