Merge pull request #14529 from Homebrew/dependabot/bundler/Library/Homebrew/rubocop-sorbet-0.7.0

build(deps): bump rubocop-sorbet from 0.6.11 to 0.7.0 in /Library/Homebrew
This commit is contained in:
Mike McQuaid 2023-02-06 21:17:37 +01:00 committed by GitHub
commit fe9af82808
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
43 changed files with 171 additions and 22 deletions

View File

@ -154,7 +154,7 @@ GEM
rubocop-rspec (2.18.1) rubocop-rspec (2.18.1)
rubocop (~> 1.33) rubocop (~> 1.33)
rubocop-capybara (~> 2.17) rubocop-capybara (~> 2.17)
rubocop-sorbet (0.6.11) rubocop-sorbet (0.7.0)
rubocop (>= 0.90.0) rubocop (>= 0.90.0)
ruby-macho (3.0.0) ruby-macho (3.0.0)
ruby-progressbar (1.11.0) ruby-progressbar (1.11.0)

View File

@ -830,8 +830,8 @@ class GitDownloadStrategy < VCSDownloadStrategy
end end
# @see VCSDownloadStrategy#last_commit # @see VCSDownloadStrategy#last_commit
sig { returns(String) }
# @api public # @api public
sig { returns(String) }
def last_commit def last_commit
out, = silent_command("git", args: ["--git-dir", git_dir, "rev-parse", "--short=7", "HEAD"]) out, = silent_command("git", args: ["--git-dir", git_dir, "rev-parse", "--short=7", "HEAD"])
out.chomp out.chomp

View File

@ -484,7 +484,6 @@ module ObserverPathnameExtension
end end
sig { returns([Integer, Integer]) } sig { returns([Integer, Integer]) }
def counts def counts
[n, d] [n, d]
end end

View File

@ -6,6 +6,7 @@
module RuboCop; end module RuboCop; end
module RuboCop::Cop; end module RuboCop::Cop; end
RuboCop::Cop::IgnoredMethods = RuboCop::Cop::AllowedMethods
RuboCop::Cop::IgnoredPattern = RuboCop::Cop::AllowedPattern RuboCop::Cop::IgnoredPattern = RuboCop::Cop::AllowedPattern
module RuboCop::Cop::Sorbet; end module RuboCop::Cop::Sorbet; end
@ -55,6 +56,17 @@ class RuboCop::Cop::Sorbet::ConstantsFromStrings < ::RuboCop::Cop::Cop
def on_send(node); end def on_send(node); end
end end
class RuboCop::Cop::Sorbet::EmptyLineAfterSig < ::RuboCop::Cop::Sorbet::SignatureCop
include ::RuboCop::Cop::RangeHelp
def autocorrect(node); end
def on_signature(node); end
private
def next_method(node); end
end
class RuboCop::Cop::Sorbet::EnforceSigilOrder < ::RuboCop::Cop::Sorbet::ValidSigil class RuboCop::Cop::Sorbet::EnforceSigilOrder < ::RuboCop::Cop::Sorbet::ValidSigil
include ::RuboCop::Cop::RangeHelp include ::RuboCop::Cop::RangeHelp
@ -175,6 +187,7 @@ end
class RuboCop::Cop::Sorbet::ForbidUntypedStructProps < ::RuboCop::Cop::Cop class RuboCop::Cop::Sorbet::ForbidUntypedStructProps < ::RuboCop::Cop::Cop
def on_class(node); end def on_class(node); end
def subclass_of_t_struct?(param0 = T.unsafe(nil)); end def subclass_of_t_struct?(param0 = T.unsafe(nil)); end
def t_immutable_struct(param0 = T.unsafe(nil)); end
def t_nilable_untyped(param0 = T.unsafe(nil)); end def t_nilable_untyped(param0 = T.unsafe(nil)); end
def t_struct(param0 = T.unsafe(nil)); end def t_struct(param0 = T.unsafe(nil)); end
def t_untyped(param0 = T.unsafe(nil)); end def t_untyped(param0 = T.unsafe(nil)); end
@ -223,6 +236,15 @@ end
RuboCop::Cop::Sorbet::OneAncestorPerLine::MSG = T.let(T.unsafe(nil), String) RuboCop::Cop::Sorbet::OneAncestorPerLine::MSG = T.let(T.unsafe(nil), String)
class RuboCop::Cop::Sorbet::RedundantExtendTSig < ::RuboCop::Cop::Cop
def autocorrect(node); end
def extend_t_sig?(param0 = T.unsafe(nil)); end
def on_send(node); end
end
RuboCop::Cop::Sorbet::RedundantExtendTSig::MSG = T.let(T.unsafe(nil), String)
RuboCop::Cop::Sorbet::RedundantExtendTSig::RESTRICT_ON_SEND = T.let(T.unsafe(nil), Array)
class RuboCop::Cop::Sorbet::SignatureBuildOrder < ::RuboCop::Cop::Sorbet::SignatureCop class RuboCop::Cop::Sorbet::SignatureBuildOrder < ::RuboCop::Cop::Sorbet::SignatureCop
def autocorrect(node); end def autocorrect(node); end
def on_signature(node); end def on_signature(node); end
@ -239,7 +261,6 @@ class RuboCop::Cop::Sorbet::SignatureBuildOrder::ModernBuilder < ::RuboCop::AST:
RuboCop::Cop::Sorbet::SignatureBuildOrder::ORDER = T.let(T.unsafe(nil), Hash) RuboCop::Cop::Sorbet::SignatureBuildOrder::ORDER = T.let(T.unsafe(nil), Hash)
class RuboCop::Cop::Sorbet::SignatureCop < ::RuboCop::Cop::Cop class RuboCop::Cop::Sorbet::SignatureCop < ::RuboCop::Cop::Cop
def allowed_recv(recv); end
def on_block(node); end def on_block(node); end
def on_signature(_); end def on_signature(_); end
def signature?(param0 = T.unsafe(nil)); end def signature?(param0 = T.unsafe(nil)); end

