rubycritic
rubycritic copied to clipboard
Ignore/exclude files
Is there a way to tell to rubycritic to exclude some file patterns?
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?
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.
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.
Actually, for Rails projects running rubycritic app lib
should be enough.
But don't worry guys, this on my radar now.
Fantastic! And thank you for a great gem! :thumbsup:
Great! :smile:
I am looking forward to this feature, as I don't want to run against 'vendor'. Also, thank you @guilhermesimoes for a useful gem!
What's the status for this feature @guilhermesimoes ? Did you decide which you wanted to go with it? (yml config or CLI)
+1 to adding the command line flag to ignore a pattern or path
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
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
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 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!
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 thanks a lot! And keep up the great work :)
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
Well, nowadays, I just run it on app
and lib
folders.
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...
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.
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