Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 10 additions & 18 deletions Library/Homebrew/rubocops/class.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,21 @@ def audit_formula(formula_nodes)
end
end

# This cop makes sure that a `test` block contains a proper test.
# This cop makes sure that a `test` block exists and contains a real test.
class Test < FormulaCop
extend AutoCorrector

sig { override.params(formula_nodes: FormulaNodes).void }
def audit_formula(formula_nodes)
test = find_block(formula_nodes.body_node, :test)
return unless test
body_node = formula_nodes.body_node
test = find_block(body_node, :test)
if test.nil?
return if find_node_method_by_name(body_node, :disable!)

offending_node(formula_nodes.class_node) if body_node.nil?
problem "A `test do` test block should be added"
Comment thread
issyl0 marked this conversation as resolved.
return
end

if test.body.nil?
problem "`test do` should not be empty"
Expand Down Expand Up @@ -130,20 +137,5 @@ def audit_formula(formula_nodes)
end
end
end

module FormulaAuditStrict
# This cop makes sure that a `test` block exists.
class TestPresent < FormulaCop
sig { override.params(formula_nodes: FormulaNodes).void }
def audit_formula(formula_nodes)
body_node = formula_nodes.body_node
return if find_block(body_node, :test)
return if find_node_method_by_name(body_node, :disable!)

offending_node(formula_nodes.class_node) if body_node.nil?
problem "A `test do` test block should be added"
end
end
end
end
end

This file was deleted.

4 changes: 2 additions & 2 deletions Library/Homebrew/sorbet/rbi/shims/portable_formula.rbi
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# typed: strict

# Not a real formula, just a Sorbet shim for external taps.
# rubocop:disable FormulaAudit/Desc,FormulaAudit/Homepage
# rubocop:disable FormulaAudit/Desc,FormulaAudit/Homepage,FormulaAudit/Test
class PortableFormula < Formula
extend T::Generic

# This is required for type checking on official taps to initially succeed
# This could also be added to homebrew-core/Abstract/portable-formula.rb and subsequently removed here
Cache = type_template { { fixed: T::Hash[Symbol, T.untyped] } }
end
# rubocop:enable FormulaAudit/Desc,FormulaAudit/Homepage
# rubocop:enable FormulaAudit/Desc,FormulaAudit/Homepage,FormulaAudit/Test
27 changes: 0 additions & 27 deletions Library/Homebrew/test/rubocops/class/test_present.rb

This file was deleted.

19 changes: 19 additions & 0 deletions Library/Homebrew/test/rubocops/class/test_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,25 @@
RSpec.describe RuboCop::Cop::FormulaAudit::Test do
subject(:cop) { described_class.new }

it "reports an offense when there is no test block" do
expect_offense(<<~RUBY)
class Foo < Formula
^^^^^^^^^^^^^^^^^^^ FormulaAudit/Test: A `test do` test block should be added
url 'https://brew.sh/foo-1.0.tgz'
end
RUBY
end

it "reports no offenses when there is no test block and formula is disabled" do
expect_no_offenses(<<~RUBY)
class Foo < Formula
url 'https://brew.sh/foo-1.0.tgz'

disable! date: "2024-07-03", because: :unsupported
end
RUBY
end

it "allows existing resources inside test blocks without a strict audit" do
expect_no_offenses(<<~RUBY)
class Foo < Formula
Expand Down
4 changes: 4 additions & 0 deletions docs/.rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ FormulaAudit/Desc:
FormulaAudit/Homepage:
Enabled: false

# The formula blocks in docs are deliberately truncated to only include bits relevant to the doc's purpose.
FormulaAudit/Test:
Enabled: false

Layout/LineLength:
Exclude:
- "**/Bottles.md" # The bottle block line length is long in its full form.
Expand Down
Loading