rubycritic icon indicating copy to clipboard operation
rubycritic copied to clipboard

Ignore/exclude files

Open cveneziani opened this issue 10 years ago • 20 comments

Is there a way to tell to rubycritic to exclude some file patterns?

cveneziani avatar Jul 25 '14 09:07 cveneziani

As of now, no. But I was thinking of implementing just that as a solution for issue #7.

The reason for delaying that feature is that I'm torn between having it as a cli option (a --ignore-files flag like the Churn gem) or having it as a dotfile (a .rubycritic.yml file like the Rubocop gem).

I think the file approach is more powerful and flexible but honestly I'm tired of each gem having its own dotfile.

I can totally see why this would be good to have but I'm curious, what's your use case?

guilhermesimoes avatar Jul 25 '14 10:07 guilhermesimoes

I agree, the file approach is a better solution. And a file can be committed within the project repository.

My first use case is that I want to focus on some parts of the project. So I want to disable other parts and specially tests. That way I'll just have an overview of the classes that interest me.

cveneziani avatar Jul 25 '14 13:07 cveneziani

Same here. Currently RubyCritic complains about generated files like schema.rb and also about repetitions in my specs, which I don't really care about that much.

milgner avatar Jul 25 '14 19:07 milgner

Actually, for Rails projects running rubycritic app lib should be enough.

But don't worry guys, this on my radar now.

guilhermesimoes avatar Jul 25 '14 21:07 guilhermesimoes

Fantastic! And thank you for a great gem! :thumbsup:

milgner avatar Jul 26 '14 07:07 milgner

Great! :smile:

cveneziani avatar Jul 26 '14 10:07 cveneziani

I am looking forward to this feature, as I don't want to run against 'vendor'. Also, thank you @guilhermesimoes for a useful gem!

midwire avatar Jul 28 '14 16:07 midwire

What's the status for this feature @guilhermesimoes ? Did you decide which you wanted to go with it? (yml config or CLI)

born4new avatar Apr 10 '15 08:04 born4new

+1 to adding the command line flag to ignore a pattern or path

deepredsky avatar Nov 25 '15 17:11 deepredsky

Due to RC's nature this is not really trivial since we aggregate multiple tools and those tools have a different understanding of how you can exclude and include paths. And some might not even offer an "exclude" functionality. Nevertheless I can see that this feature would be highly valuable. I'll take the first step for getting this feature going when I'll address #77

troessner avatar Jan 07 '16 12:01 troessner

is there anything that let's me exclude certain method calls? e.g. I get a lot of complaints about calls to Rails.logger etc - which should be ignored

solars avatar Mar 07 '16 14:03 solars

No, not at the moment I'm afraid. This kind of functionality would be great though ;) What you can do right now is use special configurations for each analyzer that will be respected by RubyCritic as you can see here With Reek you can also generate such a configuration via "reek --todo your_path" which is unfortunately not possible for flog and flay.

troessner avatar Mar 07 '16 19:03 troessner

@troessner thanks a lot for the reply! I'll have a look at the config options. --todo doesn't seem to be included in my version of reek/rubycritic and currently parser blocks an update - I'll try to resolve it adapt the config. Thanks a lot!

solars avatar Mar 08 '16 08:03 solars

The latest version of RubyCritic bundles Reek 3.11 which includes the --todo flag, so you just need to update RubyCritic and you're good to go ;)

troessner avatar Mar 08 '16 10:03 troessner

@troessner thanks a lot! And keep up the great work :)

solars avatar Mar 08 '16 10:03 solars

Hi @cveneziani I don't know if you still have a problem with more recent versions of RubyCritic (I work with version 3.3.0 right now). If so, here is a possible solution:

Define a rake task : you can specify paths as a FileList. Filelist are essentially arrays with helper method. So you can easily white list or black list whatever path you want. Example :

RubyCritic::RakeTask.new do |task|

	# Name of RubyCritic task.
	task.name    = 'quality_audit'

	excluded_files = [
		"app/jobs/file1.rb",
		"app/jobs/file2.rb"
	]

	task.paths = FileList['app/**/*.rb','lib/**/*.rb' ] - excluded_files

	# You can pass all the options here in that are shown by "rubycritic -h" except for
	# "-p / --path" since that is set separately. Defaults to ''.
	task.options = ''

	# Defaults to false
	task.verbose = true
end

I propose we close this issue, except if you prefer we write the solution in the Readme ? This solution have been cooked with @atheane

LyzioOh avatar Apr 09 '18 08:04 LyzioOh

Well, nowadays, I just run it on app and lib folders.

cveneziani avatar Apr 10 '18 09:04 cveneziani

I still think there's a the need for this feature since rubycritic should not rely on rake / rails to work flawlessly. The tools rubycritic uses already support similar flags...

nunosilva800 avatar Apr 10 '18 11:04 nunosilva800

i have also gotten used to running it just in app and lib folders. I think it would be nice to have flags which then maps to the corresponding flag to the underlying tools.

deepredsky avatar Apr 10 '18 12:04 deepredsky

Note my comment here where the .reek.yml -- which includes an exclude-this-file statement -- is being ignored by rubycritic: https://github.com/whitesmith/rubycritic/issues/270#issuecomment-494965772

philCryoport avatar May 22 '19 22:05 philCryoport