Skip to content
This repository has been archived by the owner on Sep 19, 2020. It is now read-only.

Commit

Permalink
FC019: Fix regression in var_ref handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Crump committed Jan 5, 2013
1 parent 9ab2ffb commit 52359f7
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
5 changes: 5 additions & 0 deletions features/019_check_for_consistent_node_access.feature
Expand Up @@ -83,6 +83,11 @@ Feature: Check for consistency in node access
When I check the cookbook
Then the attribute consistency warning 019 should be not shown

Scenario: Interpolated access
Given a cookbook with a single recipe that mixes node access types in an interpolated value
When I check the cookbook
Then the attribute consistency warning 019 should be shown

Scenario: Two cookbooks with differing approaches
Given a cookbook with a single recipe that reads node attributes via strings only
And another cookbook with a single recipe that reads node attributes via symbols only
Expand Down
8 changes: 8 additions & 0 deletions features/step_definitions/cookbook_steps.rb
Expand Up @@ -893,6 +893,14 @@
end
end

Given 'a cookbook with a single recipe that mixes node access types in an interpolated value' do
write_recipe %q{
execute "interpolated-example" do
command "#{node['foo'][:bar]}'"
end
}
end

Given 'a cookbook with a single recipe that reads multiple node attributes via symbols,strings' do
write_recipe %q{
node[:foo] = 'bar'
Expand Down
4 changes: 2 additions & 2 deletions lib/foodcritic/api.rb
Expand Up @@ -443,11 +443,11 @@ def standard_attribute_access(ast, options)
else
type = options[:type] == :string ? 'tstring_content' : options[:type]
expr = '//*[self::aref_field or self::aref]'
expr += '[count(descendant::aref/var_ref) = 0]'
expr += '[count(is_att_type(descendant::var_ref/ident/@value)) =
count(descendant::var_ref/ident/@value)]'
expr += '[is_att_type(descendant::ident'
expr += '[not(ancestor::aref/call)]' if options[:ignore_calls]
expr += "/@value)]/descendant::#{type}"
expr += "[ident/@value != 'node']" if type == :symbol
ast.xpath(expr, AttFilter.new).sort
end
end
Expand Down

0 comments on commit 52359f7

Please sign in to comment.