diff --git a/Library/Homebrew/bundle/mac_app_store_dumper.rb b/Library/Homebrew/bundle/mac_app_store_dumper.rb index 390b10d386..1c2d228e65 100644 --- a/Library/Homebrew/bundle/mac_app_store_dumper.rb +++ b/Library/Homebrew/bundle/mac_app_store_dumper.rb @@ -1,4 +1,4 @@ -# typed: true # rubocop:todo Sorbet/StrictSigil +# typed: strict # frozen_string_literal: true require "json" @@ -6,11 +6,14 @@ require "json" module Homebrew module Bundle module MacAppStoreDumper + sig { void } def self.reset! @apps = nil end + sig { returns(T::Array[[String, String]]) } def self.apps + @apps ||= T.let(nil, T.nilable(T::Array[[String, String]])) @apps ||= if Bundle.mas_installed? `mas list 2>/dev/null`.split("\n").map do |app| app_details = app.match(/\A(?\d+)\s+(?.*?)\s+\((?[\d.]*)\)\Z/) @@ -19,7 +22,7 @@ module Homebrew # Strip unprintable characters if app_details name = T.must(app_details[:name]) - [app_details[:id], name.gsub(/[[:cntrl:]]|[\p{C}]/, "")] + [T.must(app_details[:id]), name.gsub(/[[:cntrl:]]|[\p{C}]/, "")] end end else @@ -27,10 +30,12 @@ module Homebrew end.compact end + sig { returns(T::Array[Integer]) } def self.app_ids apps.map { |id, _| id.to_i } end + sig { returns(String) } def self.dump apps.sort_by { |_, name| name.downcase }.map { |id, name| "mas \"#{name}\", id: #{id}" }.join("\n") end