Skip to content

Commit

Permalink
Use #sub method over #match & fix regex
Browse files Browse the repository at this point in the history
It's better if we use #sub over #match + #delete_prefix.
Also, add "^" to regex, thereby fixing false-positive
cases (for eg: "/lib/foo/bar").
  • Loading branch information
terceiro authored and utkarsh2102 committed Sep 18, 2020
1 parent 8c3f7a4 commit 5edc0fe
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions lib/rubocop/cop/packaging/require_with_relative_path.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ def on_send(node)
# Called from on_send, this method helps to replace
# the "bad" require call with the "good" one.
def good_require_call
bad_part = @str.match(%r{.*/lib/}).to_s
good_call = @str.delete_prefix(bad_part)
good_call = @str.sub(%r{^.*/lib/}, "")
%(require "#{good_call}")
end

Expand Down

0 comments on commit 5edc0fe

Please sign in to comment.