puppet-lint 0.1.12 → 0.1.13

Sign up to get free protection for your applications and to get access to all the features.
data/.travis.yml ADDED
@@ -0,0 +1,24 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.2
4
+ - 1.9.3
5
+ branches:
6
+ only:
7
+ - master
8
+ notifications:
9
+ email:
10
+ - tim@github.com
11
+ env:
12
+ - PUPPET_VERSION=2.6.13
13
+ - PUPPET_VERSION=2.7.9
14
+ - PUPPET_VERSION=0.25.4
15
+ matrix:
16
+ exclude:
17
+ - rvm: 1.9.2
18
+ env: PUPPET_VERSION=2.6.13
19
+ - rvm: 1.9.3
20
+ env: PUPPET_VERSION=2.6.13
21
+ - rvm: 1.9.2
22
+ env: PUPPET_VERSION=0.25.4
23
+ - rvm: 1.9.3
24
+ env: PUPPET_VERSION=0.25.4
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source :rubygems
2
+
3
+ puppetversion = ENV.key?('PUPPET_VERSION') ? "= #{ENV['PUPPET_VERSION']}" : ['>= 2.7']
4
+
5
+ gem 'rake'
6
+ gem 'rspec'
7
+ gem 'rdoc'
8
+ gem 'puppet', puppetversion
data/README.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Puppet-lint
2
2
 
