Foodcritic / foodcritic

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

Foodcritic 13.x.x - Traversed in recipe folder thinking it is another cookbook when recipe named attributes.rb exists #760

Open knightorc opened 6 years ago

knightorc commented 6 years ago

Hit a weird issue today after updating to Foodcritic 13.x.x from 12.3.0

We have a cookbook that defines attributes at the recipe level. The recipe is called attributes.rb Foodcritic when testing the cookbook treats the recipes folder as a nested cookbook. Simply renaming the recipe to foo_attributes.rb causes the cookbook to test fine.

Structure while failing:

> foodcritic -V
foodcritic 13.1.1
> foodcritic -P -B .
Checking 5 files
x..x.
FC011: Missing README in markdown format: recipes/README.md:1
FC031: Cookbook without metadata.rb file: recipes/metadata.rb:1
FC071: Missing LICENSE file: recipes/LICENSE:1
FC078: Ensure cookbook shared under an OSI-approved open source license: ./metadata.rb:1
> find .
.
./.kitchen.local.yml
./.kitchen.yml
./CHANGELOG.md
./Berksfile
./.kill_older
./README.md
./recipes
./recipes/vci-repo.rb
./recipes/default.rb
./recipes/attributes.rb
./metadata.rb

Structure working:

> find .
.
./.kitchen.local.yml
./.kitchen.yml
./CHANGELOG.md
./Berksfile
./.kill_older
./README.md
./recipes
./recipes/vci-repo.rb
./recipes/default.rb
./recipes/repo_attributes.rb
./metadata.rb
> foodcritic -V
foodcritic 13.1.1
> foodcritic -P -B .
Checking 4 files
x...
FC078: Ensure cookbook shared under an OSI-approved open source license: ./metadata.rb:1
uqwhsu commented 6 years ago

Same issue for "templates" folder name nested under templates folder

example: ./templates/default/foldername/templates

results in FC011 FC031 FC071 for foldername folder

frezbo commented 6 years ago

whoa @knightorc you are right, I had an attributes.rb file in attributes directory, hmm wierd bug.

tas50 commented 6 years ago

This bug was introduced when I attempted to fix Foodcritic not finding mycookbook/recipe.rb or mycookbook/attribute.rb. I'm going to have to clean up that logic and I have several new failure states to add specs for so I can make sure we always detect the right thing without casting our net too wide. It's surprisingly difficult to get this right.

knightorc commented 6 years ago

@tas50 We're not blocked, as our solution was to rename the recipe in our case. Thanks for all your efforts. It is appreciated.

frezbo commented 6 years ago

Glad to know this is being looked upon, I also followed the approach @knightorc mentioned to get around this. :+1:

joe4dev commented 6 years ago

Confirm, same issue here with an recipe/attributes.rb recipe file present:

foodcritic -V
foodcritic 14.0.0
FC011: Missing README in markdown format: recipes/README.md:1
FC031: Cookbook without metadata.rb file: recipes/metadata.rb:1
FC069: Ensure standardized license defined in metadata: ./metadata.rb:1
FC071: Missing LICENSE file: recipes/LICENSE:1
FC078: Ensure cookbook shared under an OSI-approved open source license: ./metadata.rb:1

Renaming fixed the issue as workaround

djessich commented 5 years ago

I have the same issue with Foodcritic 15.1.0. I have an attributes recipe in my cookbooks recipe folder. With renaming the recipe, Foodcritic works as expected. I can confirm, that the workaround from @joe4dev works properly.

rbgurav87 commented 3 years ago

This is applicale for attributes/attributes.rb as well

foodcritic 15.1.0 we faced similar issue for attributes/attributes.rb as well. after renaming the attributes.rb to default.rb it started working.