rubocops/uses_from_macos: audit when depends_on :linux
This commit is contained in:
parent
04d8ae20f3
commit
2f3f017a6e
@ -98,7 +98,12 @@ module RuboCop
|
|||||||
def audit_formula(_node, _class_node, _parent_class_node, body_node)
|
def audit_formula(_node, _class_node, _parent_class_node, body_node)
|
||||||
return if body_node.nil?
|
return if body_node.nil?
|
||||||
|
|
||||||
|
depends_on_linux = depends_on?(:linux)
|
||||||
|
|
||||||
find_method_with_args(body_node, :uses_from_macos, /^"(.+)"/).each do |method|
|
find_method_with_args(body_node, :uses_from_macos, /^"(.+)"/).each do |method|
|
||||||
|
@offensive_node = method
|
||||||
|
problem "`uses_from_macos` should not be used when Linux is required." if depends_on_linux
|
||||||
|
|
||||||
dep = if parameters(method).first.instance_of?(RuboCop::AST::StrNode)
|
dep = if parameters(method).first.instance_of?(RuboCop::AST::StrNode)
|
||||||
parameters(method).first
|
parameters(method).first
|
||||||
elsif parameters(method).first.instance_of?(RuboCop::AST::HashNode)
|
elsif parameters(method).first.instance_of?(RuboCop::AST::HashNode)
|
||||||
|
|||||||
@ -5,16 +5,47 @@ require "rubocops/uses_from_macos"
|
|||||||
describe RuboCop::Cop::FormulaAudit::UsesFromMacos do
|
describe RuboCop::Cop::FormulaAudit::UsesFromMacos do
|
||||||
subject(:cop) { described_class.new }
|
subject(:cop) { described_class.new }
|
||||||
|
|
||||||
it "when auditing uses_from_macos dependencies" do
|
context "when auditing `uses_from_macos` dependencies" do
|
||||||
expect_offense(<<~RUBY)
|
it "reports an offense when used on non-macOS dependency" do
|
||||||
class Foo < Formula
|
expect_offense(<<~RUBY)
|
||||||
url "https://brew.sh/foo-1.0.tgz"
|
class Foo < Formula
|
||||||
homepage "https://brew.sh"
|
url "https://brew.sh/foo-1.0.tgz"
|
||||||
|
homepage "https://brew.sh"
|
||||||
|
|
||||||
uses_from_macos "postgresql"
|
uses_from_macos "postgresql"
|
||||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/UsesFromMacos: `uses_from_macos` should only be used for macOS dependencies, not postgresql.
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/UsesFromMacos: `uses_from_macos` should only be used for macOS dependencies, not postgresql.
|
||||||
end
|
end
|
||||||
RUBY
|
RUBY
|
||||||
|
end
|
||||||
|
|
||||||
|
it "reports offenses for multiple non-macOS dependencies and none for valid macOS dependencies" do
|
||||||
|
expect_offense(<<~RUBY)
|
||||||
|
class Foo < Formula
|
||||||
|
url "https://brew.sh/foo-1.0.tgz"
|
||||||
|
homepage "https://brew.sh"
|
||||||
|
|
||||||
|
uses_from_macos "boost"
|
||||||
|
^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/UsesFromMacos: `uses_from_macos` should only be used for macOS dependencies, not boost.
|
||||||
|
uses_from_macos "bzip2"
|
||||||
|
uses_from_macos "postgresql"
|
||||||
|
^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/UsesFromMacos: `uses_from_macos` should only be used for macOS dependencies, not postgresql.
|
||||||
|
uses_from_macos "zlib"
|
||||||
|
end
|
||||||
|
RUBY
|
||||||
|
end
|
||||||
|
|
||||||
|
it "reports an offense when used in `depends_on :linux` formula" do
|
||||||
|
expect_offense(<<~RUBY)
|
||||||
|
class Foo < Formula
|
||||||
|
url "https://brew.sh/foo-1.0.tgz"
|
||||||
|
homepage "https://brew.sh"
|
||||||
|
|
||||||
|
depends_on :linux
|
||||||
|
uses_from_macos "zlib"
|
||||||
|
^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/UsesFromMacos: `uses_from_macos` should not be used when Linux is required.
|
||||||
|
end
|
||||||
|
RUBY
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
include_examples "formulae exist", described_class::ALLOWED_USES_FROM_MACOS_DEPS
|
include_examples "formulae exist", described_class::ALLOWED_USES_FROM_MACOS_DEPS
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user