From 9d55fed15f27f9bb2816a93a71edc2ec05128488 Mon Sep 17 00:00:00 2001 From: commitay Date: Tue, 22 May 2018 19:39:10 +1000 Subject: [PATCH] audit: new formulae should not have options --- Library/Homebrew/dev-cmd/audit.rb | 7 +++++++ Library/Homebrew/rubocops/options_cop.rb | 7 +++++-- Library/Homebrew/test/rubocops/options_cop_spec.rb | 10 ++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb index 9c978357ce..4489a536b6 100644 --- a/Library/Homebrew/dev-cmd/audit.rb +++ b/Library/Homebrew/dev-cmd/audit.rb @@ -408,6 +408,13 @@ module Homebrew if dep.tags.include?(:run) problem "Dependency '#{dep.name}' is marked as :run. Remove :run; it is a no-op." end + + next unless @new_formula + next if formula.versioned_formula? + next unless @official_tap + if dep.tags.include?(:recommended) || dep.tags.include?(:optional) + new_formula_problem "Formulae should not have #{dep.tags} dependencies." + end end end end diff --git a/Library/Homebrew/rubocops/options_cop.rb b/Library/Homebrew/rubocops/options_cop.rb index c162441610..7818787c4a 100644 --- a/Library/Homebrew/rubocops/options_cop.rb +++ b/Library/Homebrew/rubocops/options_cop.rb @@ -46,11 +46,14 @@ module RuboCop module NewFormulaAudit class Options < FormulaCop - MSG = "New Formula should not use `deprecated_option`".freeze + DEP_OPTION = "New Formula should not use `deprecated_option`".freeze + OPTION = "Formula should not have an `option`".freeze def audit_formula(_node, _class_node, _parent_class_node, body_node) return if versioned_formula? - problem MSG if method_called_ever?(body_node, :deprecated_option) + problem DEP_OPTION if method_called_ever?(body_node, :deprecated_option) + return unless formula_tap == "homebrew-core" + problem OPTION if method_called_ever?(body_node, :option) end end end diff --git a/Library/Homebrew/test/rubocops/options_cop_spec.rb b/Library/Homebrew/test/rubocops/options_cop_spec.rb index b888f4315c..d44f044487 100644 --- a/Library/Homebrew/test/rubocops/options_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/options_cop_spec.rb @@ -64,5 +64,15 @@ describe RuboCop::Cop::NewFormulaAudit::Options do end RUBY end + + it "with options" do + expect_offense(<<~RUBY, "/homebrew-core/") + class Foo < Formula + url 'http://example.com/foo-1.0.tgz' + option "with-examples" + ^^^^^^^^^^^^^^^^^^^^^^ Formula should not have an `option` + end + RUBY + end end end