style: don't concatenate in string interpolation
This commit is contained in:
parent
63b81d847a
commit
9ad342eba0
@ -843,12 +843,6 @@ module Homebrew
|
|||||||
problem "Don't need to interpolate \"#{Regexp.last_match(2)}\" with #{Regexp.last_match(1)}"
|
problem "Don't need to interpolate \"#{Regexp.last_match(2)}\" with #{Regexp.last_match(1)}"
|
||||||
end
|
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+
|
# Prefer formula path shortcuts in Pathname+
|
||||||
if line =~ %r{\(\s*(prefix\s*\+\s*(['"])(bin|include|libexec|lib|sbin|share|Frameworks)[/'"])}
|
if line =~ %r{\(\s*(prefix\s*\+\s*(['"])(bin|include|libexec|lib|sbin|share|Frameworks)[/'"])}
|
||||||
# TODO: check could be in RuboCop
|
# TODO: check could be in RuboCop
|
||||||
|
|||||||
@ -69,6 +69,15 @@ module RuboCop
|
|||||||
offending_node(m)
|
offending_node(m)
|
||||||
problem "Use separate `make` calls"
|
problem "Use separate `make` calls"
|
||||||
end
|
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
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -226,6 +226,17 @@ describe RuboCop::Cop::FormulaAudit::Text do
|
|||||||
end
|
end
|
||||||
RUBY
|
RUBY
|
||||||
end
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user