rubocop icon indicating copy to clipboard operation
rubocop copied to clipboard

rubocop --disable-uncorrectable creates one line of rubocop:todo for each cop and/or partially inlines

Open bbugh opened this issue 2 years ago • 1 comments

I wasn't sure whether to report this as a bug or as a feature. It seems like a bug, but it's technically working, just oddly.

Is your feature request related to a problem? Please describe.

rubocop --disable-uncorrectable results in one line of rubocop:todo for each cop that fails, which can result in code with a lot of comments.

Example 1

When the line is long, it will wrap it multiple times:

  # rubocop:todo Rails/ReflectionClassName
  # rubocop:todo Rails/InverseOf
  # rubocop:todo Rails/HasManyOrHasOneDependent
  has_many :some_assocation, -> { where(status: %w[open closed]).where('created_at > ?', 24.hours.ago).order(opened_at: :desc) }, class_name: Model.name
  # rubocop:enable Rails/HasManyOrHasOneDependent
  # rubocop:enable Rails/InverseOf
  # rubocop:enable Rails/ReflectionClassName

Example 2

or when the line isn't too long, it will try to put them all on the same line:

app/models/some_model.rb:132:53: C: [Corrected] Style/DoubleCopDisableDirective: More than one disable comment on one line.
  has_many :some_assocation, class_name: Model.name # rubocop:todo Rails/HasManyOrHasOneDependent # rubocop:todo Rails/InverseOf # rubocop:todo Rails/ReflectionClassName

but it will then auto correct to split across lines and have some inline and some not:

  # rubocop:todo Rails/ReflectionClassName
  # rubocop:todo Rails/InverseOf
  has_many :some_assocation, class_name: Model.name # rubocop:todo Rails/HasManyOrHasOneDependent
  # rubocop:enable Rails/InverseOf
  # rubocop:enable Rails/ReflectionClassName

Describe the solution you'd like

All of the automatically generated rubocop:todo lines are combined into one:

  # rubocop:todo Rails/InverseOf, Rails/HasManyOrHasOneDependent, Rails/ReflectionClassName
  has_many :some_assocation, class_name: Model.name
  # rubocop:enable Rails/InverseOf, Rails/HasManyOrHasOneDependent, Rails/ReflectionClassName

Describe alternatives you've considered

  1. Leaving as-is and generating a lot of noise and confusing multi-line todos
  2. 🤔 a different feature that allows line number ranges in .rubocop_todo.yml instead? 🤷🏻‍♂️

bbugh avatar Feb 04 '22 19:02 bbugh

I think this is a duplicate of https://github.com/rubocop/rubocop/issues/8161. That issue was closed with a reference to a potential fix. I haven't looked into this in a while so I'm not sure what the current state is. When I looked at this in the past, we didn't have the proper context to add all of the uncorrectable offenses to the same line. Maybe this is in a better state now.

rrosenblum avatar Feb 17 '22 17:02 rrosenblum