Module: RuboCop::Cop::Sorbet::MutableConstantExcludeUnfreezable Private

Defined in:
rubocops/extend/mutable_constant_exclude_unfreezable.rb

Overview

This module is part of a private API. This module may only be used in the Homebrew/brew repository. Third parties should avoid using this module if possible, as it may be removed or changed without warning.

TODO:

delete this file when https://github.com/Shopify/rubocop-sorbet/pull/256 is available

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.prepended(base) ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.

Parameters:

  • base (RuboCop::AST::NodePattern::Macros)


13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'rubocops/extend/mutable_constant_exclude_unfreezable.rb', line 13

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

Instance Method Details

#on_assignment(value) ⇒ void

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

This method returns an undefined value.

Parameters:



29
30
31
32
33
34
35
36
37
# File 'rubocops/extend/mutable_constant_exclude_unfreezable.rb', line 29

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