Skip to content

Commit

Permalink
Merge pull request #500 from Lucas-C/master
Browse files Browse the repository at this point in the history
Bugfix: properly handling $gronk-$grouik with --fix (fix #442)
  • Loading branch information
rnelson0 committed Jul 7, 2016
2 parents ec6b667 + e371688 commit 305bd94
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
5 changes: 5 additions & 0 deletions README.md
Expand Up @@ -174,6 +174,11 @@ If you find a bug in puppet-lint or its results, please create an issue in the
[repo issues tracker](https://github.com/rodjek/puppet-lint/issues/). Bonus
points will be awarded if you also include a patch that fixes the issue.

## Executing puppet-lint tests suite

bundle exec rspec [spec/puppet-lint/a_single_test.rb]


## Thank You

Many thanks to the following people for contributing to puppet-lint
Expand Down
4 changes: 2 additions & 2 deletions lib/puppet-lint/lexer.rb
Expand Up @@ -170,7 +170,7 @@ def tokenise(code)
end

unless found
if var_name = chunk[/\A\$((::)?([\w-]+::)*[\w-]+(\[.+?\])*)/, 1]
if var_name = chunk[/\A\$((::)?([\w]+::)*[\w]+(\[.+?\])*)/, 1]
length = var_name.size + 1
tokens << new_token(:VARIABLE, var_name, length)

Expand Down Expand Up @@ -346,7 +346,7 @@ def interpolate_string(string, line, column)
tokens << new_token(:DQMID, value, value.size, :line => line, :column => token_column)
end
if ss.scan(/\{/).nil?
var_name = ss.scan(/(::)?([\w-]+::)*[\w-]+/)
var_name = ss.scan(/(::)?([\w]+::)*[\w]+/)
if var_name.nil?
token_column = column + ss.pos - 1
tokens << new_token(:DQMID, "$", 1, :line => line, :column => token_column)
Expand Down
2 changes: 1 addition & 1 deletion lib/puppet-lint/plugins/check_variables.rb
Expand Up @@ -7,7 +7,7 @@ def check
tokens.select { |r|
VARIABLE_DASH_TYPES.include? r.type
}.each do |token|
if token.value.gsub(/\[.+?\]/, '').match(/-/)
if not token.next_token.nil? and Set[:DQMID, :DQPOST, :MINUS].include? token.next_token.type and token.next_token.value.start_with? '-'
notify :warning, {
:message => 'variable contains a dash',
:line => token.line,
Expand Down
Expand Up @@ -39,18 +39,18 @@
end

context 'variable not enclosed in {}' do
let(:code) { '" $gronk"' }
let(:code) { '" $gronk-$grouik"' }

it 'should only detect a single problem' do
expect(problems).to have(1).problem
expect(problems).to have(2).problem
end

it 'should fix the manifest' do
expect(problems).to contain_fixed(msg).on_line(1).in_column(3)
end

it 'should enclose the variable in braces' do
expect(manifest).to eq('" ${gronk}"')
expect(manifest).to eq('" ${gronk}-${grouik}"')
end
end

Expand Down

0 comments on commit 305bd94

Please sign in to comment.