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

Support Bundler-like namespaced feature on require config #10845

Merged
merged 1 commit into from Aug 9, 2022

Conversation

r7kamura
Copy link
Contributor

As you probably know, when you write gem 'foo-bar' in Gemfile, Bundler.require will tries to require 'foo/bar' as well.

# Gemfile
gem 'foo-bar'

This behavior is implemented here in bundler gem:

It would be nice if RuboCop works in the same way when we set require config in .rubocop.yml:

# .rubocop.yml
require:
  - foo-bar

Running bundle gem foo-bar will generate lib/foo/bar.rb, so we need to call require 'foo/bar' to use foo-bar gem. However, I think users will want to write - foo-bar as above.

We can avoid this problem by preparing lib/foo-bar.rb on the foo-bar gem side, but RuboCop will register an offense with Naming/FileName cop for such file name, so I think we should avoid it.

The change in this pull request would eliminate the need for files with non-standard name, such as

and additional configuration to specifically allow such file names:


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).
    • No related open issue was found.
  • 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.

@r7kamura r7kamura marked this pull request as ready for review July 29, 2022 07:29
@r7kamura
Copy link
Contributor Author

I think this is a controversial change myself. WDYT?

This is because unlike the Bundler case, we have explicitly used the vocabulary "require" for this config. This change means that there are two patterns of targets for which require is performed. This is not Simple, but Easy for users.
I decided to propose this change because I thought the advantages outweighed the disadvantages.

@bbatsov bbatsov requested a review from jonas054 August 4, 2022 10:24
@bbatsov
Copy link
Collaborator

bbatsov commented Aug 4, 2022

I'm open to the proposal, but I think we'll have to document this behavior clearly in the configuration documentation. @jonas054 Any thoughts on this?

module RuboCop
# Load feature for "require" config.
# @api private
class FeatureLoader
Copy link
Collaborator

Choose a reason for hiding this comment

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

This class can probably use more documentation itself.

@r7kamura
Copy link
Contributor Author

r7kamura commented Aug 8, 2022

Sorry for the slow response.
I added some more documentation to the class doc comment and the documentation page. I was going to add it to the Configuration page, but it seemed to mention require in Extensions page, so I decided to add it there.

@bbatsov bbatsov merged commit 1db2aae into rubocop:master Aug 9, 2022
@bbatsov
Copy link
Collaborator

bbatsov commented Aug 9, 2022

Looks good. Thanks!

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

2 participants