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

Exclude sorbet assignments from Style/MutableConstant cop #18091

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions Library/Homebrew/PATH.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,10 @@ class PATH

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)) }
private_constant :Element
Elements = T.type_alias { T.any(Element, T::Array[Element]) }
private_constant :Elements
# rubocop:enable Style/MutableConstant

sig { params(paths: Elements).void }
def initialize(*paths)
Expand Down
3 changes: 0 additions & 3 deletions Library/Homebrew/cask/staged.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,7 @@
module Cask
# Helper functions for staged casks.
module Staged
# 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)]) }
# rubocop:enable Style/MutableConstant

sig { params(paths: Paths, permissions_str: String).void }
def set_permissions(paths, permissions_str)
Expand Down
3 changes: 0 additions & 3 deletions Library/Homebrew/cli/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,8 @@
module Homebrew
module CLI
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]) }
OptionsType = T.type_alias { T::Array[[String, T.nilable(String), T.nilable(String), String, T::Boolean]] }
# rubocop:enable Style/MutableConstant
HIDDEN_DESC_PLACEHOLDER = "@@HIDDEN@@"
SYMBOL_TO_USAGE_MAPPING = T.let({
text_or_regex: "<text>|`/`<regex>`/`",
Expand Down
3 changes: 0 additions & 3 deletions Library/Homebrew/github_runner_matrix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
require "github_runner"

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) }
private_constant :RunnerSpec

Expand All @@ -27,7 +25,6 @@ class GitHubRunnerMatrix

RunnerSpecHash = T.type_alias { T.any(LinuxRunnerSpecHash, MacOSRunnerSpecHash) }
private_constant :RunnerSpecHash
# rubocop:enable Style/MutableConstant

sig { returns(T::Array[GitHubRunner]) }
attr_reader :runners
Expand Down
3 changes: 2 additions & 1 deletion Library/Homebrew/rubocops/all.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# typed: strict
# typed: strong
# frozen_string_literal: true

require_relative "../extend/array"
require_relative "../extend/blank"
require_relative "extend/mutable_constant"
require_relative "blank"
require_relative "compact_blank"
require_relative "io_read"
Expand Down
37 changes: 37 additions & 0 deletions Library/Homebrew/rubocops/extend/mutable_constant.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# typed: strict
# frozen_string_literal: true

module RuboCop
module Cop
module Homebrew
# This injects exclusion patterns into the `Style/MutableConstant` cop to skip
# constants that we are unable to freeze.
# FIXME: Remove when https://github.com/sorbet/sorbet/issues/3532 is fixed.
module SkipSorbetConstantAssignments
extend NodePattern::Macros

def_node_matcher :t_type_alias?, "(block (send (const {nil? cbase} :T) :type_alias ...) ...)"
def_node_matcher :type_member?, "(block (send nil? :type_member ...) ...)"

sig { params(node: AST::CasgnNode).void }
def on_casgn(node)
_scope, _const_name, value = *node

Check warning on line 18 in Library/Homebrew/rubocops/extend/mutable_constant.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/rubocops/extend/mutable_constant.rb#L18

Added line #L18 was not covered by tests
return if t_type_alias?(value)
return if type_member?(value)

super

Check warning on line 22 in Library/Homebrew/rubocops/extend/mutable_constant.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/rubocops/extend/mutable_constant.rb#L22

Added line #L22 was not covered by tests
end
end
end
end
end

module RuboCop
module Cop
module Style
class MutableConstant < Base
prepend Homebrew::SkipSorbetConstantAssignments
end
end
end
end

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

3 changes: 0 additions & 3 deletions Library/Homebrew/sorbet/tapioca/compilers/args.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,8 @@ class Args < Tapioca::Dsl::Compiler
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)) }
ConstantType = type_member { { fixed: Parsable } }
# rubocop:enable Style/MutableConstant

sig { override.returns(T::Enumerable[Parsable]) }
def self.gather_constants
Expand Down
4 changes: 0 additions & 4 deletions Library/Homebrew/sorbet/tapioca/compilers/env_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@
module Tapioca
module Compilers
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 } }
# rubocop:enable Style/MutableConstant

sig { override.returns(T::Enumerable[Module]) }
def self.gather_constants = [Homebrew::EnvConfig]

Expand Down
3 changes: 0 additions & 3 deletions Library/Homebrew/sorbet/tapioca/compilers/rubocop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,9 @@
module Tapioca
module Compilers
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,
# but I don't know how to express that in Sorbet.
ConstantType = type_member { { fixed: Module } }
# rubocop:enable Style/MutableConstant

sig { override.returns(T::Enumerable[Module]) }
def self.gather_constants
Expand Down
3 changes: 0 additions & 3 deletions Library/Homebrew/sorbet/tapioca/compilers/tty.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
module Tapioca
module Compilers
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 } }
# rubocop:enable Style/MutableConstant

sig { override.returns(T::Enumerable[Module]) }
def self.gather_constants = [::Tty]
Expand Down
3 changes: 0 additions & 3 deletions Library/Homebrew/unpack_strategy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,7 @@ module UnpackStrategy
include SystemCommand::Mixin
abstract!

# 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) }
# rubocop:enable Style/MutableConstant

module ClassMethods
extend T::Helpers
Expand Down