Rubocop: Running after `--auto-gen-config` does not ignore all convention offenses

Created on 14 Sep 2016  路  14Comments  路  Source: rubocop-hq/rubocop

I have a large codebase that I'm trying to make pass rubocop. However, while I work on that, I wanted to setup the .rubocop_todo.yml to ignore all existing offenses so that I can run it on CI and avoid having the rest of my team introduce new rubocop offenses. I understand that's one of the main purposes of --auto-gen-config.

When I run rubocop --auto-gen-config, it shows 16,000+ offenses and generates the proper .rubocop_todo.yml. However, after setting rubocop to inherit from that file and running rubocop, it still shows 4000+ offenses, all of which are C (convention) offenses.

I've run rubocop --format offenses and all of the cops reporting offenses are included in the .rubocop_todo.yml with the correct config so that they should be ignored, but they are not.

Do I need to be running it with a certain flag to ignore convention offenses in .rubocop_todo.yml? I do not want to ignore all convention offenses, just those listed in the todo file.

Unfortunately, this is a private repo so I cannot post code samples. If needed, I can spin up a new app and try to reproduce.


Expected behavior

I expected the auto generated config to ignore all errors, warnings, conventions, and everything else rubocop found if .rubocop_todo.yml is inherited from in .rubocop.yml.

Actual behavior

rubocop ignored all warnings but did not ignore conventions.

Steps to reproduce the problem

  1. Run rubocop --auto-gen-config
  2. Add inherit_from: .rubocop_todo.yml to top of .rubocop.yml
  3. Run rubocop

    RuboCop version

$ rubocop -V
0.42.0 (using Parser 2.3.1.2, running on ruby 2.2.4 x86_64-darwin14)

Most helpful comment

@supremebeing7 That could probably be because your .rubocop.yml was overriding the .rubocop_todo.yml? I've been just bitten by this behavior of --auto-gen-config and now trying to verify that it's a known issue which would be likely fixed at some point (I could try to contribute as well).

All 14 comments

I've done what you're currently attempting to do (start using rubocop on a large pre-existing codebase), and my experience was although rubocop is amazing & has been a massive help for us, the --auto-gen-config process can be a bit buggy. In my case there were several cops that would not correctly generate a todo file that would allow a subsequent rubocop run to pass, but it was quite cop-specific. So, I would suggest that you make groomed smallest possible test samples & file bug reports against each problematic cop, or look at manually tweaking the config in .rubocop.yml on top of whatever is in .rubocop_todo.yml to get it to pass. Good luck!

Here's the first one (new cop introduced in 0.43.0!) https://github.com/bbatsov/rubocop/issues/3568

Thanks @madwort, good suggestion. If I have time, I will try to work through the cops one at time.

Like I said, good luck, I think it's definitely worth it but the initial setup is annoying. Here's another one that's bitten me in the most recent version: https://github.com/bbatsov/rubocop/issues/2679

I actually stumbled on that one before I posted this issue, but all of the solutions suggested in it that I tried did not work for me. But yes, that one has bitten me as well :trollface:

Style/GuardClause:
  Enabled: false

in .rubocop.yml should do the trick, no?

Well, the goal is to have it enabled but ignore certain files, right? That way, we can ignore violations currently in the code but catch any new violations, then work through the excluded files at our own pace. It was my impression that is one of the main points of the --auto-gen-config option.

Yes, it absolutely should work that way, and hopefully that bug will get fixed soon. All I meant was, for me it was worth completely disabling some cops in order to get the process started fixing lots of other ones - GuardClause for example needs slightly more thought than things like how many spaces should something be indented. The default config for --auto-gen-config is that if over 25 files in your codebase violate a cop, the cop is disabled for all files (rather than adding an Exclude line for enormous lists of files), so depending on your codebase you may find that many cops are currently completely disabled.

Gotcha, I misunderstood.

I wrote a small script a while ago to generate a complete rspec todo if you guys are interested: https://gist.github.com/backus/00f0a34857208bf356af. No promises that it will work but you might be able to adapt it for what you want given that code. Basically it just iterates over all remaining offenses and adds excludes to your rubocop config file

Thanks @backus.

My issue was actually that even the files listed under Excludes were not being excluded for certain cops.

@supremebeing7 That could probably be because your .rubocop.yml was overriding the .rubocop_todo.yml? I've been just bitten by this behavior of --auto-gen-config and now trying to verify that it's a known issue which would be likely fixed at some point (I could try to contribute as well).

Hm, I had not checked that, but it's certainly possible.

I'm not sure if that is the case, because it's definitely excluding some of violations from the results, just not all of them. As in, I will run with --auto-gen-config, it will generate the .rubocop_todo.yml and spit out x number of violations, then when run again without --auto-gen-config, it spits out far fewer violations, presumably because it's reading the .rubocop_todo.yml and excluding/ignoring at least _some_ of the violations in there.

Anyway, it's worth checking into either way. I'm not at a place where I can look into it right now, but will check it out.

I'm pretty sure you're experiencing the same problem that was discussed in #2839, a pull request that tried to solve it but was not accepted. My opinion is that we have a suggestion for a decent but imperfect solution there. The alternative is the bigger and more time-consuming overhaul of --auto-gen-config that @alexdowad hinted at. But if no-one is willing to work on that it's not really an alternative.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tedPen picture tedPen  路  3Comments

Aqualon picture Aqualon  路  3Comments

millisami picture millisami  路  3Comments

deivid-rodriguez picture deivid-rodriguez  路  3Comments

bquorning picture bquorning  路  3Comments