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

[Cop request]: UnneededRequireFileExtension #7333

Closed
TSMMark opened this issue Sep 4, 2019 · 7 comments · Fixed by #8272
Closed

[Cop request]: UnneededRequireFileExtension #7333

TSMMark opened this issue Sep 4, 2019 · 7 comments · Fixed by #8272

Comments

@TSMMark
Copy link
Contributor

TSMMark commented Sep 4, 2019

Is your feature request related to a problem? Please describe.

.rb is not necessary when require or require_relative a Ruby file. When performing code review I am having to ask contributors to remove the superfluous file extension.

Describe the solution you'd like

When given:

require_relative "./whatever.rb"
require "../foo/bar.rb"

Autocorrect to:

require_relative "./whatever"
require "../foo/bar"
@TSMMark
Copy link
Contributor Author

TSMMark commented Sep 4, 2019

I would be happy to implement this cop myself given a pointer or two.

@koic
Copy link
Member

koic commented Sep 5, 2019

It seems to be good overall to me.

It is a caution. *.rb, *.o, *.so, and other extensions are searched if the extension is omitted. (*.rb takes precedence) .
https://ruby-doc.org/core-2.6.4/Kernel.html#method-i-require

There is an edge case where foo.so file is loaded instead of a LoadError if foo.so file exists when require 'foo.rb' will be changed to require 'foo'.

FYI, the cop name should use Redundant instead of Unneeded. And I think it's probably the Style department, not the Lint department.
#7077

@rubocop-hq/rubocop-core Is there anything you are worrying about?

@jonas054
Copy link
Collaborator

jonas054 commented Sep 8, 2019

It looks safe to me. Since *.rb takes precedence I can't see any risk that removing .rb would alter the behavior, except for the edge case @koic mentioned, but that seems harmless.

@jonas054
Copy link
Collaborator

jonas054 commented Sep 8, 2019

@TSMMark Start by reading Contributing and let us know if you have any questions. For this cop I think you should implement on_send and check calls to require and require_relative. Call the cop Style/RedundantFileExtensionInRequire.

@stale
Copy link

stale bot commented Mar 6, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution and understanding!

@stale stale bot added the stale Issues that haven't been active in a while label Mar 6, 2020
@stale
Copy link

stale bot commented Jun 4, 2020

This issues been automatically closed due to lack of activity. Feel free to re-open it if you ever come back to it.

@stale stale bot closed this as completed Jun 4, 2020
@bbatsov bbatsov reopened this Jul 8, 2020
@stale stale bot removed the stale Issues that haven't been active in a while label Jul 8, 2020
@TSMMark
Copy link
Contributor Author

TSMMark commented Jul 9, 2020

Sorry y'all I totally lost track of this ticket! @fatkodima you rock!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants