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

Allow strings containing only a variable if they're used as hash keys #280

Merged
merged 2 commits into from
Jul 11, 2014
Merged
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
4 changes: 4 additions & 0 deletions lib/puppet-lint/plugins/check_strings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ def fix(problem)
# a single variable only and record a warning for each instance found.
PuppetLint.new_check(:only_variable_string) do
VAR_TYPES = Set[:VARIABLE, :UNENC_VARIABLE]

def check
tokens.each_with_index do |start_token, start_token_idx|
if start_token.type == :DQPRE and start_token.value == ''
Expand All @@ -41,6 +42,9 @@ def check
eos_offset += 3
when :DQPOST
if eos_token.value == ''
if eos_token.next_code_token && eos_token.next_code_token.type == :FARROW
break
end
notify :warning, {
:message => 'string containing only a variable',
:line => var_token.line,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,19 @@
expect(problems).to contain_warning(msg).on_line(1).in_column(3)
end
end

context 'string containing only a variable as a hash key' do
let(:code) { "
$bar = 'key'
$foo = {
\"$bar\" => 1,
}"
}

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

context 'with fix enabled' do
Expand Down