Skip to content

Commit

Permalink
Allow parametised classes to be instantiated inside classes
Browse files Browse the repository at this point in the history
Closes #31
Closes #32
  • Loading branch information
rodjek committed Oct 6, 2011
1 parent 3ba0ee8 commit 7d19af8
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 5 deletions.
18 changes: 13 additions & 5 deletions lib/puppet-lint/plugins/check_classes.rb
Expand Up @@ -65,11 +65,19 @@ def test(data)

class_indexes.each do |class_idx|
class_tokens = tokens[class_idx[:start]..class_idx[:end]]
class_tokens[1..-1].select { |r| r.first == :CLASS }.each do |token|
warn "class defined inside a class on line #{token.last[:line]}"
end
class_tokens[1..-1].select { |r| r.first == :DEFINE }.each do |token|
warn "define defined inside a class on line #{token.last[:line]}"
class_tokens[1..-1].each_index do |token_idx|
token = class_tokens[1..-1][token_idx]
next_token = class_tokens[1..-1][token_idx + 1]

if token.first == :CLASS
if next_token.first != :LBRACE
warn "class defined inside a class on line #{token.last[:line]}"
end
end

if token.first == :DEFINE
warn "define defined inside a class on line #{token.last[:line]}"
end
end
end

Expand Down
26 changes: 26 additions & 0 deletions spec/puppet-lint/check_classes_spec.rb
Expand Up @@ -171,4 +171,30 @@ class foo($bar) {
its(:warnings) { should be_empty }
its(:errors) { should be_empty }
end

describe 'instantiating a parametised class inside a class' do
let(:code) { "
class bar {
class { 'foo':
bar => 'foobar'
}
}"
}

its(:warnings) { should be_empty }
its(:errors) { should be_empty }
end

describe 'instantiating a parametised class inside a define' do
let(:code) { "
define bar() {
class { 'foo':
bar => 'foobar'
}
}"
}

its(:warnings) { should be_empty }
its(:errors) { should be_empty }
end
end

0 comments on commit 7d19af8

Please sign in to comment.