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

Do not try to expand nil Include when inheriting. #11807

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

juanxo
Copy link

@juanxo juanxo commented Apr 17, 2023

When inheriting from a parent config file that has nullified an Include in any rule, it will currently fail as it will assume that the Include will always be an non-nullable array

Example:

# rubocop.yml
Style/StringLiterals:
  Include:
    - dir/**/*.rb

# child_dir/.rubocop.yml
inherit_from: ../.rubocop.yml
Style/StringLiterals:
  Include: ~

I'm currently using this pattern to remove a default Include pattern so it resorts back to the AllCops inclusion list, so setting it to [] does not accomplish the same effect.


Before submitting the PR make sure the following are checked:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Ran bundle exec rake default. It executes all tests and runs RuboCop on its own code.
  • Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.

expect(configuration_from_file['Style/StringLiterals']['Include']).to be_nil
end

it 'gets an Include that is relative to the subdirectory when inheriting from a nil Include' do
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not so sure about this test. I wanted to mostly check that going from not nil to nil and vice versa worked

@bbatsov
Copy link
Collaborator

bbatsov commented Jun 20, 2023

I'm currently using this pattern to remove a default Include pattern so it resorts back to the AllCops inclusion list, so setting it to [] does not accomplish the same effect.

I'm OK with your proposal, but this is also something we should document in the configuration section of RuboCop, as generally I don't think we've considered the use of nil much there. //cc @koic @jonas054

@koic
Copy link
Member

koic commented Jun 20, 2023

Yeah, I agree with @bbatsov.

@bbatsov
Copy link
Collaborator

bbatsov commented Jul 1, 2023

@juanxo Ping :-)

Copy link
Collaborator

@jonas054 jonas054 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@bbatsov
Copy link
Collaborator

bbatsov commented Sep 28, 2023

@juanxo Ping again :-)

1 similar comment
@bbatsov
Copy link
Collaborator

bbatsov commented Nov 5, 2023

@juanxo Ping again :-)

@koic
Copy link
Member

koic commented Mar 26, 2024

@juanxo Ping.

@juanxo
Copy link
Author

juanxo commented Apr 8, 2024

Hey, sorry for the long delay in answering. Will look to rebase and ship this

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 this pull request may close these issues.

None yet

4 participants