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

[Fix #10143] Fix an error for Lint/RequireRelativeSelfPath #10146

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -0,0 +1 @@
* [#10143](https://github.com/rubocop/rubocop/issues/10143): Fix an error for `Lint/RequireRelativeSelfPath` when using a variable as an argument of `require_relative`. ([@koic][])
1 change: 1 addition & 0 deletions lib/rubocop/cop/lint/require_relative_self_path.rb
Expand Up @@ -27,6 +27,7 @@ class RequireRelativeSelfPath < Base

def on_send(node)
return unless (required_feature = node.first_argument)
return unless required_feature.respond_to?(:value)
return unless same_file?(processed_source.file_path, required_feature.value)

add_offense(node) do |corrector|
Expand Down
6 changes: 6 additions & 0 deletions spec/rubocop/cop/lint/require_relative_self_path_spec.rb
Expand Up @@ -42,4 +42,10 @@
require_relative 'foo.racc'
RUBY
end

it 'does not register an offense when using a variable as an argument of `require_relative`' do
expect_no_offenses(<<~RUBY, 'foo.rb')
Dir['test/**/test_*.rb'].each { |f| require_relative f }
RUBY
end
end