Merge pull request #3998 from kabel/rubocop-dependency-order-tags

audit: Fix dependency order with multiple tags
This commit is contained in:
Mike McQuaid 2018-03-29 08:15:04 +01:00 committed by GitHub
commit 62e855c863
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 6 deletions

View File

@ -44,14 +44,19 @@ module RuboCop
end
# Separate dependencies according to precedence order:
# build-time > run-time > normal > recommended > optional
# build-time > test > normal > recommended > optional
def sort_dependencies_by_type(dependency_nodes)
unsorted_deps = dependency_nodes.to_a
ordered = []
ordered.concat(dependency_nodes.select { |dep| buildtime_dependency? dep }.to_a)
ordered.concat(dependency_nodes.select { |dep| test_dependency? dep }.to_a)
ordered.concat(dependency_nodes.reject { |dep| negate_normal_dependency? dep }.to_a)
ordered.concat(dependency_nodes.select { |dep| recommended_dependency? dep }.to_a)
ordered.concat(dependency_nodes.select { |dep| optional_dependency? dep }.to_a)
ordered.concat(unsorted_deps.select { |dep| buildtime_dependency? dep })
unsorted_deps -= ordered
ordered.concat(unsorted_deps.select { |dep| test_dependency? dep })
unsorted_deps -= ordered
ordered.concat(unsorted_deps.reject { |dep| negate_normal_dependency? dep })
unsorted_deps -= ordered
ordered.concat(unsorted_deps.select { |dep| recommended_dependency? dep })
unsorted_deps -= ordered
ordered.concat(unsorted_deps.select { |dep| optional_dependency? dep })
end
# `depends_on :apple if build.with? "foo"` should always be defined

View File

@ -46,6 +46,18 @@ describe RuboCop::Cop::NewFormulaAudit::DependencyOrder do
end
RUBY
end
it "correct depends_on order for multiple tags" do
expect_no_offenses(<<~RUBY)
class Foo < Formula
homepage "http://example.com"
url "http://example.com/foo-1.0.tgz"
depends_on "bar" => [:build, :test]
depends_on "foo" => :build
depends_on "apple"
end
RUBY
end
end
context "autocorrect" do