Skip to content

Commit

Permalink
[Fix rubocop#10143] Fix an error for Lint/RequireRelativeSelfPath
Browse files Browse the repository at this point in the history
Fixes rubocop#10143.

This PR fixes an error for `Lint/RequireRelativeSelfPath`
when using a variable as an argument of `require_relative`.
  • Loading branch information
koic committed Sep 29, 2021
1 parent 85d67c9 commit afa9bb5
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
@@ -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

0 comments on commit afa9bb5

Please sign in to comment.