From e3716883af66172add680a238f12178ae78864bd Mon Sep 17 00:00:00 2001 From: Lucas Cimon Date: Tue, 5 Jul 2016 23:37:12 +0200 Subject: [PATCH] Bugfix: properly handling $gronk-$grouik with --fix (fix #442) --- README.md | 5 +++++ lib/puppet-lint/lexer.rb | 4 ++-- lib/puppet-lint/plugins/check_variables.rb | 2 +- .../plugins/check_strings/variables_not_enclosed_spec.rb | 6 +++--- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index cc30b189..3527e754 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/lib/puppet-lint/lexer.rb b/lib/puppet-lint/lexer.rb index dc24cd3d..771cc604 100644 --- a/lib/puppet-lint/lexer.rb +++ b/lib/puppet-lint/lexer.rb @@ -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) @@ -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) diff --git a/lib/puppet-lint/plugins/check_variables.rb b/lib/puppet-lint/plugins/check_variables.rb index 08480d9d..6a2f5724 100644 --- a/lib/puppet-lint/plugins/check_variables.rb +++ b/lib/puppet-lint/plugins/check_variables.rb @@ -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, diff --git a/spec/puppet-lint/plugins/check_strings/variables_not_enclosed_spec.rb b/spec/puppet-lint/plugins/check_strings/variables_not_enclosed_spec.rb index a27e9526..ac50d875 100644 --- a/spec/puppet-lint/plugins/check_strings/variables_not_enclosed_spec.rb +++ b/spec/puppet-lint/plugins/check_strings/variables_not_enclosed_spec.rb @@ -39,10 +39,10 @@ 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 @@ -50,7 +50,7 @@ end it 'should enclose the variable in braces' do - expect(manifest).to eq('" ${gronk}"') + expect(manifest).to eq('" ${gronk}-${grouik}"') end end