Rubocop: Option for '--auto-gen-config' not to change 'Max' on cop 'Metrics'

Created on 30 Jun 2016  ·  16Comments  ·  Source: rubocop-hq/rubocop

Expected behavior

Option to generate the '.rubocop_todo.yml' excluding offending files of cop 'Metrics', instead of setting 'Max' to the highest value found for the inspected code.

Actual behavior

Set 'Max' to the highest value found for the inspected code.

RuboCop version

$ rubocop -V
0.41.1 (using Parser 2.3.1.2, running on ruby 2.3.1 x86_64-darwin15)
feature request

Most helpful comment

I'll implement it! 😉

All 16 comments

Hi @jonas054,

We are experiencing an unexpected behavior while using --auto-gen-config which is probably related to this issue.

Long in short: Metrics/LineLength is added to the auto-generated config. file with a max. value of 139. Since we're setting this value to 120 (instead of the default value of 80) in our custom RuboCop config. file (.rubocop.yml), it's overriding the 139 present in the auto-gen config. file. Then... it seems like there's no point in having that 139 in the auto-generated config. file (obv. the offenses keep being reported).

Question: Would the implementation of this feature request fix this problem?

Just realized that #2102 fixed this buggy behavior for Exclude. Since the approach used to fix it there, obv. doesn't apply for Max... I guess that what you propose as "expected behavior" would finally fix everything :)

Would the implementation of this feature request fix this problem?

Yes, I'm pretty sure that it would.

I don't really see the current behavior as a problem, and definitely not a bug. Yes, we're generating a Max that will have no effect, but I prefer that to the alternative of leaving it out in this special case. It's better that you can get rid of offenses by removing the Max override in .rubocop.yml.

@jonas054 Thanks for the prompt feedback.

I'll try to find time soon to explain why the current behavior is certainly a problem, and probably a bug (meaning: not expected behavior when --auto-gen-config was born) too ;)

@dcarral I just found this issue today because I was trying to figure out why Max values in .rubocop_todo.yml weren't overriding their counterparts in .rubocop.yml

Any update on this? It's definitely a +1 from me because I was expecting to be able to add inherit_from: <my_autogenerated_config> without having to change anything else in .rubocop.yml and have 0 offenses.

@davidcpell I haven't had time to invest on this topic since my last comment :(

It would be definitely a nice bug/misbehavior to fix! ;)

I'll implement it! 😉

@Ana06 As you know, there are a lot of issues regarding the same issue (or similar ones) when using --auto-gen-config.

I hope we agree that the current warning about overriding (available in master) is nice, but far from optimal. I'd be happy to contribute to the “definite” fix (if not implementing, at least discussing the “ideal” approach -from a codebase maintainer point of view-).

Therefore: feel free to ping me to work on that or review anything, I'd happily find time for it!

There hasn't been much activity on this ticket and our Core Team is spread too thin on so many tasks, so I'll just close it for the sake of having a cleaner lists of tasks to focus on. We'd gladly review a PR, but it's unlikely that'd we're going to tackle this ourselves in the foreseeable future.

@bbatsov I think we shouldn't close this! :sob: This is an important thing! :sob: :sob: :sob: It doesn't hurt to leave it open with a help wanted tag. I don't have much time at the moment, but there is some work I did already to fix this and https://github.com/rubocop-hq/rubocop/issues/4156 in case someone want to finish it: https://github.com/rubocop-hq/rubocop/pull/5505

It doesn't hurt to leave it open with a help wanted tag.

I long believed that myself, but if the number of tickets grows over some critical point it's really hard to focus on the most important tasks at hand, as it's easy to get lost in all of the possible points for improvement. I think that if we didn't implement something in 2 years probably it's not that important, but I really hope that someone will tackle it at some point.

It seems that Metrics/ClassLength is still setting a Max when I run

rubocop --auto-gen-config --auto-gen-only-exclude

Am I misunderstanding this fix?

It does set a Max when there are many offenses (more than the limit, by default 15). But if there are less than the limit, it excludes the files instead raising the Max.

@Ana06 Ah, that's just what I was looking for, thank you!

As a followup, is there any reason for me to not run this with --exclude-limit 800 so none of the rules will be disabled on our codebase? What was the thought behind setting the default to 15?

@gabeodess

As a followup, is there any reason for me to not run this with --exclude-limit 800 so none of the rules will be disabled on our codebase? What was the thought behind setting the default to 15?

Well, it will still be disabled in potentially 800 files of your codebase. I guess the idea was to avoid that the todo file gets huge. In addition, if you have 800 files with offenses, allowing to add a few more doesn't seem to be such important.

Got it, thanks!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

AndreiMotinga picture AndreiMotinga  ·  3Comments

bbatsov picture bbatsov  ·  3Comments

deivid-rodriguez picture deivid-rodriguez  ·  3Comments

bbugh picture bbugh  ·  3Comments

Ana06 picture Ana06  ·  3Comments