diff --git a/Library/Homebrew/rubocops/compact_blank.rb b/Library/Homebrew/rubocops/compact_blank.rb index ed3f17011a..c4cad3679b 100644 --- a/Library/Homebrew/rubocops/compact_blank.rb +++ b/Library/Homebrew/rubocops/compact_blank.rb @@ -1,4 +1,4 @@ -# typed: true # rubocop:todo Sorbet/StrictSigil +# typed: strict # frozen_string_literal: true module RuboCop @@ -87,12 +87,18 @@ module RuboCop false end + sig { + params(arguments: T::Array[RuboCop::AST::Node], receiver_in_block: RuboCop::AST::Node).returns(T::Boolean) + } def use_single_value_block_argument?(arguments, receiver_in_block) - arguments.length == 1 && arguments[0].source == receiver_in_block.source + arguments.length == 1 && arguments[0]&.source == receiver_in_block.source end + sig { + params(arguments: T::Array[RuboCop::AST::Node], receiver_in_block: RuboCop::AST::Node).returns(T::Boolean) + } def use_hash_value_block_argument?(arguments, receiver_in_block) - arguments.length == 2 && arguments[1].source == receiver_in_block.source + arguments.length == 2 && arguments[1]&.source == receiver_in_block.source end sig { params(node: RuboCop::AST::SendNode).returns(Parser::Source::Range) } diff --git a/Library/Homebrew/rubocops/shared/desc_helper.rb b/Library/Homebrew/rubocops/shared/desc_helper.rb index cfab0c1978..858bc86d90 100644 --- a/Library/Homebrew/rubocops/shared/desc_helper.rb +++ b/Library/Homebrew/rubocops/shared/desc_helper.rb @@ -1,4 +1,4 @@ -# typed: true # rubocop:todo Sorbet/StrictSigil +# typed: strict # frozen_string_literal: true require "rubocops/shared/helper_functions" @@ -25,7 +25,8 @@ module RuboCop return end - @offensive_node = desc_call + @offensive_node = T.let(desc_call, T.nilable(RuboCop::AST::Node)) + @name = T.let(name, T.nilable(String)) desc = T.cast(desc_call, RuboCop::AST::SendNode).first_argument @@ -84,9 +85,10 @@ module RuboCop end # Auto correct desc problems. `regex_match_group` must be called before this to populate @offense_source_range. + sig { params(message: String).void } def desc_problem(message) add_offense(@offensive_source_range, message:) do |corrector| - match_data = @offensive_node.source.match(/\A(?["'])(?.*)(?:\k)\Z/) + match_data = @offensive_node&.source&.match(/\A(?["'])(?.*)(?:\k)\Z/) correction = match_data[:correction] quote = match_data[:quote] @@ -112,7 +114,7 @@ module RuboCop next if correction == match_data[:correction] - corrector.replace(@offensive_node.source_range, "#{quote}#{correction}#{quote}") + corrector.replace(@offensive_node&.source_range, "#{quote}#{correction}#{quote}") end end end