Merge pull request #18367 from Homebrew/skip-sorbet-assignments

Exclude sorbet assignments from Style/MutableConstant cop
This commit is contained in:
Mike McQuaid 2024-09-23 09:02:03 +01:00 committed by GitHub
commit 06f60ffaf3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
12 changed files with 46 additions and 36 deletions

View File

@ -10,14 +10,10 @@ class PATH
delegate each: :@paths delegate each: :@paths
# FIXME: Enable cop again when https://github.com/sorbet/sorbet/issues/3532 is fixed.
# rubocop:disable Style/MutableConstant
Element = T.type_alias { T.nilable(T.any(Pathname, String, PATH)) } Element = T.type_alias { T.nilable(T.any(Pathname, String, PATH)) }
private_constant :Element private_constant :Element
Elements = T.type_alias { T.any(Element, T::Array[Element]) } Elements = T.type_alias { T.any(Element, T::Array[Element]) }
private_constant :Elements private_constant :Elements
# rubocop:enable Style/MutableConstant
sig { params(paths: Elements).void } sig { params(paths: Elements).void }
def initialize(*paths) def initialize(*paths)
@paths = parse(paths) @paths = parse(paths)

View File

@ -10,11 +10,7 @@ module Cask
requires_ancestor { Kernel } requires_ancestor { Kernel }
# FIXME: Enable cop again when https://github.com/sorbet/sorbet/issues/3532 is fixed.
# rubocop:disable Style/MutableConstant
Paths = T.type_alias { T.any(String, Pathname, T::Array[T.any(String, Pathname)]) } Paths = T.type_alias { T.any(String, Pathname, T::Array[T.any(String, Pathname)]) }
# rubocop:enable Style/MutableConstant
sig { params(paths: Paths, permissions_str: String).void } sig { params(paths: Paths, permissions_str: String).void }
def set_permissions(paths, permissions_str) def set_permissions(paths, permissions_str)
full_paths = remove_nonexistent(paths) full_paths = remove_nonexistent(paths)

View File

@ -6,16 +6,12 @@ require "ostruct"
module Homebrew module Homebrew
module CLI module CLI
class Args < OpenStruct class Args < OpenStruct
# FIXME: Enable cop again when https://github.com/sorbet/sorbet/issues/3532 is fixed.
# rubocop:disable Style/MutableConstant
# Represents a processed option. The array elements are: # Represents a processed option. The array elements are:
# 0: short option name (e.g. "-d") # 0: short option name (e.g. "-d")
# 1: long option name (e.g. "--debug") # 1: long option name (e.g. "--debug")
# 2: option description (e.g. "Print debugging information") # 2: option description (e.g. "Print debugging information")
# 3: whether the option is hidden # 3: whether the option is hidden
OptionsType = T.type_alias { T::Array[[String, T.nilable(String), String, T::Boolean]] } OptionsType = T.type_alias { T::Array[[String, T.nilable(String), String, T::Boolean]] }
# rubocop:enable Style/MutableConstant
sig { returns(T::Array[String]) } sig { returns(T::Array[String]) }
attr_reader :options_only, :flags_only attr_reader :options_only, :flags_only

View File

