From 01cf98e52631ee2eedf3977a8178738303b001e6 Mon Sep 17 00:00:00 2001 From: Rylan Polster Date: Thu, 3 Dec 2020 14:30:34 -0500 Subject: [PATCH] Remove style exceptions for ProvidedByMacos and UsesFromMacos --- Library/Homebrew/rubocops/lines.rb | 2 +- Library/Homebrew/rubocops/uses_from_macos.rb | 15 ++---- Library/Homebrew/test/rubocops/lines_spec.rb | 31 +++++++++++- .../test/rubocops/provided_by_macos_spec.rb | 49 ++++--------------- 4 files changed, 42 insertions(+), 55 deletions(-) diff --git a/Library/Homebrew/rubocops/lines.rb b/Library/Homebrew/rubocops/lines.rb index 31b78a50db..f01fb03ed9 100644 --- a/Library/Homebrew/rubocops/lines.rb +++ b/Library/Homebrew/rubocops/lines.rb @@ -443,7 +443,7 @@ module RuboCop next if key.nil? || value.nil? next unless match = regex_match_group(value, /^(lua|perl|python|ruby)(\d*)/) - problem "#{match[1]} modules should be vendored rather than use deprecated #{method.source}`" + problem "#{match[1]} modules should be vendored rather than use deprecated `#{method.source}`" end find_every_method_call_by_name(body_node, :system).each do |method| diff --git a/Library/Homebrew/rubocops/uses_from_macos.rb b/Library/Homebrew/rubocops/uses_from_macos.rb index 554a16b42c..29da97e467 100644 --- a/Library/Homebrew/rubocops/uses_from_macos.rb +++ b/Library/Homebrew/rubocops/uses_from_macos.rb @@ -50,6 +50,7 @@ module RuboCop texinfo unifdef unzip + whois zip zlib ].freeze @@ -57,17 +58,9 @@ module RuboCop def audit_formula(_node, _class_node, _parent_class_node, body_node) find_method_with_args(body_node, :keg_only, :provided_by_macos) do return if PROVIDED_BY_MACOS_FORMULAE.include? @formula_name - return if tap_style_exception? :provided_by_macos_formulae - message = if formula_tap == "homebrew-core" - "Formulae in homebrew/core that are `keg_only :provided_by_macos` should be "\ - "added to the `PROVIDED_BY_MACOS_FORMULAE` list (in the Homebrew/brew repo)" - else - "Formulae that are `keg_only :provided_by_macos` should be added to "\ - "`style_exceptions/provided_by_macos_formulae.json`" - end - - problem message + problem "Formulae that are `keg_only :provided_by_macos` should be "\ + "added to the `PROVIDED_BY_MACOS_FORMULAE` list (in the Homebrew/brew repo)" end end end @@ -106,8 +99,6 @@ module RuboCop dep_name = string_content(dep) next if ALLOWED_USES_FROM_MACOS_DEPS.include? dep_name next if ProvidedByMacos::PROVIDED_BY_MACOS_FORMULAE.include? dep_name - next if tap_style_exception? :provided_by_macos_formulae, dep_name - next if tap_style_exception? :non_keg_only_provided_by_macos_formulae, dep_name problem "`uses_from_macos` should only be used for macOS dependencies, not #{dep_name}." end diff --git a/Library/Homebrew/test/rubocops/lines_spec.rb b/Library/Homebrew/test/rubocops/lines_spec.rb index 3cb2eade4e..852c1f0226 100644 --- a/Library/Homebrew/test/rubocops/lines_spec.rb +++ b/Library/Homebrew/test/rubocops/lines_spec.rb @@ -1339,7 +1339,7 @@ describe RuboCop::Cop::FormulaAudit::Miscellaneous do desc "foo" url 'https://brew.sh/foo-1.0.tgz' depends_on "lpeg" => :lua51 - ^^^^^ lua modules should be vendored rather than use deprecated depends_on \"lpeg\" => :lua51` + ^^^^^ lua modules should be vendored rather than use deprecated `depends_on \"lpeg\" => :lua51` end RUBY end @@ -1469,8 +1469,23 @@ end describe RuboCop::Cop::FormulaAuditStrict::MakeCheck do subject(:cop) { described_class.new } + let(:path) { Tap::TAP_DIRECTORY/"homebrew/homebrew-core" } + + before do + path.mkpath + (path/"style_exceptions").mkpath + end + + def setup_style_exceptions + (path/"style_exceptions/make_check_allowlist.json").write <<~JSON + [ "bar" ] + JSON + end + it "build-time checks in homebrew/core" do - expect_offense(<<~RUBY, "/homebrew-core/") + setup_style_exceptions + + expect_offense(<<~RUBY, "#{path}/Formula/foo.rb") class Foo < Formula desc "foo" url 'https://brew.sh/foo-1.0.tgz' @@ -1479,6 +1494,18 @@ describe RuboCop::Cop::FormulaAuditStrict::MakeCheck do end RUBY end + + it "build-time checks in homebrew/core in allowlist" do + setup_style_exceptions + + expect_no_offenses(<<~RUBY, "#{path}/Formula/bar.rb") + class Bar < Formula + desc "bar" + url 'https://brew.sh/bar-1.0.tgz' + system "make", "-j1", "test" + end + RUBY + end end describe RuboCop::Cop::FormulaAuditStrict::ShellCommands do diff --git a/Library/Homebrew/test/rubocops/provided_by_macos_spec.rb b/Library/Homebrew/test/rubocops/provided_by_macos_spec.rb index a0035f2b3f..64ad615094 100644 --- a/Library/Homebrew/test/rubocops/provided_by_macos_spec.rb +++ b/Library/Homebrew/test/rubocops/provided_by_macos_spec.rb @@ -6,51 +6,22 @@ require "rubocops/uses_from_macos" describe RuboCop::Cop::FormulaAudit::ProvidedByMacos do subject(:cop) { described_class.new } - let(:path) { Tap::TAP_DIRECTORY/"homebrew/homebrew-foo" } - - before do - path.mkpath - (path/"style_exceptions").mkpath - end - - def setup_style_exceptions - (path/"style_exceptions/provided_by_macos_formulae.json").write <<~JSON - [ "foo", "bar" ] - JSON - end - - it "fails for formulae not in provided_by_macos_formulae list" do - setup_style_exceptions - - expect_offense(<<~RUBY, "#{path}/Formula/baz.rb") + it "fails for formulae not in PROVIDED_BY_MACOS_FORMULAE list" do + expect_offense(<<~RUBY) class Baz < Formula url "https://brew.sh/baz-1.0.tgz" homepage "https://brew.sh" keg_only :provided_by_macos - ^^^^^^^^^^^^^^^^^^^^^^^^^^^ Formulae that are `keg_only :provided_by_macos` should be added to `style_exceptions/provided_by_macos_formulae.json` + ^^^^^^^^^^^^^^^^^^^^^^^^^^^ Formulae that are `keg_only :provided_by_macos` should be added to the `PROVIDED_BY_MACOS_FORMULAE` list (in the Homebrew/brew repo) end RUBY end - it "fails for homebrew-core formulae not in provided_by_macos_formulae list" do - expect_offense(<<~RUBY, "/homebrew-core/") - class Baz < Formula - url "https://brew.sh/baz-1.0.tgz" - homepage "https://brew.sh" - - keg_only :provided_by_macos - ^^^^^^^^^^^^^^^^^^^^^^^^^^^ Formulae in homebrew/core that are `keg_only :provided_by_macos` should be added to the `PROVIDED_BY_MACOS_FORMULAE` list (in the Homebrew/brew repo) - end - RUBY - end - - it "succeeds for formulae in provided_by_macos_formulae list" do - setup_style_exceptions - - expect_no_offenses(<<~RUBY, "#{path}/Formula/foo.rb") - class Foo < Formula - url "https://brew.sh/foo-1.0.tgz" + it "succeeds for formulae in PROVIDED_BY_MACOS_FORMULAE list" do + expect_no_offenses(<<~RUBY, "/homebrew-core/Formula/apr.rb") + class Apr < Formula + url "https://brew.sh/apr-1.0.tgz" homepage "https://brew.sh" keg_only :provided_by_macos @@ -59,10 +30,8 @@ describe RuboCop::Cop::FormulaAudit::ProvidedByMacos do end it "succeeds for formulae that are keg_only for a different reason" do - setup_style_exceptions - - expect_no_offenses(<<~RUBY, "#{path}/Formula/foo.rb") - class Baz < Formula + expect_no_offenses(<<~RUBY) + class Foo < Formula url "https://brew.sh/foo-1.0.tgz" homepage "https://brew.sh"