From 4dba9fddf1a12b4d14b5085b30eee999a7c77095 Mon Sep 17 00:00:00 2001 From: commitay Date: Tue, 3 Jul 2018 11:46:39 +1000 Subject: [PATCH] components_redundancy: audit `stable do` without a head or devel spec --- .../rubocops/components_redundancy_cop.rb | 7 +++ .../components_redundancy_cop_spec.rb | 44 +++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/Library/Homebrew/rubocops/components_redundancy_cop.rb b/Library/Homebrew/rubocops/components_redundancy_cop.rb index e22ec6a910..b6986db609 100644 --- a/Library/Homebrew/rubocops/components_redundancy_cop.rb +++ b/Library/Homebrew/rubocops/components_redundancy_cop.rb @@ -8,10 +8,12 @@ module RuboCop # - `url|checksum|mirror` should be inside `stable` block # - `head` and `head do` should not be simultaneously present # - `bottle :unneeded/:disable` and `bottle do` should not be simultaneously present + # - `stable do` should not be present without a `head` or `devel` spec class ComponentsRedundancy < FormulaCop HEAD_MSG = "`head` and `head do` should not be simultaneously present".freeze BOTTLE_MSG = "`bottle :modifier` and `bottle do` should not be simultaneously present".freeze + STABLE_MSG = "`stable do` should not be present without a `head` or `devel` spec".freeze def audit_formula(_node, _class_node, _parent_class_node, body_node) stable_block = find_block(body_node, :stable) @@ -26,6 +28,11 @@ module RuboCop problem BOTTLE_MSG if method_called?(body_node, :bottle) && find_block(body_node, :bottle) + + return if method_called?(body_node, :head) || + find_block(body_node, :head) || + find_block(body_node, :devel) + problem STABLE_MSG if stable_block end end end diff --git a/Library/Homebrew/test/rubocops/components_redundancy_cop_spec.rb b/Library/Homebrew/test/rubocops/components_redundancy_cop_spec.rb index fd325e5846..08ab0210a6 100644 --- a/Library/Homebrew/test/rubocops/components_redundancy_cop_spec.rb +++ b/Library/Homebrew/test/rubocops/components_redundancy_cop_spec.rb @@ -12,6 +12,10 @@ describe RuboCop::Cop::FormulaAudit::ComponentsRedundancy do stable do # stuff end + + devel do + # stuff + end end RUBY end @@ -40,5 +44,45 @@ describe RuboCop::Cop::FormulaAudit::ComponentsRedundancy do end RUBY end + + it "When `stable do` is present with a `head` method" do + expect_no_offenses(<<~RUBY) + class Foo < Formula + head "http://example.com/foo.git" + + stable do + # stuff + end + end + RUBY + end + + it "When `stable do` is present with a `head do` block" do + expect_no_offenses(<<~RUBY) + class Foo < Formula + stable do + # stuff + end + + head do + # stuff + end + end + RUBY + end + + it "When `stable do` is present with a `devel` block" do + expect_no_offenses(<<~RUBY) + class Foo < Formula + stable do + # stuff + end + + devel do + # stuff + end + end + RUBY + end end end