Foodcritic / foodcritic

Lint tool for Chef cookbooks.
http://foodcritic.io
MIT License
407 stars 153 forks source link

FC019 false positive #474

Closed Bjorn248 closed 8 years ago

Bjorn248 commented 8 years ago

Using foodcritic 6.3.0

Output of foodcritic . is

FC019: Access node attributes in a consistent manner: ./recipes/configure_topics.rb:6
FC019: Access node attributes in a consistent manner: ./recipes/configure_topics.rb:10
FC019: Access node attributes in a consistent manner: ./recipes/configure_topics.rb:12

configure_topics.rb has the following contents

#
# Cookbook Name:: kafka
# Recipe:: configure_topics
#

node['kafka']['topics'].each do |topic, flag|
    bash "create #{topic} topic" do
        user "root"
        code <<-EOH
        /opt/kafka/bin/kafka-topics.sh --zookeeper #{node['kafka']['broker']['zookeeper']['connect']} --create --topic #{topic} --partitions 1 --replication-factor 1
        EOH
        not_if "/opt/kafka/bin/kafka-topics.sh --zookeeper #{node['kafka']['broker']['zookeeper']['connect']} --list | grep #{topic}"
    end
end

As seen in the code, the symbol method of accessing attributes is not used, so FC019 should not be shown here, correct?

coderanger commented 8 years ago

This was cross-posted to StackOverflow and answered (probably) over there. https://stackoverflow.com/questions/38577490/chef-foodcritic-fc019-false-positive/38579150

Bjorn248 commented 8 years ago

Yes, this was resolved on stack overflow. I had dot notation in the attributes file e.g. default.kafka.version and that was causing the string notation to throw the warnings.

http://stackoverflow.com/questions/38577490/chef-foodcritic-fc019-false-positive

jillson commented 5 years ago

Necro-thread time: shouldn't this still be a bug with foodcritic, namely that it should show the line in attributes.rb that causes it to flag the recipes?