3
+ [![Build
4
+ Status](https://secure.travis-ci.org/rodjek/puppet-lint.png)](http://travis-ci.org/rodjek/puppet-lint)
5
+ [![Dependency
6
+ Status](https://gemnasium.com/rodjek/puppet-lint.png)](http://gemnasium.com/rodjek/puppet-lint)
7
+
3
8
  The goal of this project is to implement as many of the recommended Puppet
4
9
  style guidelines from the [Puppet Labs style
5
10
  guide](http://docs.puppetlabs.com/guides/style_guide.html) as practical.
@@ -10,10 +15,14 @@ guide](http://docs.puppetlabs.com/guides/style_guide.html) as practical.
10
15
 
11
16
  ## Testing your manifests
12
17
 
18
+ ### By hand
19
+
13
20
  You can test a single manifest file by running
14
21
 
15
22
  puppet-lint <path to file>
16
23
 
24
+ ### Rake task
25
+
17
26
  If you want to test your entire Puppet manifest directory, you can add
18
27
  `require 'puppet-lint/tasks/puppet-lint'` to your Rakefile and then run
19
28
 
@@ -51,7 +60,7 @@ At the moment, the following tests have been implemented:
51
60
  * Symbolic links should be declared by using an ensure value of `link` and
52
61
  explicitly specifying a value for the `target` attribute.
53
62
  * File modes should be represented as a 4 digit string enclosed in single
54
- quotes.
63
+ quotes or use symbolic file modes.
55
64
 
56
65
  ### Conditionals
57
66
 
@@ -71,10 +80,224 @@ At the moment, the following tests have been implemented:
71
80
  * When using top-scope variables, including facts, Puppet modules should
72
81
  explicitly specify the empty namespace.
73
82
 
83
+ ## Fixing problems
84
+
85
+ ### right_to_left_relationship
86
+
87
+ ```
88
+ WARNING: right-to-left (<-) relationship on line X
89
+ ```
90
+
91
+ While right to left relationships are perfectly valid, it's highly recommended
92
+ that you don't use them as most people think and read from left to right and
93
+ this can lead to confusion.
94
+
95
+ Bad:
96
+
97
+ ```
98
+ Service['httpd'] <- Package['httpd']
99
+ ```
100
+
101
+ Good:
102
+
103
+ ```
104
+ Package['httpd'] -> Service['httpd']
105
+ ```
106
+
107
+ ### autoloader_layout
108
+
109
+ ```
110
+ ERROR: mymodule::myclass not in autoload module layout on line X
111
+ ```
112
+
113
+ Puppet attempts to autoload only the required manifests for the resources and
114
+ classes specified in your manifests. In order to do this, the autoloader
115
+ expects your manifests to be layed out on disk in a particular format. For
116
+ example, when you use `mymodule::myclass` in your manifests, Puppet will
117
+ attempt to read `<modulepath>/mymodule/manifests/myclass.pp`. The only
118
+ exception to this is when you reference `mymodule` itself (without any
119
+ subclass/subtype) in which case it will read
120
+ `<modulepath>/mymodule/manifests/init.pp`.
121
+
122
+ ### parameter_order
123
+
124
+ ```
125
+ WARNING: optional parameter listed before required parameter on line X
126
+ ```
127
+
128
+ In parameterised class and defined type definitions, parameters that are
129
+ required should be listed before optional parameters (those with default
130
+ values).
131
+
132
+ Bad:
133
+
134
+ ```
135
+ class foo($bar='baz', $gronk) {
136
+ ```
137
+
138
+ Good:
139
+
140
+ ```
141
+ class foo($gronk, $bar='baz') {
142
+ ```
143
+
144
+ ### inherits_across_namespaces
145
+
146
+ Placeholder
147
+
148
+ ### nested_classes_or_defines
149
+
150
+ Placeholder
151
+
152
+ ### variable_scope
153
+
154
+ Placeholder
155
+
156
+ ### selector_inside_resource
157
+
158
+ Placeholder
159
+
160
+ ### case_without_default
161
+
162
+ Placeholder
163
+
164
+ ### unquoted_resource_title
165
+
166
+ Placeholder
167
+
168
+ ### ensure_first_param
169
+
170
+ Placeholder
171
+
172
+ ### unquoted_file_mode
173
+
174
+ Placeholder
175
+
176
+ ### 4digit_file_mode
177
+
178
+ Placeholder
179
+
180
+ ### ensure_not_symlink_target
181
+
182
+ Placeholder
183
+
184
+ ### double_quoted_strings
185
+
186
+ Placeholder
187
+
188
+ ### only_variable_string
189
+
190
+ Placeholder
191
+
192
+ ### variables_not_enclosed
193
+
194
+ Placeholder
195
+
196
+ ### single_quote_string_with_variables
197
+
198
+ Placeholder
199
+
200
+ ### quoted_booleans
201
+
202
+ Placeholder
203
+
204
+ ### variable_contains_dash
205
+
206
+ Placeholder
207
+
208
+ ### hard_tabs
209
+
210
+ Placeholder
211
+
212
+ ### trailing_whitespace
213
+
214
+ Placeholder
215
+
216
+ ### 80chars
217
+
218
+ Placeholder
219
+
220
+ ### 2sp_soft_tabs
221
+
222
+ Placeholder
223
+
224
+ ### arrow_alignment
225
+
226
+ Placeholder
227
+
228
+ ## Disabling checks
229
+
230
+ ### puppet-lint
231
+
232
+ You can disable any of the checks when running the `puppet-lint` command by
233
+ adding a `--disable-<check name>` flag to the command. For example, if you
234
+ wanted to skip the 80 character check, you would run
235
+
236
+ ```
237
+ puppet-lint --disable-80chars /path/to/my/manifest.pp
238
+ ```
239
+
240
+ puppet-lint will also check for a `.puppet-lintrc` file in the current
241
+ directory and your home directory and read in flags from there, so if you
242
+ wanted to always skip the hard tab character check, you could create
243
+ `~./puppet-lintrc` containing
244
+
245
+ ```
246
+ --disable-hard_tabs
247
+ ```
248
+
249
+ ### Rake task
250
+
251
+ You can also disable checks when running puppet-lint through the supplied Rake
252
+ task. Simply add the following line after the `require` statement in your
253
+ `Rakefile`.
254
+
255
+ ``` ruby
256
+ PuppetLint.configuration.send("disable_<check name")
257
+ ```
258
+
259
+ So, to disable the 80 character check, you would add:
260
+
261
+ ``` ruby
262
+ PuppetLint.configuration.send("disable_80chars")
263
+ ```
264
+
74
265
  ## Reporting bugs or incorrect results
75
266
 
76
267
  If you find a bug in puppet-lint or its results, please create an issue in the
77
268
  [repo issues tracker](https://github.com/rodjek/puppet-lint/issues/). Bonus
78
269
  points will be awarded if you also include a patch that fixes the issue.
79
270
 
80
- ## Build status
271
+ ## Thank You
272
+
273
+ Many thanks to the following people for contributing to puppet-lint
274
+
275
+ * James Turnbull (@kartar)
276
+ * Jan Vansteenkiste (@vStone)
277
+ * Julian Simpson (@simpsonjulian)
278
+ * S. Zachariah Sprackett (@zsprackett)
279
+
280
+ As well as the many people who have reported the issues they've had!
281
+
282
+ ## License
283
+
284
+ Copyright (c) 2011 Tim Sharpe
285
+
286
+ Permission is hereby granted, free of charge, to any person obtaining
287
+ a copy of this software and associated documentation files (the
288
+ "Software"), to deal in the Software without restriction, including
289
+ without limitation the rights to use, copy, modify, merge, publish,
290
+ distribute, sublicense, and/or sell copies of the Software, and to
291
+ permit persons to whom the Software is furnished to do so, subject to
292
+ the following conditions:
293
+
294
+ The above copyright notice and this permission notice shall be
295
+ included in all copies or substantial portions of the Software.
296
+
297
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
298
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
299
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
300
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
301
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
302
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
303
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/bin/puppet-lint CHANGED
@@ -80,13 +80,21 @@ if ARGV[0].nil?
80
80
  end
81
81
 
82
82
  begin
83
- l = PuppetLint.new
84
- l.file = ARGV[0]
85
- l.run
83
+ path = ARGV[0]
84
+ if File.directory?(path)
85
+ Dir.chdir(path)
86
+ path = Dir.glob('**/*.pp')
87
+ end
86
88
 
87
- if l.errors? or (l.warnings? and PuppetLint.configuration.fail_on_warnings)
88
- exit 1
89
+ path.each do |f|
90
+ l = PuppetLint.new
91
+ l.file = f
92
+ l.run
93
+ if l.errors? or (l.warnings? and PuppetLint.configuration.fail_on_warnings)
94
+ exit 1
95
+ end
89
96
  end
97
+
90
98
  rescue PuppetLint::NoCodeError
91
99
  puts "puppet-lint: no file specified or specified file does not exist"
92
100
  puts "puppet-lint: try 'puppet-lint --help' for more information"
@@ -1,7 +1,9 @@
1
1
  class PuppetLint::Plugins::CheckClasses < PuppetLint::CheckPlugin
2
- check 'right_to_left_relationship' do
3
- tokens.select { |r| r.first == :OUT_EDGE }.each do |token|
4
- notify :warning, :message => "right-to-left (<-) relationship", :linenumber => token.last[:line]
2
+ if Puppet::PUPPETVERSION !~ /^0\.2/
3
+ check 'right_to_left_relationship' do
4
+ tokens.select { |r| r.first == :OUT_EDGE }.each do |token|
5
+ notify :warning, :message => "right-to-left (<-) relationship", :linenumber => token.last[:line]
6
+ end
5
7
  end
6
8
  end
7
9
 
@@ -89,7 +91,7 @@ class PuppetLint::Plugins::CheckClasses < PuppetLint::CheckPlugin
89
91
  check 'variable_scope' do
90
92
  (class_indexes + defined_type_indexes).each do |idx|
91
93
  object_tokens = tokens[idx[:start]..idx[:end]]
92
- variables_in_scope = ['name', 'title', 'module_name']
94
+ variables_in_scope = ['name', 'title', 'module_name', 'environment', 'clientcert', 'clientversion', 'servername', 'serverip', 'serverversion', 'caller_module_name']
93
95
  referenced_variables = []
94
96
  header_end_idx = object_tokens.index { |r| r.first == :LBRACE }
95
97
  lparen_idx = object_tokens[0..header_end_idx].index { |r| r.first == :LPAREN }
@@ -41,7 +41,7 @@ class PuppetLint::Plugins::CheckResources < PuppetLint::CheckPlugin
41
41
  end
42
42
  end
43
43
 
44
- check '4digit_file_mode' do
44
+ check 'file_mode' do
45
45
  resource_indexes.each do |resource|
46
46
  resource_tokens = tokens[resource[:start]..resource[:end]]
47
47
  resource_type_token = tokens[tokens[0..resource[:start]].rindex { |r| r.first == :LBRACE } - 1]
@@ -50,8 +50,8 @@ class PuppetLint::Plugins::CheckResources < PuppetLint::CheckPlugin
50
50
  attr_token = resource_tokens[resource_token_idx]
51
51
  if attr_token.first == :NAME and attr_token.last[:value] == 'mode'
52
52
  value_token = resource_tokens[resource_token_idx + 2]
53
- if value_token.last[:value] !~ /\d{4}/ and value_token.first != :VARIABLE
54
- notify :warning, :message => "mode should be represented as a 4 digit octal value", :linenumber => value_token.last[:line]
53
+ if value_token.last[:value] !~ /\d{4}/ and value_token.first != :VARIABLE and value_token.last[:value] !~ /^([ugoa]*[-=+][-=+rstwxXugo]*)(,[ugoa]*[-=+][-=+rstwxXugo]*)*$/
54
+ notify :warning, :message => "mode should be represented as a 4 digit octal value or symbolic file mode", :linenumber => value_token.last[:line]
55
55
  end
56
56
  end
57
57
  end
@@ -9,8 +9,15 @@ class PuppetLint::Plugins::CheckStrings < PuppetLint::CheckPlugin
9
9
  TOKENS.add_tokens("<single quotes string>" => :SSTRING)
10
10
  TOKENS.del_token(:SQUOTE)
11
11
 
12
- TOKENS.add_token :SQUOTE, "'" do |lexer, value|
13
- [TOKENS[:SSTRING], lexer.slurpstring(value,["'"],:ignore_invalid_escapes).first ]
12
+ if Puppet::PUPPETVERSION =~ /^0\.2/
13
+ TOKENS.add_token :SQUOTE, "'" do |lexer, value|
14
+ value = lexer.slurpstring(value)
15
+ [TOKENS[:SSTRING], value]
16
+ end
17
+ else
18
+ TOKENS.add_token :SQUOTE, "'" do |lexer, value|
19
+ [ TOKENS[:SSTRING], lexer.slurpstring(value,["'"],:ignore_invalid_escapes).first ]
20
+ end
14
21
  end
15
22
  end
16
23
 
@@ -22,6 +29,10 @@ class PuppetLint::Plugins::CheckStrings < PuppetLint::CheckPlugin
22
29
  unless token.last[:value].include? "\t" or token.last[:value].include? "\n"
23
30
  notify :warning, :message => "double quoted string containing no variables", :linenumber => token.last[:line]
24
31
  end
32
+ elsif token.first == :DQTEXT
33
+ unless token.last[:value].include? "\\t" or token.last[:value].include? "\\n" or token.last[:value] =~ /[^\\]?\$\{?/
34
+ notify :warning, :message => "double quoted string containing no variables", :linenumber => token.last[:line]
35
+ end
25
36
  end
26
37
  end
27
38
  end
@@ -37,6 +48,9 @@ class PuppetLint::Plugins::CheckStrings < PuppetLint::CheckPlugin
37
48
  end
38
49
  end
39
50
  end
51
+ if token.first == :DQTEXT and token.last[:value] =~ /\A\$\{.+\}\Z/
52
+ notify :warning, :message => "string containing only a variable", :linenumber => token.last[:line]
53
+ end
40
54
  end
41
55
  end
42
56
 
@@ -54,6 +68,8 @@ class PuppetLint::Plugins::CheckStrings < PuppetLint::CheckPlugin
54
68
  end
55
69
  end
56
70
  end
71
+ elsif token.first == :DQTEXT and token.last[:value] =~ /\$\w+/
72
+ notify :warning, :message => "variable not enclosed in {}", :linenumber => token.last[:line]
57
73
  end
58
74
  end
59
75
  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.12'
3
+ s.version = '0.1.13'
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
@@ -8,7 +8,9 @@ Gem::Specification.new do |s|
8
8
 
9
9
  s.executables = ['puppet-lint']
10
10
  s.files = [
11
+ '.travis.yml',
11
12
  'bin/puppet-lint',
13
+ 'Gemfile',
12
14
  'lib/puppet-lint/configuration.rb',
13
15
  'lib/puppet-lint/plugin.rb',
14
16
  'lib/puppet-lint/plugins/check_classes.rb',
@@ -7,19 +7,21 @@ describe PuppetLint::Plugins::CheckClasses do
7
7
  klass
8
8
  end
9
9
 
10
- describe 'chain 2 resources left to right' do
11
- let(:code) { "Class[foo] -> Class[bar]" }
10
+ if Puppet::PUPPETVERSION !~ /^0\.2/
11
+ describe 'chain 2 resources left to right' do
12
+ let(:code) { "Class[foo] -> Class[bar]" }
12
13
 
13
- its(:problems) { should be_empty }
14
- end
14
+ its(:problems) { should be_empty }
15
+ end
15
16
 
16
- describe 'chain 2 resources right to left' do
17
- let(:code) { "Class[foo] <- Class[bar]" }
17
+ describe 'chain 2 resources right to left' do
18
+ let(:code) { "Class[foo] <- Class[bar]" }
18
19
 
19
- its(:problems) {
20
- should have_problem :kind => :warning, :message => "right-to-left (<-) relationship", :linenumber => 1
21
- should_not have_problem :kind => :error
22
- }
20
+ its(:problems) {
21
+ should have_problem :kind => :warning, :message => "right-to-left (<-) relationship", :linenumber => 1
22
+ should_not have_problem :kind => :error
23
+ }
24
+ end
23
25
  end
24
26
 
25
27
  describe 'class on its own' do
@@ -11,7 +11,7 @@ describe PuppetLint::Plugins::CheckResources do
11
11
  let(:code) { "file { 'foo': mode => 777 }" }
12
12
 
13
13
  its(:problems) {
14
- should have_problem :kind => :warning, :message => "mode should be represented as a 4 digit octal value", :linenumber => 1
14
+ should have_problem :kind => :warning, :message => "mode should be represented as a 4 digit octal value or symbolic file mode", :linenumber => 1
15
15
  should_not have_problem :kind => :error
16
16
  }
17
17
  end
@@ -22,12 +22,27 @@ describe PuppetLint::Plugins::CheckResources do
22
22
  its(:problems) { should be_empty }
23
23
  end
24
24
 
25
+ describe '4 digit unquoted file mode' do
26
+ let(:code) { "file { 'foo': mode => 0777 }" }
27
+
28
+ its(:problems) {
29
+ should have_problem :kind => :warning, :message => "unquoted file mode"
30
+ should_not have_problem :kind => :error
31
+ }
32
+ end
33
+
25
34
  describe 'file mode as a variable' do
26
35
  let(:code) { "file { 'foo': mode => $file_mode }" }
27
36
 
28
37
  its(:problems) { should be_empty }
29
38
  end
30
39
 
40
+ describe 'symbolic file mode' do
41
+ let(:code) { "file { 'foo': mode => 'u=rw,og=r' }" }
42
+
43
+ its(:problems) { should be_empty }
44
+ end
45
+
31
46
  describe 'ensure as only attr in a single line resource' do
32
47
  let(:code) { "file { 'foo': ensure => present }" }
33
48
 
data/spec/spec_helper.rb CHANGED
@@ -86,7 +86,7 @@ RSpec::Matchers.define :only_have_problem do |filter|
86
86
  end
87
87
 
88
88
  failure_message_for_should do |problems|
89
- left = problems - filter_problems(actual, filter)
89
+ left = problems - filter_array_of_hashes(actual, filter)
90
90
  message = "There were problems not matching filter."
91
91
  message << "
92
92
  * filter = #{filter.inspect}
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: 3
4
+ hash: 1
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 12
10
- version: 0.1.12
9
+ - 13
10
+ version: 0.1.13
11
11
  platform: ruby
12
12
  authors:
13
13
  - Tim Sharpe
@@ -15,7 +15,8 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2012-01-27 00:00:00 Z
18
+ date: 2012-03-26 00:00:00 +11:00
19
+ default_executable:
19
20
  dependencies:
20
21
  - !ruby/object:Gem::Dependency
21
22
  name: rspec
@@ -56,7 +57,9 @@ extensions: []
56
57
  extra_rdoc_files: []
57
58
 
58
59
  files:
60
+ - .travis.yml
59
61
  - bin/puppet-lint
62
+ - Gemfile
60
63
  - lib/puppet-lint/configuration.rb
61
64
  - lib/puppet-lint/plugin.rb
62
65
  - lib/puppet-lint/plugins/check_classes.rb
@@ -79,6 +82,7 @@ files:
79
82
  - spec/puppet-lint/check_variables_spec.rb
80
83
  - spec/puppet-lint/check_whitespace_spec.rb
81
84
  - spec/spec_helper.rb
85
+ has_rdoc: true
82
86
  homepage: https://github.com/rodjek/puppet-lint/
83
87
  licenses: []
84
88
 
@@ -108,7 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
112
  requirements: []
109
113
 
110
114
  rubyforge_project:
111
- rubygems_version: 1.8.6
115
+ rubygems_version: 1.6.2
112
116
  signing_key:
113
117
  specification_version: 3
114
118
  summary: Ensure your Puppet manifests conform with the Puppetlabs style guide