Class: RuboCop::Cop::FormulaAudit::JavaVersions Private
- Inherits:
-
RuboCop::Cop::FormulaCop
- Object
- Base
- RuboCop::Cop::FormulaCop
- RuboCop::Cop::FormulaAudit::JavaVersions
- Extended by:
- AutoCorrector
- Defined in:
- rubocops/lines.rb,
sorbet/rbi/dsl/rubo_cop/cop/formula_audit/java_versions.rbi
Overview
This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.
This cop makes sure that Java versions are consistent.
Instance Attribute Summary
Attributes inherited from RuboCop::Cop::FormulaCop
Instance Method Summary collapse
- #audit_formula(formula_nodes) ⇒ void private
- #java_home_method_call(node, *pattern, **kwargs, &block) ⇒ T.untyped private
- #java_version_assignment(node, *pattern, **kwargs, &block) ⇒ T.untyped private
Methods inherited from RuboCop::Cop::FormulaCop
#audit_comments, #audit_urls, #caveats_strings, #dependency_name_hash_match?, #dependency_type_hash_match?, #depends_on?, #depends_on_name_type?, #formula_tap, #get_checksum_node, #on_class, #required_dependency?, #required_dependency_name?, #style_exceptions_dir, #tap_style_exception?, #versioned_formula?
Methods included from HelperFunctions
#block_method_called_in_block?, #check_precedence, #class_name, #component_precedes?, #end_column, #expression_negated?, #find_all_blocks, #find_block, #find_blocks, #find_const, #find_every_func_call_by_name, #find_every_method_call_by_name, #find_instance_call, #find_instance_method_call, #find_method_calls_by_name, #find_method_def, #find_method_with_args, #find_node_method_by_name, #find_strings, #format_component, #line_number, #line_start_column, #method_called?, #method_called_ever?, #method_name, #node_equals?, #offending_node, #parameters, #parameters_passed?, #problem, #regex_match_group, #source_buffer, #start_column, #string_content
Instance Method Details
#audit_formula(formula_nodes) ⇒ void
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
This method returns an undefined value.
463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 |
# File 'rubocops/lines.rb', line 463 def audit_formula(formula_nodes) return if formula_tap != "homebrew-core" return if (body_node = formula_nodes.body_node).nil? openjdk_dependency_matches = find_every_method_call_by_name(body_node, :depends_on).filter_map do |method| dep = parameters(method).first dep = dep.keys.first if dep.is_a?(RuboCop::AST::HashNode) string_content(dep).match(/^openjdk(?:@(\d+(?:\.\d+)*))?$/) end # Only handle single OpenJDK dependency scenario return if openjdk_dependency_matches.count != 1 openjdk_dependency_match = openjdk_dependency_matches.fetch(0) openjdk_version = openjdk_dependency_match[1] openjdk_version = "1.8" if openjdk_version == "8" = "Java version argument should match the specified dependency (`#{openjdk_dependency_match[0]}`)" variables = [] # e.g. Language::Java.overridable_java_home_env("25") java_home_method_call(body_node) do |java_home_node, method, args| java_version_node = args.first java_version = nil case java_version_node when nil java_version = nil when RuboCop::AST::StrNode java_version = string_content(java_version_node) when RuboCop::AST::VarNode variables << java_version_node.name next else next unless java_version_node.nil_type? if openjdk_version.nil? offending_node(java_version_node) problem "Argument is unnecessary when using unversioned OpenJDK" do |corrector| corrector.replace(java_home_node.source_range, "Language::Java.#{method}") end end end next if java_version == openjdk_version correct = "Language::Java.#{method}" correct += "(\"#{openjdk_version}\")" if openjdk_version offending_node(java_version_node || java_home_node) problem do |corrector| corrector.replace(java_home_node.source_range, correct) end end # e.g. bin.write_jar_script libexec/"<name>.jar", "<name>", java_version: "25" find_instance_method_call(body_node, :bin, :write_jar_script) do |method| params = parameters(method) next unless (last_param = params.last) java_version = nil java_version_node = nil if last_param.is_a?(RuboCop::AST::HashNode) java_version_arg_node = last_param.pairs.find { |pair| pair.key.value == :java_version } java_version_node = java_version_arg_node&.value case java_version_node when nil java_version = nil when RuboCop::AST::StrNode java_version = string_content(java_version_node) when RuboCop::AST::VarNode variables << java_version_node.name next else next unless java_version_node.nil_type? end end next if openjdk_version == java_version offending_node(java_version_node || method) problem do |corrector| if java_version_node.nil? corrector.insert_after(last_param.source_range, ", java_version: \"#{openjdk_version}\"") elsif openjdk_version.nil? range = range_with_surrounding_space(range: last_param.source_range, side: :left) corrector.remove(range_with_surrounding_comma(range, :left)) else corrector.replace(java_version_node.source_range, "\"#{openjdk_version}\"") end end end # e.g. java_version = "25"; Language::Java.overridable_java_home_env(java_version) variables.uniq! variables.each do |variable| java_version_assignment(body_node, variable:) do |java_version_node| java_version = nil java_version = string_content(java_version_node) if java_version_node.str_type? next if java_version == openjdk_version correct = openjdk_version ? "\"#{openjdk_version}\"" : "nil" offending_node(java_version_node) problem do |corrector| corrector.replace(java_version_node.source_range, correct) end end end end |
#java_home_method_call(node, *pattern, **kwargs, &block) ⇒ T.untyped
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
17 |
# File 'sorbet/rbi/dsl/rubo_cop/cop/formula_audit/java_versions.rbi', line 17 def java_home_method_call(node, *pattern, **kwargs, &block); end |
#java_version_assignment(node, *pattern, **kwargs, &block) ⇒ T.untyped
This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.
27 |
# File 'sorbet/rbi/dsl/rubo_cop/cop/formula_audit/java_versions.rbi', line 27 def java_version_assignment(node, *pattern, **kwargs, &block); end |