Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rubocops/lines: consistency with single non-runtime Python #16364

Merged
merged 1 commit into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 10 additions & 2 deletions Library/Homebrew/rubocops/lines.rb
Original file line number Diff line number Diff line change
Expand Up @@ -375,9 +375,17 @@ def audit_formula(_node, _class_node, _parent_class_node, body_node)
string_content(parameters(dep).first).start_with? "python@"
end

return if python_formula_node.blank?
python_version = if python_formula_node.blank?
other_python_nodes = find_every_method_call_by_name(body_node, :depends_on).select do |dep|
parameters(dep).first.instance_of?(RuboCop::AST::HashNode) &&
string_content(parameters(dep).first.keys.first).start_with?("python@")
end
return if other_python_nodes.size != 1

python_version = string_content(parameters(python_formula_node).first).split("@").last
string_content(parameters(other_python_nodes.first).first.keys.first).split("@").last
else
string_content(parameters(python_formula_node).first).split("@").last
end

find_strings(body_node).each do |str|
content = string_content(str)
Expand Down
40 changes: 40 additions & 0 deletions Library/Homebrew/test/rubocops/text/python_versions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -179,5 +179,45 @@ def install
end
RUBY
end

it "reports no offenses for multiple non-runtime Python dependencies" do
expect_no_offenses(<<~RUBY)
class Foo < Formula
depends_on "python@3.9" => :build
depends_on "python@3.10" => :test

def install
puts "python3.9"
end

test do
puts "python3.10"
end
end
RUBY
end

it "reports and corrects Python references that mismatch single non-runtime Python dependency" do
expect_offense(<<~RUBY)
class Foo < Formula
depends_on "python@3.9" => :build

def install
puts "python@3.8"
^^^^^^^^^^^^ FormulaAudit/PythonVersions: References to `python@3.8` should match the specified python dependency (`python@3.9`)
end
end
RUBY

expect_correction(<<~RUBY)
class Foo < Formula
depends_on "python@3.9" => :build

def install
puts "python@3.9"
end
end
RUBY
end
end
end