rubocop-erb's default config is overwritten by .rubocop_todo.yml
Earlopain opened this issue · comments
I have a codebase which employs .rubocop_todo.yml
to silence existing violations. Once I add this gem that file is partially ignored.
I can fix this if I add this to my .rubocop.yml
:
inherit_mode:
merge:
- Exclude
Makes sense. Perhaps this should be added to the readme as a general recommendation? There would probably also be some sort of issue if I specify excludes for cops in my own rubocop config.
It is puzzling that this would be the case after adding this gem. Can you please tell me more about how I can reproduce it so I can try to reproduce it?
Of course, I can try to create a small reproduction case and link it here once I've got time.
I was misinterpreting what I was looking at. The file is not being ignored, the default of this gem is overwritten.
If a cop is exluded as part of .rubocop_todo.yml
which also is also being ignored in config/default.yml then those cops will run on erb files.
Heres a small example:
.rubocop_todo.yml
# This configuration was generated by
# `rubocop --auto-gen-config --auto-gen-only-exclude --exclude-limit 20000`
# on 2023-02-23 22:33:45 UTC using RuboCop version 1.46.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.
# Offense count: 1
# This cop supports safe autocorrection (--autocorrect).
# Configuration parameters: EnforcedStyle.
# SupportedStyles: final_newline, final_blank_line
Layout/TrailingEmptyLines:
Exclude:
- 'test.rb' # This file isn't needed, just the 'Exlude' entry
.rubocop.yml
inherit_from: .rubocop_todo.yml
require:
- rubocop-erb
AllCops:
NewCops: enable
test.html.erb
<% method_call_with_parens() %>
Running rubocop produces this output:
Offenses:
test.html.erb:1:27: C: [Correctable] Style/MethodCallWithoutArgsParentheses: Do not use parentheses for method calls with no arguments.
<% method_call_with_parens() %>
^^
test.html.erb:1:30: C: [Correctable] Layout/TrailingEmptyLines: Final newline missing.
<% method_call_with_parens() %>
The second offence goes away once you add this to the rubocop config:
inherit_mode:
merge:
- Exclude
Thanks! I prepared a similar file here and was able to reproduce the problem 👌
The way rubocop-erb manages default config is realized by exactly the same mechanism as rubocop-rspec, rubocop-rails, and other plugins, so I am wondering if other plugins have the same problem. I am not sure at the moment if this is a problem that should be fixed on the rubocop gem side or on the plugin side.
At any rate, I agree that we should explain the caveat about the inherit_mode in the README as a workaround. I will work on it now.