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

extend_config vs .rubocop_todo.yml #540

Open
palkan opened this issue Mar 16, 2023 · 1 comment
Open

extend_config vs .rubocop_todo.yml #540

palkan opened this issue Mar 16, 2023 · 1 comment

Comments

@palkan
Copy link
Contributor

palkan commented Mar 16, 2023

Standard: 1.24.3
RuboCop: 1.44.1

I've been working on the blog post update, and found that it's not possible to migrate the project from .rubocop_todo.yml to standardrb without re-generating the TODO file with standard.

Reproduction script

Given the source code file (a.rb):

module A
  def foo; 'bar'; end
end

And the following configuration files:

# .rubocop.yml
inherit_mode:
  merge:
    - Exclude

require:
  - standard

inherit_gem:
  standard: config/base.yml

inherit_from:
  - .rubocop_todo.yml

AllCops:
  NewCops: disable
  SuggestExtensions: false
  TargetRubyVersion: 2.6
# .standard.yml
parallel: true
format: progress

extend_config:
  - .rubocop_todo.yml

The TODO file has been generated with RuboCop and contains:

Style/SingleLineMethods:
  Exclude:
    - 'a.rb'

Style/StringLiterals:
  EnforcedStyle: single_quotes

Adding .rubocop_todo.yml has no effect

I expect running standardrb to show no errors, but:

$ be standardrb

Inspecting 1 file
C

Offenses:

a.rb:2:3: C: [Correctable] Style/SingleLineMethods: Avoid single-line method definitions.
  def foo; 'bar'; end
  ^^^^^^^^^^^^^^^^^^^
a.rb:2:12: C: [Correctable] Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
  def foo; 'bar'; end
           ^^^^^

Running rubocop works as expected: 1 file, no offenses detected.

Possible solutions

I think, it's okay to instruct users to run standardrb --generate-todo instead of loading the existing .rubocop_todo.yml. Thus, just a note in the documentation could be enough.

However, it's not clear why extending the configuration doesn't work in this case. Maybe, something related to the inherit_mode?

@searls
Copy link
Contributor

searls commented Mar 17, 2023

I think that extend_config won't work here because the thing that merges in your extension will filter out all top-level keys that match the names of cops included in rubocop+performance. It does this to prevent people from extending the config so as to change the rules.

I think updating the doc to point people to standardrb --generate-todo is probably appropriate based on my read of what you want

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

No branches or pull requests

2 participants