Skip to content
Snippets Groups Projects
Unverified Commit ffe30058 authored by Izaak Beekman's avatar Izaak Beekman
Browse files

Add MPICH cop and test

 - Split off from PR Homebrew/brew#6209
 - Create stand alone class for cop w/ auto-correct
parent 14755541
No related branches found
No related tags found
No related merge requests found
......@@ -157,6 +157,24 @@ module RuboCop
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
......
......@@ -279,6 +279,23 @@ describe RuboCop::Cop::FormulaAudit::OptionDeclarations do
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 }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment