Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

build(deps): bump rubocop-sorbet from 0.7.3 to 0.7.4 in /Library/Homebrew #16034

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion Library/Homebrew/Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ GEM
rubocop-rspec (2.20.0)
rubocop (~> 1.33)
rubocop-capybara (~> 2.17)
rubocop-sorbet (0.7.3)
rubocop-sorbet (0.7.4)
rubocop (>= 0.90.0)
ruby-macho (4.0.0)
ruby-prof (1.4.3)
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Library/Homebrew/sorbet/rbi/hidden-definitions/hidden.rbi
Original file line number Diff line number Diff line change
Expand Up @@ -7114,6 +7114,7 @@ module RuboCop::AST::NodePattern::Sets
SET_OR_NEWER_OR_OLDER = ::T.let(nil, ::T.untyped)
SET_SIG_HELPERS = ::T.let(nil, ::T.untyped)
SET_STRUCT_IMMUTABLESTRUCT = ::T.let(nil, ::T.untyped)
SET_STRUCT_IMMUTABLESTRUCT_INEXACTSTRUCT = ::T.let(nil, ::T.untyped)
SET_SYSTEM_SHELL_OUTPUT_PIPE_OUTPUT = ::T.let(nil, ::T.untyped)
SET_WITH_WITHOUT = ::T.let(nil, ::T.untyped)
SET____ETC_4 = ::T.let(nil, ::T.untyped)
Expand Down
2 changes: 1 addition & 1 deletion Library/Homebrew/vendor/bundle/bundler/setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def self.extension_api_version
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rubocop-performance-1.17.1/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rubocop-rails-2.19.1/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rubocop-rspec-2.20.0/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rubocop-sorbet-0.7.3/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rubocop-sorbet-0.7.4/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/ruby-macho-4.0.0/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/extensions/universal-darwin-22/#{Gem.extension_api_version}/ruby-prof-1.4.3")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/ruby-prof-1.4.3/lib")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,13 @@ Sorbet/ForbidSuperclassConstLiteral:
Exclude:
- db/migrate/*.rb

Sorbet/ForbidTStruct:
Description: 'Forbid usage of T::Struct.'
Enabled: false
VersionAdded: <<next>>
VersionChanged: <<next>>
Safe: false

Sorbet/ForbidTUnsafe:
Description: 'Forbid usage of T.unsafe.'
Enabled: false
Expand Down Expand Up @@ -171,6 +178,23 @@ Sorbet/ObsoleteStrictMemoization:
Safe: true
SafeAutoCorrect: true

Sorbet/BuggyObsoleteStrictMemoization:
Description: >-
Checks for the a mistaken variant of the "obsolete memoization pattern" that used to be required
for older Sorbet versions in `#typed: strict` files. The mistaken variant would overwrite the ivar with `nil`
on every call, causing the memoized value to be discarded and recomputed on every call.

This cop will correct it to read from the ivar instead of `nil`, which will memoize it correctly.

The result of this correction will be the "obsolete memoization pattern", which can further be corrected by
the `Sorbet/ObsoleteStrictMemoization` cop.

See `Sorbet/ObsoleteStrictMemoization` for more details.
Enabled: true
VersionAdded: '0.7.3'
Safe: true
SafeAutoCorrect: false

Sorbet/OneAncestorPerLine:
Description: 'Enforces one ancestor per call to requires_ancestor'
Enabled: false
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# frozen_string_literal: true

require "rubocop"

module RuboCop
module Cop
module Sorbet
# Checks for the a mistaken variant of the "obsolete memoization pattern" that used to be required
# for older Sorbet versions in `#typed: strict` files. The mistaken variant would overwrite the ivar with `nil`
# on every call, causing the memoized value to be discarded and recomputed on every call.
#
# This cop will correct it to read from the ivar instead of `nil`, which will memoize it correctly.
#
# The result of this correction will be the "obsolete memoization pattern", which can further be corrected by
# the `Sorbet/ObsoleteStrictMemoization` cop.
#
# See `Sorbet/ObsoleteStrictMemoization` for more details.
#
# @safety
# If the computation being memoized had side effects, calling it only once (instead of once on every call
# to the affected method) can be observed, and might be a breaking change.
#
# @example
# # bad
# sig { returns(Foo) }
# def foo
# # This `nil` is likely a mistake, causing the memoized value to be discarded and recomputed on every call.
# @foo = T.let(nil, T.nilable(Foo))
# @foo ||= some_computation
# end
#
# # good
# sig { returns(Foo) }
# def foo
# # This will now memoize the value as was likely intended, so `some_computation` is only ever called once.
# # ⚠️If `some_computation` has side effects, this might be a breaking change!
# @foo = T.let(@foo, T.nilable(Foo))
# @foo ||= some_computation
# end
#
# @see Sorbet/ObsoleteStrictMemoization
class BuggyObsoleteStrictMemoization < RuboCop::Cop::Base
include RuboCop::Cop::MatchRange
include RuboCop::Cop::Alignment
include RuboCop::Cop::LineLengthHelp
include RuboCop::Cop::RangeHelp
extend AutoCorrector

include TargetSorbetVersion

MSG = "This might be a mistaken variant of the two-stage workaround that used to be needed for memoization in "\
"`#typed: strict` files. See https://sorbet.org/docs/type-assertions#put-type-assertions-behind-memoization."

# @!method buggy_legacy_memoization_pattern?(node)
def_node_matcher :buggy_legacy_memoization_pattern?, <<~PATTERN
(begin
... # Ignore any other lines that come first.
(ivasgn $_ivar # First line: @_ivar = ...
(send # T.let(_ivar, T.nilable(_ivar_type))
(const {nil? cbase} :T) :let
$nil
(send (const {nil? cbase} :T) :nilable _ivar_type))) # T.nilable(_ivar_type)
(or-asgn (ivasgn _ivar) _initialization_expr)) # Second line: @_ivar ||= _initialization_expr
PATTERN

def on_begin(node)
buggy_legacy_memoization_pattern?(node) do |ivar, nil_node|
add_offense(nil_node) do |corrector|
corrector.replace(
range_between(nil_node.source_range.begin_pos, nil_node.source_range.end_pos),
ivar,
)
end
end
end

def relevant_file?(file)
super && sorbet_enabled?
end
end
end
end
end