Skip to content

Commit

Permalink
Fix style/type violations
Browse files Browse the repository at this point in the history
  • Loading branch information
dduugg committed Jan 11, 2024
1 parent 7e083d1 commit 4760978
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 274 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
!**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/
!**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/
!**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/*/
!**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/enumerable.rb
!**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/file/atomic.rb
!**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/hash/deep_merge.rb
!**/vendor/bundle/ruby/*/gems/activesupport-*/lib/active_support/core_ext/hash/deep_transform_values.rb
Expand Down
21 changes: 9 additions & 12 deletions Library/Homebrew/extend/enumerable.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# typed: strict
# frozen_string_literal: true

module Enumerable
Expand All @@ -9,21 +10,20 @@ module Enumerable
#
# people.index_by { |person| "#{person.first_name} #{person.last_name}" }
# # => { "Chade- Fowlersburg-e" => <Person ...>, "David Heinemeier Hansson" => <Person ...>, ...}
def index_by
if block_given?
def index_by(&block)
if block
result = {}
each { |elem| result[yield(elem)] = elem }
result
else
to_enum(:index_by) { size if respond_to?(:size) }
T.unsafe(self).to_enum(:index_by) { T.unsafe(self).size if respond_to?(:size) }
end
end

# The negative of the <tt>Enumerable#include?</tt>. Returns +true+ if the
# collection does not include the object.
def exclude?(object)
!include?(object)
end
sig { params(object: T.untyped).returns(T::Boolean) }
def exclude?(object) = !include?(object)

# Returns a new +Array+ without the blank items.
# Uses Object#blank? for determining if an item is blank.
Expand All @@ -38,14 +38,11 @@ def exclude?(object)
#
# { a: "", b: 1, c: nil, d: [], e: false, f: true }.compact_blank
# # => { b: 1, f: true }
def compact_blank
reject(&:blank?)
end
sig { returns(T.self_type) }
def compact_blank = T.unsafe(self).reject(&:blank?)
end

class Hash
# Hash#reject has its own definition, so this needs one too.
def compact_blank # :nodoc:
reject { |_k, v| v.blank? }
end
def compact_blank = reject { T.unsafe(_2).blank? }
end
17 changes: 17 additions & 0 deletions Library/Homebrew/extend/enumerable.rbi
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# typed: strict

module Enumerable
requires_ancestor { Object }

sig {
type_parameters(:key).params(
block: T.nilable(T.proc.params(o: Enumerable::Elem).returns(T.type_parameter(:key))),
).returns(T::Hash[T.type_parameter(:key), Enumerable::Elem])
}
def index_by(&block); end
end

class Hash
sig { returns(T::Hash[Hash::K, Hash::V]) }
def compact_blank; end
end
2 changes: 1 addition & 1 deletion Library/Homebrew/global.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
require "forwardable"
require "set"

require "active_support/core_ext/enumerable"
require "active_support/core_ext/file/atomic"
require "active_support/core_ext/hash/deep_merge"
require "active_support/core_ext/hash/keys"
Expand Down Expand Up @@ -68,6 +67,7 @@

require "extend/array"
require "extend/blank"
require "extend/enumerable"
require "extend/string"
require "env_config"
require "macos_version"
Expand Down

This file was deleted.

0 comments on commit 4760978

Please sign in to comment.