Skip to content

Commit

Permalink
Merge pull request #678 from rodjek/issue-663
Browse files Browse the repository at this point in the history
Ignore selectors when finding resource type
  • Loading branch information
rnelson0 authored Mar 29, 2017
2 parents 21ac968 + 0746c7b commit b91a2fa
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/puppet-lint/data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,10 @@ def resource_indexes
#
# Returns a Token object.
def find_resource_type_token(index)
tokens[tokens[0..index].rindex { |token| token.type == :LBRACE }].prev_code_token
lbrace_idx = tokens[0..index].rindex { |token|
token.type == :LBRACE && token.prev_code_token.type != :QMARK
}
tokens[lbrace_idx].prev_code_token
end

# Internal: Find all the Token objects representing the parameter names in
Expand Down
64 changes: 64 additions & 0 deletions spec/puppet-lint/plugins/check_resources/file_mode_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,30 @@
expect(problems).to have(0).problems
end
end

context 'multi body file bad modes selector' do
let(:code) { "
file {
'/tmp/foo1':
ensure => $foo ? { default => absent },
mode => 644;
'/tmp/foo2':
mode => 644;
'/tmp/foo3':
mode => 644;
}"
}

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

it 'should create three warnings' do
expect(problems).to contain_warning(sprintf(msg)).on_line(5).in_column(21)
expect(problems).to contain_warning(sprintf(msg)).on_line(7).in_column(21)
expect(problems).to contain_warning(sprintf(msg)).on_line(9).in_column(21)
end
end
end

context 'with fix enabled' do
Expand Down Expand Up @@ -225,5 +249,45 @@
expect(manifest).to eq(code)
end
end

context 'multi body file bad modes selector' do
let(:code) { "
file {
'/tmp/foo1':
ensure => $foo ? { default => absent },
mode => 644;
'/tmp/foo2':
mode => 644;
'/tmp/foo3':
mode => 644;
}"
}

let(:fixed) { "
file {
'/tmp/foo1':
ensure => $foo ? { default => absent },
mode => '0644';
'/tmp/foo2':
mode => '0644';
'/tmp/foo3':
mode => '0644';
}"
}

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

it 'should fix 3 problems' do
expect(problems).to contain_fixed(msg).on_line(5).in_column(21)
expect(problems).to contain_fixed(msg).on_line(7).in_column(21)
expect(problems).to contain_fixed(msg).on_line(9).in_column(21)
end

it 'should zero pad the file modes and change them to strings' do
expect(manifest).to eq(fixed)
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,30 @@
expect(problems).to have(0).problems
end
end

context 'multi body file bad modes selector' do
let(:code) { "
file {
'/tmp/foo1':
ensure => $foo ? { default => absent },
mode => 644;
'/tmp/foo2':
mode => 644;
'/tmp/foo3':
mode => 644;
}"
}

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

it 'should create three warnings' do
expect(problems).to contain_warning(sprintf(msg)).on_line(5).in_column(21)
expect(problems).to contain_warning(sprintf(msg)).on_line(7).in_column(21)
expect(problems).to contain_warning(sprintf(msg)).on_line(9).in_column(21)
end
end
end

context 'with fix enabled' do
Expand Down Expand Up @@ -89,5 +113,45 @@
expect(manifest).to eq(code)
end
end

context 'multi body file bad modes selector' do
let(:code) { "
file {
'/tmp/foo1':
ensure => $foo ? { default => absent },
mode => 644;
'/tmp/foo2':
mode => 644;
'/tmp/foo3':
mode => 644;
}"
}

let(:fixed) { "
file {
'/tmp/foo1':
ensure => $foo ? { default => absent },
mode => '644';
'/tmp/foo2':
mode => '644';
'/tmp/foo3':
mode => '644';
}"
}

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

it 'should fix 3 problems' do
expect(problems).to contain_fixed(msg).on_line(5).in_column(21)
expect(problems).to contain_fixed(msg).on_line(7).in_column(21)
expect(problems).to contain_fixed(msg).on_line(9).in_column(21)
end

it 'should quote the file modes' do
expect(manifest).to eq(fixed)
end
end
end
end

0 comments on commit b91a2fa

Please sign in to comment.