Update string_content method to support multiline strings, add test for same
This commit is contained in:
parent
459fef3b09
commit
80572939b4
@ -180,9 +180,10 @@ module RuboCop
|
|||||||
node.source_range.source_buffer
|
node.source_range.source_buffer
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns the string representation if node is of type str
|
# Returns the string representation if node is of type str(plain) or dstr(interpolated)
|
||||||
def string_content(node)
|
def string_content(node)
|
||||||
node.str_content if node.type == :str
|
return node.str_content if node.type == :str
|
||||||
|
node.each_child_node(:str).map(&:str_content).join("") if node.type == :dstr
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns printable component name
|
# Returns printable component name
|
||||||
|
|||||||
@ -51,6 +51,31 @@ describe RuboCop::Cop::FormulaAuditStrict::Desc do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it "When desc is multiline string" do
|
||||||
|
source = <<-EOS.undent
|
||||||
|
class Foo < Formula
|
||||||
|
url 'http://example.com/foo-1.0.tgz'
|
||||||
|
desc '#{"bar"*10}'\
|
||||||
|
'#{"foo"*21}'
|
||||||
|
end
|
||||||
|
EOS
|
||||||
|
|
||||||
|
msg = <<-EOS.undent
|
||||||
|
Description is too long. "name: desc" should be less than 80 characters.
|
||||||
|
Length is calculated as Foo + desc. (currently 98)
|
||||||
|
EOS
|
||||||
|
expected_offenses = [{ message: msg,
|
||||||
|
severity: :convention,
|
||||||
|
line: 3,
|
||||||
|
column: 2,
|
||||||
|
source: source }]
|
||||||
|
|
||||||
|
inspect_source(cop, source)
|
||||||
|
expected_offenses.zip(cop.offenses).each do |expected, actual|
|
||||||
|
expect_offense(expected, actual)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
it "When wrong \"command-line\" usage in desc" do
|
it "When wrong \"command-line\" usage in desc" do
|
||||||
source = <<-EOS.undent
|
source = <<-EOS.undent
|
||||||
class Foo < Formula
|
class Foo < Formula
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user