Class: RuboCop::Cop::Sorbet::ConstantsFromStrings
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Sorbet::ConstantsFromStrings
- Defined in:
- lib/rubocop/cop/sorbet/constants_from_strings.rb
Overview
Disallows the calls that are used to get constants fom Strings such as constantize
, const_get
, and constants
.
The goal of this cop is to make the code easier to statically analyze, more IDE-friendly, and more predictable. It leads to code that clearly expresses which values the constant can have.
Constant Summary collapse
- MSG =
"Don't use `%<method_name>s`, it makes the code harder to understand, less editor-friendly, " \ "and impossible to analyze. Replace `%<method_name>s` with a case/when or a hash."
- RESTRICT_ON_SEND =
[ :constantize, :constants, :const_get, ].freeze
Instance Method Summary collapse
- #on_send(node) ⇒ Object (also: #on_csend)
Instance Method Details
#on_send(node) ⇒ Object Also known as: on_csend
46 47 48 |
# File 'lib/rubocop/cop/sorbet/constants_from_strings.rb', line 46 def on_send(node) add_offense(node.selector, message: format(MSG, method_name: node.method_name)) end |