diff --git a/CHANGELOG.md b/CHANGELOG.md index dcd620400a..92ce5fd615 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -589,3 +589,4 @@ [@natematykiewicz]: https://github.com/natematykiewicz [@lulalala]: https://github.com/lulalala [@gmcgibbon]: https://github.com/gmcgibbon +[@tk0miya]: https://github.com/tk0miya diff --git a/changelog/fix_a_false_positive_for_rails_filepath_for_colon_separated_pathlist.md b/changelog/fix_a_false_positive_for_rails_filepath_for_colon_separated_pathlist.md new file mode 100644 index 0000000000..054afda625 --- /dev/null +++ b/changelog/fix_a_false_positive_for_rails_filepath_for_colon_separated_pathlist.md @@ -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][]) diff --git a/lib/rubocop/cop/rails/file_path.rb b/lib/rubocop/cop/rails/file_path.rb index e8258537e4..540c8d3146 100644 --- a/lib/rubocop/cop/rails/file_path.rb +++ b/lib/rubocop/cop/rails/file_path.rb @@ -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) diff --git a/spec/rubocop/cop/rails/file_path_spec.rb b/spec/rubocop/cop/rails/file_path_spec.rb index 6ae24d63bf..24a8c74383 100644 --- a/spec/rubocop/cop/rails/file_path_spec.rb +++ b/spec/rubocop/cop/rails/file_path_spec.rb @@ -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 @@ -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