Skip to content

Commit

Permalink
Merge pull request #318 from rodjek/issue-311
Browse files Browse the repository at this point in the history
Insert :WHITESPACE token between :NAME and :FARROW if needed
  • Loading branch information
timtim123456 committed Sep 18, 2014
2 parents 1c98182 + d7edd29 commit 61d4b8e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
10 changes: 8 additions & 2 deletions lib/puppet-lint/plugins/check_whitespace.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,13 @@ def check
end

def fix(problem)
new_indent = ' ' * (problem[:indent_depth] - problem[:token].prev_token.column)
problem[:token].prev_token.value = new_indent
if problem[:token].prev_token.type == :WHITESPACE
new_indent = ' ' * (problem[:indent_depth] - problem[:token].prev_token.column)
problem[:token].prev_token.value = new_indent
else
index = tokens.index(problem[:token].prev_token)
whitespace = ' ' * (problem[:indent_depth] - problem[:token].column)
tokens.insert(index + 1, PuppetLint::Lexer::Token.new(:WHITESPACE, whitespace, 0, 0))
end
end
end
28 changes: 28 additions & 0 deletions spec/puppet-lint/plugins/check_whitespace/arrow_alignment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -399,5 +399,33 @@ class { 'lvs::base':
expect(manifest).to eq(fixed)
end
end

context 'resource with unaligned => and no whitespace between param and =>' do
let(:code) { "
user { 'test':
param1 => 'foo',
param2=> 'bar',
}
" }

let(:fixed) { "
user { 'test':
param1 => 'foo',
param2 => 'bar',
}
" }

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

it 'should fix the problem' do
expect(problems).to contain_fixed(msg).on_line(4).in_column(17)
end

it 'should add whitespace between the param and the arrow' do
expect(manifest).to eq(fixed)
end
end
end
end

0 comments on commit 61d4b8e

Please sign in to comment.