Skip to content

Commit

Permalink
Add MPICH cop and test
Browse files Browse the repository at this point in the history
 - Split off from PR #6209
 - Create stand alone class for cop w/ auto-correct
  • Loading branch information
zbeekman committed Jun 6, 2019
1 parent 1475554 commit ffe3005
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
18 changes: 18 additions & 0 deletions Library/Homebrew/rubocops/lines.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,24 @@ def unless_modifier?(node)
end
end

class MpiCheck < FormulaCop
def audit_formula(_node, _class_node, _parent_class_node, body_node)
# Enforce use of OpenMPI for MPI dependency in core
return unless formula_tap == "homebrew-core"

find_method_with_args(body_node, :depends_on, "mpich") do
problem "Use 'depends_on \"open-mpi\"' instead of '#{@offensive_node.source}'."
end
end

def autocorrect(node)
# The dependency nodes may need to be re-sorted because of this
lambda do |corrector|
corrector.replace(node.source_range, "depends_on \"open-mpi\"")
end
end
end

class Miscellaneous < FormulaCop
def audit_formula(_node, _class_node, _parent_class_node, body_node)
# FileUtils is included in Formula
Expand Down
17 changes: 17 additions & 0 deletions Library/Homebrew/test/rubocops/lines_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,23 @@ def options
end
end

describe RuboCop::Cop::FormulaAudit::MpiCheck do
subject(:cop) { described_class.new }

context "When auditing formula" do
it "reports an offense when using depends_on \"mpich\"" do
expect_offense(<<~RUBY, "/homebrew-core/")
class Foo < Formula
desc "foo"
url 'https://brew.sh/foo-1.0.tgz'
depends_on "mpich"
^^^^^^^^^^^^^^^^^^ Use 'depends_on "open-mpi"' instead of 'depends_on "mpich"'.
end
RUBY
end
end
end

describe RuboCop::Cop::FormulaAudit::Miscellaneous do
subject(:cop) { described_class.new }

Expand Down

0 comments on commit ffe3005

Please sign in to comment.