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

foodcritic is trying to descend into a "spec" directory and treating it as a cookbook? #148

Closed
juliandunn opened this issue Jun 11, 2013 · 19 comments

Comments

@juliandunn
Copy link

Got this weird error while running Foodcritic on Opscode's Java cookbook within Travis. It looks like it's trying to treat the 'spec' directory as another cookbook. Ideas?

https://travis-ci.org/juliandunn/java/jobs/7971824#L122

@claco
Copy link

claco commented Jun 17, 2013

Yes. I have the same problem. In my case I have ./spec/libraries/libname_spec.rb files. It sees the libraries directory and thinks spec is a cookbook.

Oddly enough, this is not a problem using thor because the linter supports -e/explude_paths. The foodcritic bin itself has no -e. :-(

renaming my ./spec/libraries directory to ./spec/foop or anything non cookbookish resolved the issue.

@tmatilai
Copy link
Contributor

There seems to be #45 for adding the CLI option.

But maybe it would be good to set the default :exclude_paths in @options in CommandLine#initialize or even in Linter#setup_defaults?

@ghost
Copy link

ghost commented Jun 20, 2013

👍 Was having this same issue last night.

I wonder if a white list might be a better idea here though. You really only want to check the standard cookbook directories. For example %w{libraries, recipes, resources, providers, templates, attributes}, i'm not even positive you would always want the files directory checked.

@tmatilai
Copy link
Contributor

@gregf As I understand it, foodcritic already does that. But as it is recursive, so it matches to e.g. spec/libraries/libname_spec.rb. So Linter#files_to_process should be modified to not traverse to subdirs of found cookbook directories.

Actually nowadays I always use foodcritic for one cookbook only (normally from a rake/thor task or by guard-foodcritic) and would not want the recursive behavior at all. So the command line UI with "cookbook_paths" is not fitting well to that use case. It should maybe have an option to specify "cookbook_path" (singular) instead. I.e. disable the recursive traversal.

@juliandunn
Copy link
Author

So the problem would be solved if we modified this?

https://github.com/acrmp/foodcritic/blob/master/lib/foodcritic/linter.rb#L188

What use case am I missing by replacing the logic with just:

files += (Dir.glob(File.join(dir, cookbook_glob)) - exclusions)

?

@JeanMertz
Copy link

Was there ever a consensus on this issue? I've just ran into this myself. but both this, and #45 seem to have died out half a year ago.

@jperry
Copy link

jperry commented Nov 21, 2013

Same here, I am running into this right now.

@micgo
Copy link

micgo commented Dec 31, 2013

Did this get resolved as a side effect of https://github.com/acrmp/foodcritic/blob/11fca11b32c697333be43309af0a08fec07e2c7a/lib/foodcritic/linter.rb#L210-L233 ?

There now appears to be an undocumented 'excludes' option in the linter?

@docwhat
Copy link
Contributor

docwhat commented Jan 16, 2014

In 3.0.3 it still descends into test and spec directories.

When working on single cookbooks it makes the command foodcritic . spew annoying warnings that have to be ignored.

For guard, I suppose I can add an explicit list of %w{libraries, recipes, resources, providers, templates, attributes}.

@docwhat
Copy link
Contributor

docwhat commented Jan 16, 2014

Ah, nope. An explicit list doesn't work. foodcritic accepts directories on the command line as cookbooks, not parts of a cookbook.

BTW: In 3.0.3 you can access the Linter with exclude list by using a rake file:

require 'foodcritic/rake_task'
require 'foodcritic'

FoodCritic::Rake::LintTask.new

However, you cannot set arguments like -C because the LintTask:

  1. Doesn't support :context as an option.
  2. Ignores the options

@arr-dev
Copy link

arr-dev commented Jan 21, 2014

This is still issue in 3.0.3, guess :exclude_paths option should be accepted through CLI options.

@acrmp
Copy link
Member

acrmp commented Jan 21, 2014

Sorry for the lack of responsiveness. I've merged a modified version of Juanje's pull request to foodcritic master if you'd like to test the -X option.

Thanks,

Andrew.

acharlieh added a commit to acharlieh/cerner_splunk that referenced this issue Jan 12, 2015
yzl pushed a commit to chef-boneyard/languages that referenced this issue Oct 14, 2015
foodcritic descends into the 'spec' directory and treats it as a cookbook.
Details:  Foodcritic/foodcritic#148
@brodock
Copy link

brodock commented Feb 10, 2016

can we agree on ignoring spec folder by default?

@unixorn
Copy link
Contributor

unixorn commented Oct 3, 2016

And ignore the test folder too. I'm seeing it descend into test for some of my cookbooks even when I explicitly --exclude cookbookname/test.

This is using foodcritic 8.0.0.

edit - it was unclear from the --help output that I needed to exclude test instead of cookbook_name/test

@vinyar
Copy link

vinyar commented Oct 5, 2016

So, the big issue around this bug, is that is now blows up any pipeline created via chefdk chef generate cookbook. It now generates a cookbook with scafolding for delivery, and the very first commit using default scaffolding epic fails due to this bug.

Workaround is to add exceptions to the config.json of the cookbook and have delivery-truck ignore it.

StephenKing added a commit to TYPO3-infrastructure/jenkins-pipeline-global-library-chefci that referenced this issue Jan 31, 2017
Unbelievable. What a mess.

Foodcritic/foodcritic#148

Otherwise FC complains as follows:

> FC011: Missing README in markdown format: spec/README.md:1
> FC031: Cookbook without metadata file: spec/metadata.rb:1
> FC045: Metadata does not contain cookbook name: spec/metadata.rb:1
@tas50
Copy link
Contributor

tas50 commented Apr 8, 2017

It feels great to be able to close this one out. By default now Foodcritic excludes the spec and test directories since we know those aren't actual shared cookbooks. Not only does it make the run faster, it prevents these annoying warnings. Enjoy

@tas50 tas50 closed this as completed Apr 8, 2017
@unixorn
Copy link
Contributor

unixorn commented Apr 8, 2017

Thanks, @tas50!

@frezbo
Copy link

frezbo commented May 30, 2018

Looks like it matches attributes in one of my cookbooks:

chef-reantestclient (aws:rean-gov-sd)(kc)(git:RD-507)*$ foodcritic .
Checking 12 files
.x.........x
FC011: Missing README in markdown format: attributes/README.md:1
FC031: Cookbook without metadata.rb file: attributes/metadata.rb:1
FC071: Missing LICENSE file: attributes/LICENSE:1

Dont know why

@knightorc
Copy link

@frezbo I opened this when I tried Foodcritic 13.x.x #760

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests