Skip to content

Commit

Permalink
[Fix rubocop#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 85a0c2d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -589,3 +589,4 @@
[@natematykiewicz]: https://github.com/natematykiewicz
[@lulalala]: https://github.com/lulalala
[@gmcgibbon]: https://github.com/gmcgibbon
[@tk0miya]: https://github.com/tk0miya
@@ -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][])
1 change: 1 addition & 0 deletions lib/rubocop/cop/rails/file_path.rb
Expand Up @@ -48,6 +48,7 @@ class FilePath < Base
def on_dstr(node)
return unless rails_root_nodes?(node)
return unless node.children.last.str_type?
return if node.children.last.source.start_with?(':')
return unless node.children.last.source.start_with?('.') ||
node.children.last.source.include?(File::SEPARATOR)

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 85a0c2d

Please sign in to comment.