Merge pull request #8862 from Rylan12/fix-multiline-license-style

style: allow license exceptions to be on one line
This commit is contained in:
Rylan Polster 2020-10-06 09:21:40 -04:00 committed by GitHub
commit 6a4a30e434
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 5 deletions

View File

@ -305,16 +305,20 @@ module RuboCop
def audit_formula(_node, _class_node, _parent_class_node, body_node) def audit_formula(_node, _class_node, _parent_class_node, body_node)
license_node = find_node_method_by_name(body_node, :license) license_node = find_node_method_by_name(body_node, :license)
return unless license_node return unless license_node
return if license_node.source.include?("\n")
license = parameters(license_node).first parameters(license_node).first.each_descendant(:hash).each do |license_hash|
return unless license.hash_type? next if license_exception? license_hash
return unless license.each_descendant(:hash).count.positive?
return if license.source.include?("\n")
problem "Split nested license declarations onto multiple lines" problem "Split nested license declarations onto multiple lines"
end end
end end
def_node_matcher :license_exception?, <<~EOS
(hash (pair (sym :with) str))
EOS
end
# This cop checks for other miscellaneous style violations. # This cop checks for other miscellaneous style violations.
# #
# @api private # @api private

View File

@ -681,6 +681,16 @@ describe RuboCop::Cop::FormulaAudit::Licenses do
RUBY RUBY
end end
it "allow license exceptions" do
expect_no_offenses(<<~RUBY)
class Foo < Formula
desc "foo"
url 'https://brew.sh/foo-1.0.tgz'
license "MIT" => { with: "LLVM-exception" }
end
RUBY
end
it "allow multiline nested license hashes" do it "allow multiline nested license hashes" do
expect_no_offenses(<<~RUBY) expect_no_offenses(<<~RUBY)
class Foo < Formula class Foo < Formula
@ -694,6 +704,20 @@ describe RuboCop::Cop::FormulaAudit::Licenses do
RUBY RUBY
end end
it "allow multiline nested license hashes with exceptions" do
expect_no_offenses(<<~RUBY)
class Foo < Formula
desc "foo"
url 'https://brew.sh/foo-1.0.tgz'
license any_of: [
"MIT",
all_of: ["0BSD", "Zlib"],
"GPL-2.0-only" => { with: "LLVM-exception" },
]
end
RUBY
end
it "require multiple lines for nested license hashes" do it "require multiple lines for nested license hashes" do
expect_offense(<<~RUBY) expect_offense(<<~RUBY)
class Foo < Formula class Foo < Formula