Skip to content
Snippets Groups Projects
Commit 9ad342eb authored by Rylan Polster's avatar Rylan Polster
Browse files

style: don't concatenate in string interpolation

parent 63b81d84
No related branches found
No related tags found
No related merge requests found
......@@ -843,12 +843,6 @@ module Homebrew
problem "Don't need to interpolate \"#{Regexp.last_match(2)}\" with #{Regexp.last_match(1)}"
end
# Check for string concatenation; prefer interpolation
if line =~ /(#\{\w+\s*\+\s*['"][^}]+\})/
# TODO: check could be in RuboCop
problem "Try not to concatenate paths in string interpolation:\n #{Regexp.last_match(1)}"
end
# Prefer formula path shortcuts in Pathname+
if line =~ %r{\(\s*(prefix\s*\+\s*(['"])(bin|include|libexec|lib|sbin|share|Frameworks)[/'"])}
# TODO: check could be in RuboCop
......
......@@ -69,6 +69,15 @@ module RuboCop
offending_node(m)
problem "Use separate `make` calls"
end
body_node.each_descendant(:dstr) do |dstr_node|
dstr_node.each_descendant(:begin) do |interpolation_node|
next unless interpolation_node.source.match?(/#\{\w+\s*\+\s*['"][^}]+\}/)
offending_node(interpolation_node)
problem "Do not concatenate paths in string interpolation"
end
end
end
end
end
......
......@@ -226,6 +226,17 @@ describe RuboCop::Cop::FormulaAudit::Text do
end
RUBY
end
it "When concatenating in string interpolation" do
expect_offense(<<~RUBY)
class Foo < Formula
def install
ohai "foo \#{bar + "baz"}"
^^^^^^^^^^^^^^ Do not concatenate paths in string interpolation
end
end
RUBY
end
end
end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment