diff --git a/Library/.rubocop.yml b/Library/.rubocop.yml index 9d8602f9df..2107cf2f89 100644 --- a/Library/.rubocop.yml +++ b/Library/.rubocop.yml @@ -15,9 +15,10 @@ AllCops: TargetRubyVersion: 3.1 NewCops: enable Include: - - "**/*.rbi" + # FIXME: https://github.com/rubocop/rubocop/issues/12695 + - "Homebrew/**/*.rbi" Exclude: - - "Homebrew/sorbet/rbi/gems/**/*.rbi" + - "Homebrew/sorbet/rbi/{dsl,gems}/**/*.rbi" - "Homebrew/bin/*" - "Homebrew/vendor/**/*" - "Taps/*/*/vendor/**/*" @@ -259,6 +260,10 @@ Sorbet/ConstantsFromStrings: Sorbet/FalseSigil: Enabled: false +# We generally prefer to colo rbi files with the Ruby files they describe. +Sorbet/ForbidRBIOutsideOfAllowedPaths: + Enabled: false + # T::Sig is monkey-patched into Module Sorbet/RedundantExtendTSig: Enabled: true @@ -295,6 +300,10 @@ Style/BlockDelimiters: BracesRequiredMethods: - "sig" +Style/ClassAndModuleChildren: + Exclude: + - "**/*.rbi" + # Use consistent style for better readability. Style/CollectionMethods: Enabled: true @@ -382,6 +391,7 @@ Style/OpenStructUse: # TODO: This is a pre-existing violation and should be corrected # to define methods so that call sites can be type-checked. - "Homebrew/cli/args.rb" + - "Homebrew/cli/args.rbi" # Rescuing `StandardError` is an understood default. Style/RescueStandardError: diff --git a/Library/Homebrew/cli/args.rbi b/Library/Homebrew/cli/args.rbi index e5394d4d7b..e51b8fe18f 100644 --- a/Library/Homebrew/cli/args.rbi +++ b/Library/Homebrew/cli/args.rbi @@ -321,7 +321,7 @@ module Homebrew sig { returns(T.nilable(String)) } def screen_saverdir; end - sig { returns(T::Array[String])} + sig { returns(T::Array[String]) } def repositories; end sig { returns(T.nilable(String)) } diff --git a/Library/Homebrew/dependencies.rbi b/Library/Homebrew/dependencies.rbi index 652ce4f99d..ea20b01d7e 100644 --- a/Library/Homebrew/dependencies.rbi +++ b/Library/Homebrew/dependencies.rbi @@ -4,8 +4,8 @@ class Dependencies < SimpleDelegator include Kernel # This is a workaround to enable `alias eql? ==` # @see https://github.com/sorbet/sorbet/issues/2378#issuecomment-569474238 - sig { params(arg0: BasicObject).returns(T::Boolean) } - def ==(arg0); end + sig { params(other: BasicObject).returns(T::Boolean) } + def ==(other); end end class Requirements < SimpleDelegator diff --git a/Library/Homebrew/download_strategy.rbi b/Library/Homebrew/download_strategy.rbi index 4fe282238f..0df06cf3b1 100644 --- a/Library/Homebrew/download_strategy.rbi +++ b/Library/Homebrew/download_strategy.rbi @@ -4,15 +4,20 @@ module AbstractDownloadStrategy::Pourable requires_ancestor { AbstractDownloadStrategy } end +# This is a third-party implementation +# rubocop:disable Lint/StructNewOverride class Mechanize::HTTP ContentDisposition = Struct.new :type, :filename, :creation_date, - :modification_date, :read_date, :size, :parameters + :modification_date, :read_date, :size, :parameters end +# rubocop:enable Lint/StructNewOverride +# rubocop:disable Style/OptionalBooleanParameter class Mechanize::HTTP::ContentDispositionParser sig { params(content_disposition: String, header: T::Boolean) - .returns(T.nilable(Mechanize::HTTP::ContentDisposition)) + .returns(T.nilable(Mechanize::HTTP::ContentDisposition)) } def parse(content_disposition, header = false); end end +# rubocop:enable Style/OptionalBooleanParameter diff --git a/Library/Homebrew/extend/hash/deep_merge.rbi b/Library/Homebrew/extend/hash/deep_merge.rbi index ed5f3a9b6c..a2a316e1b5 100644 --- a/Library/Homebrew/extend/hash/deep_merge.rbi +++ b/Library/Homebrew/extend/hash/deep_merge.rbi @@ -2,19 +2,19 @@ # frozen_string_literal: true class Hash - sig do + sig { type_parameters(:k2).params( other_hash: T::Hash[T.type_parameter(:k2), T.untyped], - block: T.nilable(T.proc.params(k: T.untyped, v1: T.untyped, v2: T.untyped).returns(T.untyped)) + block: T.nilable(T.proc.params(k: T.untyped, v1: T.untyped, v2: T.untyped).returns(T.untyped)), ).returns(T::Hash[T.any(Hash::K, T.type_parameter(:k2)), T.untyped]) - end + } def deep_merge(other_hash, &block); end - sig do + sig { type_parameters(:k2).params( other_hash: T::Hash[T.type_parameter(:k2), T.untyped], - block: T.nilable(T.proc.params(k: T.untyped, v1: T.untyped, v2: T.untyped).returns(T.untyped)) + block: T.nilable(T.proc.params(k: T.untyped, v1: T.untyped, v2: T.untyped).returns(T.untyped)), ).returns(T::Hash[T.any(Hash::K, T.type_parameter(:k2)), T.untyped]) - end + } def deep_merge!(other_hash, &block); end end diff --git a/Library/Homebrew/extend/hash/deep_transform_values.rbi b/Library/Homebrew/extend/hash/deep_transform_values.rbi index 29c8d273e2..8eece3e2dc 100644 --- a/Library/Homebrew/extend/hash/deep_transform_values.rbi +++ b/Library/Homebrew/extend/hash/deep_transform_values.rbi @@ -3,14 +3,14 @@ class Hash sig { type_parameters(:out).params( - block: T.proc.params(o: Hash::V).returns(T.type_parameter(:out)) + block: T.proc.params(o: Hash::V).returns(T.type_parameter(:out)), ).returns(T::Hash[Hash::K, T.type_parameter(:out)]) } def deep_transform_values(&block); end sig { type_parameters(:out).params( - block: T.proc.params(o: Hash::V).returns(T.type_parameter(:out)) + block: T.proc.params(o: Hash::V).returns(T.type_parameter(:out)), ).returns(T::Hash[Hash::K, T.type_parameter(:out)]) } def deep_transform_values!(&block); end diff --git a/Library/Homebrew/extend/hash/keys.rbi b/Library/Homebrew/extend/hash/keys.rbi index 581c876f7f..ed4e6a6eb8 100644 --- a/Library/Homebrew/extend/hash/keys.rbi +++ b/Library/Homebrew/extend/hash/keys.rbi @@ -4,14 +4,14 @@ class Hash sig { type_parameters(:out).params( - block: T.proc.params(o: K).returns(T.type_parameter(:out)) + block: T.proc.params(o: K).returns(T.type_parameter(:out)), ).returns(T::Hash[T.type_parameter(:out), V]) } def deep_transform_keys(&block); end sig { type_parameters(:out).params( - block: T.proc.params(o: K).returns(T.type_parameter(:out)) + block: T.proc.params(o: K).returns(T.type_parameter(:out)), ).returns(T::Hash[T.type_parameter(:out), V]) } def deep_transform_keys!(&block); end diff --git a/Library/Homebrew/pkg_version.rbi b/Library/Homebrew/pkg_version.rbi index c49afd3a5b..41f19badd3 100644 --- a/Library/Homebrew/pkg_version.rbi +++ b/Library/Homebrew/pkg_version.rbi @@ -3,6 +3,6 @@ class PkgVersion # This is a workaround to enable `alias eql? ==` # @see https://github.com/sorbet/sorbet/issues/2378#issuecomment-569474238 - sig { params(arg0: BasicObject).returns(T::Boolean) } - def ==(arg0); end + sig { params(other: BasicObject).returns(T::Boolean) } + def ==(other); end end diff --git a/Library/Homebrew/sorbet/rbi/parlour.rbi b/Library/Homebrew/sorbet/rbi/parlour.rbi index 92c7d251b0..80fa50d439 100644 --- a/Library/Homebrew/sorbet/rbi/parlour.rbi +++ b/Library/Homebrew/sorbet/rbi/parlour.rbi @@ -1,4 +1,5 @@ # typed: strict + class PATH sig { params(args: T.untyped, options: T.untyped, block: T.untyped).returns(T.untyped) } def each(*args, **options, &block); end diff --git a/Library/Homebrew/sorbet/rbi/upstream.rbi b/Library/Homebrew/sorbet/rbi/upstream.rbi index 1c15b292f8..2aa21d6a36 100644 --- a/Library/Homebrew/sorbet/rbi/upstream.rbi +++ b/Library/Homebrew/sorbet/rbi/upstream.rbi @@ -3,14 +3,6 @@ # This file contains temporary definitions for fixes that have # been submitted upstream to https://github.com/sorbet/sorbet. -# https://github.com/sorbet/sorbet/pull/7682 -class Array - include JSON::Ext::Generator::GeneratorMethods::Array -end -class Hash - include JSON::Ext::Generator::GeneratorMethods::Hash -end - # https://github.com/sorbet/sorbet/pull/7650 class Etc::Group < Struct sig { returns(Integer) } @@ -28,111 +20,3 @@ module IRB sig { params(ap_path: T.nilable(String), argv: T::Array[String]).void } def self.setup(ap_path, argv: ::ARGV); end end - -# https://github.com/sorbet/sorbet/pull/7678 -class String - sig do - params( - arg0: Integer, - arg1: Integer, - ) - .returns(T.nilable(String)) - end - sig do - params( - arg0: T.any(T::Range[Integer], Regexp), - ) - .returns(T.nilable(String)) - end - sig do - params( - arg0: Regexp, - arg1: Integer, - ) - .returns(T.nilable(String)) - end - sig do - params( - arg0: Regexp, - arg1: T.any(String, Symbol), - ) - .returns(T.nilable(String)) - end - sig do - params( - arg0: String, - ) - .returns(T.nilable(String)) - end - def [](arg0, arg1=T.unsafe(nil)); end - - sig do - params( - arg0: Integer, - arg1: Integer, - ) - .returns(T.nilable(String)) - end - sig do - params( - arg0: T.any(T::Range[Integer], Regexp), - ) - .returns(T.nilable(String)) - end - sig do - params( - arg0: Regexp, - arg1: Integer, - ) - .returns(T.nilable(String)) - end - sig do - params( - arg0: Regexp, - arg1: T.any(String, Symbol), - ) - .returns(T.nilable(String)) - end - sig do - params( - arg0: String, - ) - .returns(T.nilable(String)) - end - def slice!(arg0, arg1=T.unsafe(nil)); end - - sig do - params( - arg0: Integer, - arg1: Integer, - ) - .returns(T.nilable(String)) - end - sig do - params( - arg0: T.any(T::Range[Integer], Regexp), - ) - .returns(T.nilable(String)) - end - sig do - params( - arg0: Regexp, - arg1: Integer, - ) - .returns(T.nilable(String)) - end - sig do - params( - arg0: Regexp, - arg1: T.any(String, Symbol), - ) - .returns(T.nilable(String)) - end - sig do - params( - arg0: String, - ) - .returns(T.nilable(String)) - end - def slice(arg0, arg1=T.unsafe(nil)); end -end