How can I find out which config file(s) rubocop is using?

Viewed 286

I'm clear on the rules rubocop follows to find the config file or files it uses to build up the list of cops it uses -- it is explained here: RuboCop Configuration

However, the rules allow for several different possibilities, and what I am looking for would be some way to get rubocop to display the path(s) of the file(s) it has found to use.

For example, if I edit a file that I think is the active rubocop config file, but find out when I run rubocop that the change I've made isn't incorporated (ergo rubocop must not be getting its config from there after all, or it's being overridden somewhere else) then it would help to know which file(s) rubocop is in fact getting its config from.

Ideally there would be a command option like rubocop --display_config_paths, which would display the path or paths of all config files it will use as currently invoked -- but given that such an option doesn't exist, is there any way to find this out?

1 Answers

Short Answer: Add debug option when calling rubocop then you will see config files loaded:

   $ rubocop --config ~/.rubocop.yml --debug zpl/bin/zpl_csv 
   configuration from /home/user/.rubocop.yml
   Default configuration from 
   /home/lcs/.rbenv/versions/2.6.1/lib/ruby/gems/2.6.0/gems/rubocop-1.25.1/config/default.yml
   Inspecting 1 file`
   ...

Others things:

Take a look to 'Config file locations' paragraph from rubocop documentation, and check priority of configs files, note the following sentence:

'then RuboCop will use the config as specified inside the first of the following files'

If you want to use several files you may have to use 'Inheriting from another configuration file in the project'

Related