Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rubocop-erb's default config is overwritten by .rubocop_todo.yml #15

Closed
Earlopain opened this issue Feb 23, 2023 · 4 comments · Fixed by #17
Closed

rubocop-erb's default config is overwritten by .rubocop_todo.yml #15

Earlopain opened this issue Feb 23, 2023 · 4 comments · Fixed by #17

Comments

@Earlopain
Copy link
Contributor

Earlopain commented Feb 23, 2023

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.

@r7kamura
Copy link
Owner

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?

@Earlopain
Copy link
Contributor Author

Of course, I can try to create a small reproduction case and link it here once I've got time.

@Earlopain
Copy link
Contributor Author

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

@r7kamura
Copy link
Owner

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.

@r7kamura r7kamura changed the title Small issue with .rubocop_todo.yml rubocop-erb's default config is overwritten by .rubocop_todo.yml Feb 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants