style: forbid one line nested license expressions
This commit is contained in:
parent
ef447a38c6
commit
97b1b75dc5
@ -272,6 +272,20 @@ module RuboCop
|
||||
end
|
||||
end
|
||||
|
||||
class Licenses < FormulaCop
|
||||
def audit_formula(_node, _class_node, _parent_class_node, body_node)
|
||||
license_node = find_node_method_by_name(body_node, :license)
|
||||
return unless license_node
|
||||
|
||||
license = parameters(license_node).first
|
||||
return unless license.hash_type?
|
||||
return unless license.each_descendant(:hash).count.positive?
|
||||
return if license.source.include?("\n")
|
||||
|
||||
problem "Split nested license declarations onto multiple lines"
|
||||
end
|
||||
end
|
||||
|
||||
class Miscellaneous < FormulaCop
|
||||
def audit_formula(_node, _class_node, _parent_class_node, body_node)
|
||||
# FileUtils is included in Formula
|
||||
|
||||
@ -647,6 +647,66 @@ describe RuboCop::Cop::FormulaAudit::LicenseArrays do
|
||||
end
|
||||
end
|
||||
|
||||
describe RuboCop::Cop::FormulaAudit::Licenses do
|
||||
subject(:cop) { described_class.new }
|
||||
|
||||
context "When auditing licenses" do
|
||||
it "allow license strings" do
|
||||
expect_no_offenses(<<~RUBY)
|
||||
class Foo < Formula
|
||||
desc "foo"
|
||||
url 'https://brew.sh/foo-1.0.tgz'
|
||||
license "MIT"
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "allow license symbols" do
|
||||
expect_no_offenses(<<~RUBY)
|
||||
class Foo < Formula
|
||||
desc "foo"
|
||||
url 'https://brew.sh/foo-1.0.tgz'
|
||||
license :public_domain
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "allow license hashes" do
|
||||
expect_no_offenses(<<~RUBY)
|
||||
class Foo < Formula
|
||||
desc "foo"
|
||||
url 'https://brew.sh/foo-1.0.tgz'
|
||||
license any_of: ["MIT", "0BSD"]
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "allow multiline nested license hashes" 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"],
|
||||
]
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "require multiple lines for nested license hashes" do
|
||||
expect_offense(<<~RUBY)
|
||||
class Foo < Formula
|
||||
desc "foo"
|
||||
url 'https://brew.sh/foo-1.0.tgz'
|
||||
license any_of: ["MIT", all_of: ["0BSD", "Zlib"]]
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Split nested license declarations onto multiple lines
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe RuboCop::Cop::FormulaAudit::Miscellaneous do
|
||||
subject(:cop) { described_class.new }
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user