Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(GH416) Wrong arrow alignment when key has interpolated variable #497

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/puppet-lint/lexer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ def interpolate_string(string, line, column)
lexer.tokens.each do |token|
tok_col = column + token.column + (ss.pos - contents.size - 1)
tok_line = token.line + line - 1
tokens << new_token(token.type, token.value, token.value.size, :line => tok_line, :column => tok_col)
tokens << new_token(token.type, token.value, token.value.size + 3, :line => tok_line, :column => tok_col)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this do on a line w/o the curlies? e.g., "A double quoted $string without properly bracketed variables"

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ugh, it does not work properly. However I think #492 will give us a better grasp on the issue to debug it.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So we are still waiting to merge this one, correct?

end
end
end
Expand Down
68 changes: 68 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 @@ -570,5 +570,73 @@ class { 'lvs::base':
expect(manifest).to eq(fixed)
end
end

context 'nested hashes with correct indentation and interpolated variable' do
let(:code) { "
class example (
$external_ip_base,
) {

bar { 'xxxxxxxxxxx':
inputs => {
'ny' => {
\"${external_ip_base}.16:443\" => 'foo',
'veryveryverylongstring8:443' => 'foo',
},
},
}
}"
}

it 'should not detect any problems' do
expect(problems).to have(0).problems
end
end

context 'nested hashes with incorrect indentation and interpolated variable' do
let(:code) { "
class example (
$external_ip_base,
) {

bar { 'xxxxxxxxxxx':
inputs => {
'ny' => {
\"${external_ip_base}.16:443\" => 'foo',
'veryveryverylongstring8:443' => 'foo',
},
},
}
}"
}

let(:fixed) { "
class example (
$external_ip_base,
) {

bar { 'xxxxxxxxxxx':
inputs => {
'ny' => {
\"${external_ip_base}.16:443\" => 'foo',
'veryveryverylongstring8:443' => 'foo',
},
},
}
}"
}

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

#it 'should fix the problem' do
#expect(problems).to contain_fixed(msg).in_column(48)
#end

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