@ -13,10 +13,7 @@ require "utils/formatter"
module Homebrew module Homebrew
module CLI module CLI
class Parser class Parser
# FIXME: Enable cop again when https://github.com/sorbet/sorbet/issues/3532 is fixed.
# rubocop:disable Style/MutableConstant
ArgType = T.type_alias { T.any(NilClass, Symbol, T::Array[String], T::Array[Symbol]) } ArgType = T.type_alias { T.any(NilClass, Symbol, T::Array[String], T::Array[Symbol]) }
# rubocop:enable Style/MutableConstant
HIDDEN_DESC_PLACEHOLDER = "@@HIDDEN@@" HIDDEN_DESC_PLACEHOLDER = "@@HIDDEN@@"
SYMBOL_TO_USAGE_MAPPING = T.let({ SYMBOL_TO_USAGE_MAPPING = T.let({
text_or_regex: "<text>|`/`<regex>`/`", text_or_regex: "<text>|`/`<regex>`/`",

View File

@ -5,8 +5,6 @@ require "test_runner_formula"
require "github_runner" require "github_runner"
class GitHubRunnerMatrix class GitHubRunnerMatrix
# FIXME: Enable cop again when https://github.com/sorbet/sorbet/issues/3532 is fixed.
# rubocop:disable Style/MutableConstant
RunnerSpec = T.type_alias { T.any(LinuxRunnerSpec, MacOSRunnerSpec) } RunnerSpec = T.type_alias { T.any(LinuxRunnerSpec, MacOSRunnerSpec) }
private_constant :RunnerSpec private_constant :RunnerSpec
@ -36,8 +34,6 @@ class GitHubRunnerMatrix
RunnerSpecHash = T.type_alias { T.any(LinuxRunnerSpecHash, MacOSRunnerSpecHash) } RunnerSpecHash = T.type_alias { T.any(LinuxRunnerSpecHash, MacOSRunnerSpecHash) }
private_constant :RunnerSpecHash private_constant :RunnerSpecHash
# rubocop:enable Style/MutableConstant
sig { returns(T::Array[GitHubRunner]) } sig { returns(T::Array[GitHubRunner]) }
attr_reader :runners attr_reader :runners

View File

@ -5,6 +5,7 @@ require_relative "../extend/array"
require_relative "../extend/blank" require_relative "../extend/blank"
require_relative "blank" require_relative "blank"
require_relative "compact_blank" require_relative "compact_blank"
require_relative "extend/mutable_constant_exclude_unfreezable"
require_relative "io_read" require_relative "io_read"
require_relative "move_to_extend_os" require_relative "move_to_extend_os"
require_relative "negate_include" require_relative "negate_include"

View File

@ -0,0 +1,45 @@
# typed: strict
# frozen_string_literal: true
require "rubocop/cop/style/mutable_constant"
module RuboCop
module Cop
module Sorbet
# TODO: delete this file when https://github.com/Shopify/rubocop-sorbet/pull/256 is available
module MutableConstantExcludeUnfreezable
class << self
sig { params(base: RuboCop::AST::NodePattern::Macros).void }
def prepended(base)
base.def_node_matcher(:t_let, <<~PATTERN)
(send (const nil? :T) :let $_constant _type)
PATTERN
base.def_node_matcher(:t_type_alias?, <<~PATTERN)
(block (send (const {nil? cbase} :T) :type_alias ...) ...)
PATTERN
base.def_node_matcher(:type_member?, <<~PATTERN)
(block (send nil? :type_member ...) ...)
PATTERN
end
end
sig { params(value: RuboCop::AST::Node).void }
def on_assignment(value)
T.unsafe(self).t_let(value) do |constant|
value = T.let(constant, RuboCop::AST::Node)
end
return if T.unsafe(self).t_type_alias?(value)
return if T.unsafe(self).type_member?(value)
super
end
end
end
end
end
RuboCop::Cop::Style::MutableConstant.prepend(
RuboCop::Cop::Sorbet::MutableConstantExcludeUnfreezable,
)

View File

@ -13,12 +13,8 @@ module Tapioca
end.flatten.freeze, T::Array[String] end.flatten.freeze, T::Array[String]
) )
# FIXME: Enable cop again when https://github.com/sorbet/sorbet/issues/3532 is fixed.
# rubocop:disable Style/MutableConstant
Parsable = T.type_alias { T.any(T.class_of(Homebrew::CLI::Args), T.class_of(Homebrew::AbstractCommand)) } Parsable = T.type_alias { T.any(T.class_of(Homebrew::CLI::Args), T.class_of(Homebrew::AbstractCommand)) }
ConstantType = type_member { { fixed: Parsable } } ConstantType = type_member { { fixed: Parsable } }
# rubocop:enable Style/MutableConstant
sig { override.returns(T::Enumerable[Parsable]) } sig { override.returns(T::Enumerable[Parsable]) }
def self.gather_constants def self.gather_constants
# require all the commands to ensure the command subclasses are defined # require all the commands to ensure the command subclasses are defined

View File

@ -7,10 +7,7 @@ require "env_config"
module Tapioca module Tapioca
module Compilers module Compilers
class EnvConfig < Tapioca::Dsl::Compiler class EnvConfig < Tapioca::Dsl::Compiler
# FIXME: Enable cop again when https://github.com/sorbet/sorbet/issues/3532 is fixed.
# rubocop:disable Style/MutableConstant
ConstantType = type_member { { fixed: Module } } ConstantType = type_member { { fixed: Module } }
# rubocop:enable Style/MutableConstant
sig { override.returns(T::Enumerable[Module]) } sig { override.returns(T::Enumerable[Module]) }
def self.gather_constants = [Homebrew::EnvConfig] def self.gather_constants = [Homebrew::EnvConfig]

View File

@ -8,13 +8,9 @@ require_relative "../../../rubocops"
module Tapioca module Tapioca
module Compilers module Compilers
class RuboCop < Tapioca::Dsl::Compiler class RuboCop < Tapioca::Dsl::Compiler
# FIXME: Enable cop again when https://github.com/sorbet/sorbet/issues/3532 is fixed.
# rubocop:disable Style/MutableConstant
# This should be a module whose singleton class contains RuboCop::AST::NodePattern::Macros, # This should be a module whose singleton class contains RuboCop::AST::NodePattern::Macros,
# but I don't know how to express that in Sorbet. # but I don't know how to express that in Sorbet.
ConstantType = type_member { { fixed: Module } } ConstantType = type_member { { fixed: Module } }
# rubocop:enable Style/MutableConstant
sig { override.returns(T::Enumerable[Module]) } sig { override.returns(T::Enumerable[Module]) }
def self.gather_constants def self.gather_constants
all_modules.select do |klass| all_modules.select do |klass|

View File

@ -7,10 +7,7 @@ require "utils/tty"
module Tapioca module Tapioca
module Compilers module Compilers
class Tty < Tapioca::Dsl::Compiler class Tty < Tapioca::Dsl::Compiler
# FIXME: Enable cop again when https://github.com/sorbet/sorbet/issues/3532 is fixed.
# rubocop:disable Style/MutableConstant
ConstantType = type_member { { fixed: Module } } ConstantType = type_member { { fixed: Module } }
# rubocop:enable Style/MutableConstant
sig { override.returns(T::Enumerable[Module]) } sig { override.returns(T::Enumerable[Module]) }
def self.gather_constants = [::Tty] def self.gather_constants = [::Tty]

View File

@ -11,10 +11,7 @@ module UnpackStrategy
requires_ancestor { Kernel } requires_ancestor { Kernel }
# FIXME: Enable cop again when https://github.com/sorbet/sorbet/issues/3532 is fixed.
# rubocop:disable Style/MutableConstant
UnpackStrategyType = T.type_alias { T.all(T::Class[UnpackStrategy], UnpackStrategy::ClassMethods) } UnpackStrategyType = T.type_alias { T.all(T::Class[UnpackStrategy], UnpackStrategy::ClassMethods) }
# rubocop:enable Style/MutableConstant
module ClassMethods module ClassMethods
extend T::Helpers extend T::Helpers