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

inherit_mode is ignored for arrays other than Include/Exclude if also inheriting non-default configuration (with inherit_mode at cop level) #10026

Closed
Drowze opened this issue Aug 18, 2021 · 0 comments
Assignees
Labels

Comments

@Drowze
Copy link
Contributor

Drowze commented Aug 18, 2021

Expected behavior

I expect to be able to merge my configuration with rubocop default configuration, even if I also inherit a non-default configuration.

Actual behavior

At the project .rubocop.yml, if I define an array that already exists within rubocop's default configuration, my configuration overwrites' the default config, even if inherit_mode is set to merge on the cop level

Steps to reproduce the problem

Given a hosted configuration (gist here):

AllCops:
  NewCops: enable

Naming/VariableNumber:
  EnforcedStyle: snake_case
  Exclude:
    - foo.rb
  Include:
    - bar.rb

And given .rubocop.yml:

inherit_from:
  - https://gist.githubusercontent.com/Drowze/0ea51fa5bf3cbec9e280f2f913be57df/raw/eaa3ac4911b982ddf933e32e4f53d91c41cebb43/rubocop-test.yml

Naming/VariableNumber:
  inherit_mode:
    merge:
      - AllowedIdentifiers
      - Exclude
      - Include
  AllowedIdentifiers:
    - iso2
  Exclude:
    - test.rb
  Include:
    - another_test.rb

When I run rubocop --debug --show-cops Naming/VariableNumber I get this output:
(note that AllowedIdentifiers does not include capture3 or any of the items defined at the default configuration)

For /Users/Drowze/r/rubocop_bug9: configuration from /Users/Drowze/r/rubocop_bug9/.rubocop.yml
configuration from /Users/Drowze/r/rubocop_bug9/.rubocop-https---gist-githubusercontent-com-Drowze-0ea51fa5bf3cbec9e280f2f913be57df-raw-eaa3ac4911b982ddf933e32e4f53d91c41cebb43-rubocop-test-yml
Default configuration from /Users/Drowze/.asdf/installs/ruby/2.7.3/lib/ruby/gems/2.7.0/gems/rubocop-1.19.0/config/default.yml
Naming/VariableNumber:
  Description: Use the configured style when numbering symbols, methods and variables.
  StyleGuide: "#snake-case-symbols-methods-vars-with-numbers"
  Enabled: true
  VersionAdded: '0.50'
  VersionChanged: '1.4'
  EnforcedStyle: snake_case
  SupportedStyles:
  - snake_case
  - normalcase
  - non_integer
  CheckMethodNames: true
  CheckSymbols: true
  AllowedIdentifiers:
  - iso2
  Exclude:
  - "/Users/Drowze/r/rubocop_bug9/foo.rb"
  - "/Users/Drowze/r/rubocop_bug9/test.rb"
  Include:
  - bar.rb
  - another_test.rb

Finished in 0.111557999975048 seconds

From my test I also found:

  • if I move inherit_mode to the root level, AllowedIdentifiers is merged correctly
  • if I do not inherit configuration (via inherit_from or inherit_gem), AllowedIdentifiers is merged correctly

RuboCop version

$ rubocop -V
1.19.0 (using Parser 3.0.2.0, rubocop-ast 1.10.0, running on ruby 2.7.3 x86_64-darwin20)
@jonas054 jonas054 self-assigned this Jul 6, 2022
@jonas054 jonas054 added the bug label Jul 6, 2022
jonas054 added a commit to jonas054/rubocop that referenced this issue Jul 7, 2022
…t config

The problem was that we deleted the `inherit_mode` entry in the
configuration hash while processing the resolution of inheritance from
base configurations (`inherit_from`, etc.). When the merging of default
configuration and user configuration was done at a later stage, the
`inherit_mode` parameter was gone.

By not deleting `inherit_mode`, we fix the problem. I don't think it
has any unwanted side effects, but `inherit_mode` does show up in the
output from `--show-cops` now. This should be OK.
@bbatsov bbatsov closed this as completed in 354f88b Jul 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants