diff options
| author | Gautham Goli | 2017-05-13 18:44:37 +0530 |
|---|---|---|
| committer | Gautham Goli | 2017-05-13 18:48:40 +0530 |
| commit | 80572939b4ba691e6dc754e1151dd46ac5dcbca4 (patch) | |
| tree | 8d5e52e13a50ff7e9586e7aaf39bcaa86582002a | |
| parent | 459fef3b09b25d3e24cce6aa6f2e3a7bd5460a2b (diff) | |
| download | brew-80572939b4ba691e6dc754e1151dd46ac5dcbca4.tar.bz2 | |
Update string_content method to support multiline strings, add test for same
| -rw-r--r-- | Library/Homebrew/rubocops/extend/formula_cop.rb | 5 | ||||
| -rw-r--r-- | Library/Homebrew/test/rubocops/formula_desc_cop_spec.rb | 25 |
2 files changed, 28 insertions, 2 deletions
diff --git a/Library/Homebrew/rubocops/extend/formula_cop.rb b/Library/Homebrew/rubocops/extend/formula_cop.rb index 4120be6ef..3f70086b3 100644 --- a/Library/Homebrew/rubocops/extend/formula_cop.rb +++ b/Library/Homebrew/rubocops/extend/formula_cop.rb @@ -180,9 +180,10 @@ module RuboCop node.source_range.source_buffer 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) - 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 # Returns printable component name diff --git a/Library/Homebrew/test/rubocops/formula_desc_cop_spec.rb b/Library/Homebrew/test/rubocops/formula_desc_cop_spec.rb index 581667935..432b15e3c 100644 --- a/Library/Homebrew/test/rubocops/formula_desc_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/formula_desc_cop_spec.rb @@ -51,6 +51,31 @@ describe RuboCop::Cop::FormulaAuditStrict::Desc do 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 source = <<-EOS.undent class Foo < Formula |
