Skip to content

Commit

Permalink
Adding support for checking the contain and require functions
Browse files Browse the repository at this point in the history
Relative class inclusion can also occur using the contain and require
functions in addition to the include function. This commit adds support
for testing the use of those functions.

Fixes #1.
  • Loading branch information
liamjbennett committed Mar 15, 2016
1 parent 5934614 commit 47c47f0
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/puppet-lint/plugins/check_absolute_classname.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PuppetLint.new_check(:relative_classname_inclusion) do
def check
tokens.each_with_index do |token, token_idx|
if token.type == :NAME && token.value == 'include'
if token.type == :NAME && ['include','contain','require'].include?(token.value)
s = token.next_code_token
in_function = 0
while s.type != :NEWLINE
Expand Down
2 changes: 1 addition & 1 deletion puppet-lint-absolute_classname-check.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'rspec-collection_matchers', '~> 1.0'
spec.add_development_dependency 'mime-types', '~> 1.0' # 2.x dropped Ruby 1.8 support
spec.add_development_dependency 'coveralls', '~> 0.7' unless RUBY_VERSION =~ /^1\.8/
spec.add_development_dependency 'rake'
spec.add_development_dependency 'rake', '~> 10.5' # 11.x dropped Ruby 1.8 support
end
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ class { '::foobar': }
class foobar {
}
contain ::foobar
contain('::foobar')
contain(foobar(baz))
contain(foobar('baz'))
require ::foobar
require('::foobar')
require(foobar(baz))
require(foobar('baz'))
EOS
end

Expand All @@ -33,17 +43,25 @@ class foobar {
include foobar
include(foobar)
class { 'foobar': }
contain foobar
contain(foobar)
require foobar
require(foobar)
EOS
end

it 'should detect 3 problems' do
expect(problems).to have(3).problems
it 'should detect 7 problems' do
expect(problems).to have(7).problems
end

it 'should create warnings' do
expect(problems).to contain_warning(msg).on_line(1).in_column(17)
expect(problems).to contain_warning(msg).on_line(2).in_column(17)
expect(problems).to contain_warning(msg).on_line(3).in_column(17)
expect(problems).to contain_warning(msg).on_line(4).in_column(17)
expect(problems).to contain_warning(msg).on_line(5).in_column(17)
expect(problems).to contain_warning(msg).on_line(6).in_column(17)
expect(problems).to contain_warning(msg).on_line(7).in_column(17)
end
end
end
Expand Down Expand Up @@ -72,6 +90,16 @@ class { '::foobar': }
class foobar {
}
contain ::foobar
contain('::foobar')
contain(foobar(baz))
contain(foobar('baz'))
require ::foobar
require('::foobar')
require(foobar(baz))
require(foobar('baz'))
EOS
end

Expand All @@ -86,17 +114,25 @@ class foobar {
include foobar
include(foobar)
class { 'foobar': }
contain foobar
contain(foobar)
require foobar
require(foobar)
EOS
end

it 'should detect 3 problems' do
expect(problems).to have(3).problems
it 'should detect 7 problems' do
expect(problems).to have(7).problems
end

it 'should fix the problems' do
expect(problems).to contain_fixed(msg).on_line(1).in_column(17)
expect(problems).to contain_fixed(msg).on_line(2).in_column(17)
expect(problems).to contain_fixed(msg).on_line(3).in_column(17)
expect(problems).to contain_fixed(msg).on_line(4).in_column(17)
expect(problems).to contain_fixed(msg).on_line(5).in_column(17)
expect(problems).to contain_fixed(msg).on_line(6).in_column(17)
expect(problems).to contain_fixed(msg).on_line(7).in_column(17)
end

it 'should should add colons' do
Expand All @@ -105,6 +141,10 @@ class { 'foobar': }
include ::foobar
include(::foobar)
class { '::foobar': }
contain ::foobar
contain(::foobar)
require ::foobar
require(::foobar)
EOS
)
end
Expand Down

0 comments on commit 47c47f0

Please sign in to comment.