style: require java dependency for JAVA_HOME
This commit is contained in:
parent
9ad342eba0
commit
b4a9565b8b
@ -852,13 +852,6 @@ module Homebrew
|
||||
)
|
||||
end
|
||||
|
||||
if line =~ /JAVA_HOME/i &&
|
||||
[formula.name, *formula.deps.map(&:name)].none? { |name| name.match?(/^openjdk(@|$)/) } &&
|
||||
formula.requirements.none? { |req| req.is_a?(JavaRequirement) }
|
||||
# TODO: check could be in RuboCop
|
||||
problem "Use `depends_on :java` to set JAVA_HOME"
|
||||
end
|
||||
|
||||
return unless @strict
|
||||
|
||||
# TODO: check could be in RuboCop
|
||||
|
||||
@ -78,6 +78,21 @@ module RuboCop
|
||||
problem "Do not concatenate paths in string interpolation"
|
||||
end
|
||||
end
|
||||
|
||||
find_strings(body_node).each do |n|
|
||||
next unless regex_match_group(n, /JAVA_HOME/i)
|
||||
|
||||
next if @formula_name.match?(/^openjdk(@|$)/)
|
||||
|
||||
next if find_every_method_call_by_name(body_node, :depends_on).any? do |dependency|
|
||||
dependency.each_descendant(:str).count.zero? ||
|
||||
regex_match_group(dependency.each_descendant(:str).first, /^openjdk(@|$)/) ||
|
||||
depends_on?(:java)
|
||||
end
|
||||
|
||||
offending_node(n)
|
||||
problem "Use `depends_on :java` to set JAVA_HOME"
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@ -237,6 +237,61 @@ describe RuboCop::Cop::FormulaAudit::Text do
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "When using JAVA_HOME without a java dependency" do
|
||||
expect_offense(<<~RUBY)
|
||||
class Foo < Formula
|
||||
def install
|
||||
ohai "JAVA_HOME"
|
||||
^^^^^^^^^^^ Use `depends_on :java` to set JAVA_HOME
|
||||
end
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "When using JAVA_HOME with an openjdk dependency" do
|
||||
expect_no_offenses(<<~RUBY)
|
||||
class Foo < Formula
|
||||
depends_on "openjdk"
|
||||
def install
|
||||
ohai "JAVA_HOME"
|
||||
end
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "When using JAVA_HOME with an openjdk build dependency" do
|
||||
expect_no_offenses(<<~RUBY)
|
||||
class Foo < Formula
|
||||
depends_on "openjdk" => :build
|
||||
def install
|
||||
ohai "JAVA_HOME"
|
||||
end
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "When using JAVA_HOME with a java dependency" do
|
||||
expect_no_offenses(<<~RUBY)
|
||||
class Foo < Formula
|
||||
depends_on :java
|
||||
def install
|
||||
ohai "JAVA_HOME"
|
||||
end
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
|
||||
it "When using JAVA_HOME with a java build dependency" do
|
||||
expect_no_offenses(<<~RUBY)
|
||||
class Foo < Formula
|
||||
depends_on :java => :build
|
||||
def install
|
||||
ohai "JAVA_HOME"
|
||||
end
|
||||
end
|
||||
RUBY
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user