Skip to content

Commit

Permalink
[Fix #700] Fix a false positive for Rails/FilePath
Browse files Browse the repository at this point in the history
  • Loading branch information
tk0miya committed May 2, 2022
1 parent 8119838 commit 4977ea3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
@@ -0,0 +1 @@
* [#700](https://github.com/rubocop/rubocop-rails/issues/700): Fix a false positive for `Rails/FilePath` when a list of paths separated by colon including Rails.root. ([@tk0miya][])
7 changes: 5 additions & 2 deletions lib/rubocop/cop/rails/file_path.rb
Expand Up @@ -48,8 +48,11 @@ class FilePath < Base
def on_dstr(node)
return unless rails_root_nodes?(node)
return unless node.children.last.str_type?
return unless node.children.last.source.start_with?('.') ||
node.children.last.source.include?(File::SEPARATOR)

last_child_source = node.children.last.source
return unless last_child_source.start_with?('.') ||
last_child_source.include?(File::SEPARATOR)
return if last_child_source.start_with?(':')

register_offense(node)
end
Expand Down
16 changes: 16 additions & 0 deletions spec/rubocop/cop/rails/file_path_spec.rb
Expand Up @@ -122,6 +122,14 @@
RUBY
end
end

context 'when concat Rails.root and colon using string interpoloation' do
it 'does not register an offense' do
expect_no_offenses(<<~'RUBY')
"#{Rails.root}:/foo/bar"
RUBY
end
end
end

context 'when EnforcedStyle is `arguments`' do
Expand Down Expand Up @@ -245,5 +253,13 @@
RUBY
end
end

context 'when concat Rails.root and colon using string interpoloation' do
it 'does not register an offense' do
expect_no_offenses(<<~'RUBY')
"#{Rails.root}:/foo/bar"
RUBY
end
end
end
end

0 comments on commit 4977ea3

Please sign in to comment.