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

Prefer require_relative for internal requires #170

Merged

Conversation

tagliala
Copy link
Contributor

@tagliala tagliala commented Sep 27, 2024

require_relative is preferred over require for files within the same
project because it uses paths relative to the current file, making code
more portable and less dependent on the load path.

This change updates internal requires to use require_relative for
consistency, performance, and improved portability.

However, the test directory makes an exception and there require is
preferred

Fix Packaging/RequireRelativeHardcodingLib safe offense

Ref:

@tagliala tagliala marked this pull request as draft September 27, 2024 14:50
@jamesmartin jamesmartin deleted the branch jamesmartin:master September 30, 2024 07:32
@jamesmartin jamesmartin reopened this Sep 30, 2024
@jamesmartin jamesmartin changed the base branch from main to master September 30, 2024 07:34
@tagliala tagliala force-pushed the chore/prefer-require-relative branch 2 times, most recently from b6f8fcb to 78020be Compare October 9, 2024 06:55
@tagliala tagliala marked this pull request as ready for review October 9, 2024 06:56
@tagliala
Copy link
Contributor Author

tagliala commented Oct 9, 2024

@jamesmartin and ready for review

Then I will go for another round of RuboCop offenses

@tagliala tagliala marked this pull request as draft October 9, 2024 07:11
`require_relative` is preferred over `require` for files within the same
project because it uses paths relative to the current file, making code
more portable and less dependent on the load path.

This change updates internal requires to use `require_relative` for
consistency, performance, and improved portability.

However, the test directory makes an exception and there `require` is
preferred

Fix `Packaging/RequireRelativeHardcodingLib` safe offense

Ref:
- ruby/psych#522
- ruby/logger#20
- ruby/rdoc#658
- rubocop/rubocop#8748
- https://docs.rubocop.org/rubocop-packaging/cops_packaging.html#packagingrequirerelativehardcodinglib
@tagliala tagliala force-pushed the chore/prefer-require-relative branch from 78020be to 001b5c7 Compare October 9, 2024 07:18
@tagliala tagliala marked this pull request as ready for review October 10, 2024 06:54
@tagliala
Copy link
Contributor Author

Sorry, I forgot to remove draft

@tagliala tagliala mentioned this pull request Oct 10, 2024
@jamesmartin jamesmartin merged commit 9ab5ccf into jamesmartin:master Oct 11, 2024
7 checks passed
@jamesmartin
Copy link
Owner

Thanks, @tagliala! 🙇

@tagliala tagliala deleted the chore/prefer-require-relative branch October 11, 2024 06:45
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.

2 participants