View File

@ -108,7 +108,7 @@ $:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rubocop-performance-1.15.2/lib") $:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rubocop-performance-1.15.2/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rubocop-rails-2.17.4/lib") $:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rubocop-rails-2.17.4/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rubocop-rspec-2.18.1/lib") $:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rubocop-rspec-2.18.1/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rubocop-sorbet-0.6.11/lib") $:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/rubocop-sorbet-0.7.0/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/ruby-macho-3.0.0/lib") $:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/ruby-macho-3.0.0/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/simplecov-html-0.12.3/lib") $:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/simplecov-html-0.12.3/lib")
$:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/simplecov_json_formatter-0.1.4/lib") $:.unshift File.expand_path("#{__dir__}/../#{RUBY_ENGINE}/#{Gem.ruby_api_version}/gems/simplecov_json_formatter-0.1.4/lib")

View File

@ -25,6 +25,11 @@ Sorbet/CheckedTrueInSignature:
Enabled: true Enabled: true
VersionAdded: 0.2.0 VersionAdded: 0.2.0
Sorbet/EmptyLineAfterSig:
Description: 'Ensures that there are no blank lines after signatures'
Enabled: true
VersionAdded: 0.7.0
Sorbet/ConstantsFromStrings: Sorbet/ConstantsFromStrings:
Description: >- Description: >-
Forbids constant access through meta-programming. Forbids constant access through meta-programming.
@ -42,7 +47,7 @@ Sorbet/EnforceSigilOrder:
Sorbet/EnforceSingleSigil: Sorbet/EnforceSingleSigil:
Description: 'Ensures that there is only one Sorbet sigil in a file.' Description: 'Ensures that there is only one Sorbet sigil in a file.'
Enabled: true Enabled: true
VersionAdded: '<<next>>' VersionAdded: 0.7.0
Sorbet/EnforceSignatures: Sorbet/EnforceSignatures:
Description: 'Ensures all methods have a valid signature.' Description: 'Ensures all methods have a valid signature.'
@ -73,6 +78,7 @@ Sorbet/ForbidRBIOutsideOfAllowedPaths:
Enabled: true Enabled: true
VersionAdded: 0.6.1 VersionAdded: 0.6.1
AllowedPaths: AllowedPaths:
- "rbi/**"
- "sorbet/rbi/**" - "sorbet/rbi/**"
Include: Include:
- "**/*.rbi" - "**/*.rbi"
@ -150,6 +156,16 @@ Sorbet/OneAncestorPerLine:
Enabled: false Enabled: false
VersionAdded: '0.6.0' VersionAdded: '0.6.0'
Sorbet/RedundantExtendTSig:
Description: >-
Forbid the usage of redundant `extend T::Sig`.
Only for use in applications that monkey patch `Module.include(T::Sig)` directly,
where it is useful to reduce noise.
Enabled: false
Safe: false
VersionAdded: 0.7.0
Sorbet/SignatureBuildOrder: Sorbet/SignatureBuildOrder:
Description: >- Description: >-
Enforces the order of parts in a signature. Enforces the order of parts in a signature.

View File

@ -7,18 +7,18 @@ module RuboCop
module Cop module Cop
module Sorbet module Sorbet
# This cop disallows use of `T.untyped` or `T.nilable(T.untyped)` # This cop disallows use of `T.untyped` or `T.nilable(T.untyped)`
# as a prop type for `T::Struct`. # as a prop type for `T::Struct` or `T::ImmutableStruct`.
# #
# @example # @example
# #
# # bad # # bad
# class SomeClass # class SomeClass < T::Struct
# const :foo, T.untyped # const :foo, T.untyped
# prop :bar, T.nilable(T.untyped) # prop :bar, T.nilable(T.untyped)
# end # end
# #
# # good # # good
# class SomeClass # class SomeClass < T::Struct
# const :foo, Integer # const :foo, Integer
# prop :bar, T.nilable(String) # prop :bar, T.nilable(String)
# end # end
@ -29,6 +29,10 @@ module RuboCop
(const (const nil? :T) :Struct) (const (const nil? :T) :Struct)
PATTERN PATTERN
def_node_matcher :t_immutable_struct, <<~PATTERN
(const (const nil? :T) :ImmutableStruct)
PATTERN
def_node_matcher :t_untyped, <<~PATTERN def_node_matcher :t_untyped, <<~PATTERN
(send (const nil? :T) :untyped) (send (const nil? :T) :untyped)
PATTERN PATTERN
@ -38,7 +42,7 @@ module RuboCop
PATTERN PATTERN
def_node_matcher :subclass_of_t_struct?, <<~PATTERN def_node_matcher :subclass_of_t_struct?, <<~PATTERN
(class (const ...) #t_struct ...) (class (const ...) {#t_struct #t_immutable_struct} ...)
PATTERN PATTERN
def_node_search :untyped_props, <<~PATTERN def_node_search :untyped_props, <<~PATTERN

View File

@ -9,7 +9,7 @@ module RuboCop
# #
# Options: # Options:
# #
# * `AllowedPaths`: A list of the paths where RBI files are allowed (default: ["sorbet/rbi/**"]) # * `AllowedPaths`: A list of the paths where RBI files are allowed (default: ["rbi/**", "sorbet/rbi/**"])
# #
# @example # @example
# # bad # # bad
@ -17,6 +17,7 @@ module RuboCop
# # other_file.rbi # # other_file.rbi
# #
# # good # # good
# # rbi/external_interface.rbi
# # sorbet/rbi/some_file.rbi # # sorbet/rbi/some_file.rbi
# # sorbet/rbi/any/path/for/file.rbi # # sorbet/rbi/any/path/for/file.rbi
class ForbidRBIOutsideOfAllowedPaths < RuboCop::Cop::Cop class ForbidRBIOutsideOfAllowedPaths < RuboCop::Cop::Cop

View File

@ -0,0 +1,50 @@
# frozen_string_literal: true
module RuboCop
module Cop
module Sorbet
# Forbids the use of redundant `extend T::Sig`. Only for use in
# applications that monkey patch `Module.include(T::Sig)` globally,
# which would make it redundant.
#
# @safety
# This cop should not be enabled in applications that have not monkey
# patched `Module`.
#
# @example
# # bad
# class Example
# extend T::Sig
# sig { void }
# def no_op; end
# end
#
# # good
# class Example
# sig { void }
# def no_op; end
# end
#
class RedundantExtendTSig < RuboCop::Cop::Cop
MSG = "Do not redundantly `extend T::Sig` when it is already included in all modules."
RESTRICT_ON_SEND = [:extend].freeze
def_node_matcher :extend_t_sig?, <<~PATTERN
(send _ :extend (const (const {nil? | cbase} :T) :Sig))
PATTERN
def on_send(node)
return unless extend_t_sig?(node)
add_offense(node)
end
def autocorrect(node)
lambda do |corrector|
corrector.remove(node)
end
end
end
end
end
end

View File

@ -7,7 +7,7 @@ module RuboCop
module Sorbet module Sorbet
# This cop checks that the Sorbet sigil comes as the first magic comment in the file. # This cop checks that the Sorbet sigil comes as the first magic comment in the file.
# #
# The expected order for magic comments is: typed, (en)?coding, warn_indent then frozen_string_literal. # The expected order for magic comments is: (en)?coding, typed, warn_indent then frozen_string_literal.
# #
# For example, the following bad ordering: # For example, the following bad ordering:
# #
@ -25,7 +25,7 @@ module RuboCop
# class Foo; end # class Foo; end
# ``` # ```
# #
# Only `typed`, `(en)?coding`, `warn_indent` and `frozen_string_literal` magic comments are considered, # Only `(en)?coding`, `typed`, `warn_indent` and `frozen_string_literal` magic comments are considered,
# other comments or magic comments are left in the same place. # other comments or magic comments are left in the same place.
class EnforceSigilOrder < ValidSigil class EnforceSigilOrder < ValidSigil
include RangeHelp include RangeHelp

View File

@ -0,0 +1,57 @@
# frozen_string_literal: true
require_relative "signature_cop"
module RuboCop
module Cop
module Sorbet
# This cop checks for blank lines after signatures.
#
# It also suggests an autocorrect
#
# @example
#
# # bad
# sig { void }
#
# def foo; end
#
# # good
# sig { void }
# def foo; end
#
class EmptyLineAfterSig < SignatureCop
include RangeHelp
def on_signature(node)
if (next_method(node).line - node.last_line) > 1
location = source_range(processed_source.buffer, next_method(node).line - 1, 0)
add_offense(node, location: location, message: "Extra empty line or comment detected")
end
end
def autocorrect(node)
-> (corrector) do
offending_range = node.source_range.with(
begin_pos: node.source_range.end_pos + 1,
end_pos: processed_source.buffer.line_range(next_method(node).line).begin_pos
)
corrector.remove(offending_range)
clean_range = offending_range.source.split("\n").reject(&:empty?).join("\n")
offending_line = processed_source.buffer.line_range(node.source_range.first_line)
corrector.insert_before(offending_line, "#{clean_range}\n") unless clean_range.empty?
end
end
private
def next_method(node)
processed_source.tokens.find do |t|
t.line >= node.last_line &&
(t.type == :kDEF || t.text.start_with?("attr_"))
end
end
end
end
end
end

View File

@ -94,6 +94,8 @@ module RuboCop
end end
def call_chain(sig_child_node) def call_chain(sig_child_node)
return [] if sig_child_node.nil?
call_node = root_call(sig_child_node).first call_node = root_call(sig_child_node).first
return [] unless call_node return [] unless call_node

View File

@ -12,7 +12,11 @@ module RuboCop
@registry = Cop.registry # So we can properly subclass this cop @registry = Cop.registry # So we can properly subclass this cop
def_node_matcher(:signature?, <<~PATTERN) def_node_matcher(:signature?, <<~PATTERN)
(block (send #allowed_recv :sig) (args) ...) (block (send
{nil? #with_runtime? #without_runtime?}
:sig
(sym :final)?
) (args) ...)
PATTERN PATTERN
def_node_matcher(:with_runtime?, <<~PATTERN) def_node_matcher(:with_runtime?, <<~PATTERN)
@ -23,13 +27,6 @@ module RuboCop
(const (const (const nil? :T) :Sig) :WithoutRuntime) (const (const (const nil? :T) :Sig) :WithoutRuntime)
PATTERN PATTERN
def allowed_recv(recv)
return true unless recv
return true if with_runtime?(recv)
return true if without_runtime?(recv)
false
end
def on_block(node) def on_block(node)
on_signature(node) if signature?(node) on_signature(node) if signature?(node)
end end

View File

@ -8,6 +8,7 @@ require_relative "sorbet/one_ancestor_per_line"
require_relative "sorbet/callback_conditionals_binding" require_relative "sorbet/callback_conditionals_binding"
require_relative "sorbet/forbid_t_unsafe" require_relative "sorbet/forbid_t_unsafe"
require_relative "sorbet/forbid_t_untyped" require_relative "sorbet/forbid_t_untyped"
require_relative "sorbet/redundant_extend_t_sig"
require_relative "sorbet/type_alias_name" require_relative "sorbet/type_alias_name"
require_relative "sorbet/rbi/forbid_extend_t_sig_helpers_in_shims" require_relative "sorbet/rbi/forbid_extend_t_sig_helpers_in_shims"
@ -19,6 +20,7 @@ require_relative "sorbet/signatures/checked_true_in_signature"
require_relative "sorbet/signatures/keyword_argument_ordering" require_relative "sorbet/signatures/keyword_argument_ordering"
require_relative "sorbet/signatures/signature_build_order" require_relative "sorbet/signatures/signature_build_order"
require_relative "sorbet/signatures/enforce_signatures" require_relative "sorbet/signatures/enforce_signatures"
require_relative "sorbet/signatures/empty_line_after_sig"
require_relative "sorbet/sigils/valid_sigil" require_relative "sorbet/sigils/valid_sigil"
require_relative "sorbet/sigils/has_sigil" require_relative "sorbet/sigils/has_sigil"

View File

@ -1,6 +1,6 @@
# frozen_string_literal: true # frozen_string_literal: true
module RuboCop module RuboCop
module Sorbet module Sorbet
VERSION = "0.6.11" VERSION = "0.7.0"
end end
end end