diff --git a/Library/Homebrew/rubocops/lines_cop.rb b/Library/Homebrew/rubocops/lines_cop.rb index 49eff510d8c5a9a6dc472b2ece30ced0246166ab..d3640c9efa05219f519d6ddae9d0eb8bad0ad7e2 100644 --- a/Library/Homebrew/rubocops/lines_cop.rb +++ b/Library/Homebrew/rubocops/lines_cop.rb @@ -124,15 +124,15 @@ module RuboCop problem "\"\#\{share}#{match[1]}\" should be \"\#{#{match[2]}}\"" end - formula_path_strings(body_node, :share) do |p| - if match = regex_match_group(p, %r{/(bin|include|libexec|lib|sbin|share|Frameworks)}i) - problem "\"\#\{prefix}#{match[1]}\" should be \"\#{#{match[1].downcase}}\"" + formula_path_strings(body_node, :prefix) do |p| + if match = regex_match_group(p, %r{(/share/(info|man))$}) + problem "\"\#\{prefix}#{match[1]}\" should be \"\#{#{match[2]}}\"" end - if match = regex_match_group(p, %r{((/share/man/|\#\{man\}/)(man[1-8]))}) + if match = regex_match_group(p, %r{((/share/man/)(man[1-8]))}) problem "\"\#\{prefix}#{match[1]}\" should be \"\#{#{match[3]}}\"" end - if match = regex_match_group(p, %r{(/share/(info|man))}) - problem "\"\#\{prefix}#{match[1]}\" should be \"\#{#{match[2]}}\"" + if match = regex_match_group(p, %r{(/(bin|include|libexec|lib|sbin|share|Frameworks))}i) + problem "\"\#\{prefix}#{match[1]}\" should be \"\#{#{match[2].downcase}}\"" end end @@ -350,7 +350,8 @@ module RuboCop EOS def_node_search :formula_path_strings, <<-EOS.undent - (dstr (begin (send nil %1)) $(str _ )) + {(dstr (begin (send nil %1)) $(str _ )) + (dstr _ (begin (send nil %1)) $(str _ ))} EOS def_node_matcher :negation?, '(send ... :!)' diff --git a/Library/Homebrew/test/rubocops/lines_cop_spec.rb b/Library/Homebrew/test/rubocops/lines_cop_spec.rb index 63ae88dd9e448ade3bd62e9ce270373ac3bceb92..1d25c472110d54a8265031be578fa80ec2e37baa 100644 --- a/Library/Homebrew/test/rubocops/lines_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/lines_cop_spec.rb @@ -979,6 +979,78 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do expect_offense(expected, actual) end end + + it "with formula path shortcut long form 1" do + source = <<-EOS.undent + class Foo < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + def install + mv "\#{prefix}/libexec", share + end + end + EOS + + expected_offenses = [{ message: "\"\#\{prefix}/libexec\" should be \"\#{libexec}\"", + severity: :convention, + line: 5, + column: 18, + source: source }] + + inspect_source(cop, source) + + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + + it "with formula path shortcut long form 2" do + source = <<-EOS.undent + class Foo < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + def install + system "./configure", "--INFODIR=\#{prefix}/share/info" + end + end + EOS + + expected_offenses = [{ message: "\"\#\{prefix}/share/info\" should be \"\#{info}\"", + severity: :convention, + line: 5, + column: 47, + source: source }] + + inspect_source(cop, source) + + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + it "with formula path shortcut long form 3" do + source = <<-EOS.undent + class Foo < Formula + desc "foo" + url 'http://example.com/foo-1.0.tgz' + def install + system "./configure", "--MANDIR=\#{prefix}/share/man/man8" + end + end + EOS + + expected_offenses = [{ message: "\"\#\{prefix}/share/man/man8\" should be \"\#{man8}\"", + severity: :convention, + line: 5, + column: 46, + source: source }] + + inspect_source(cop, source) + + expected_offenses.zip(cop.offenses).each do |expected, actual| + expect_offense(expected, actual) + end + end + end def expect_offense(expected, actual) expect(actual.message).to eq(expected[:message])