Class: RuboCop::Cop::Performance::FixedSize
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
Base
|
|
Instance Chain:
self,
Base
|
|
Inherits: |
Base
|
Defined in: | lib/rubocop/cop/performance/fixed_size.rb |
Overview
Do not compute the size of statically sized objects.
Constant Summary
-
MSG =
# File 'lib/rubocop/cop/performance/fixed_size.rb', line 49'Do not compute the size of statically sized objects.'
-
RESTRICT_ON_SEND =
# File 'lib/rubocop/cop/performance/fixed_size.rb', line 50%i[count length size].freeze
Instance Method Summary
-
#on_csend(node)
Alias for #on_send.
- #on_send(node) (also: #on_csend)
- #allowed_argument?(arg) ⇒ Boolean private
- #allowed_parent?(node) ⇒ Boolean private
- #allowed_variable?(var) ⇒ Boolean private
- #contains_double_splat?(node) ⇒ Boolean private
- #contains_splat?(node) ⇒ Boolean private
- #non_string_argument?(node) ⇒ Boolean private
Instance Method Details
#allowed_argument?(arg) ⇒ Boolean
(private)
# File 'lib/rubocop/cop/performance/fixed_size.rb', line 73
def allowed_argument?(arg) arg && non_string_argument?(arg.first) end
#allowed_parent?(node) ⇒ Boolean
(private)
# File 'lib/rubocop/cop/performance/fixed_size.rb', line 77
def allowed_parent?(node) node && (node.casgn_type? || node.block_type?) end
#allowed_variable?(var) ⇒ Boolean
(private)
# File 'lib/rubocop/cop/performance/fixed_size.rb', line 69
def allowed_variable?(var) contains_splat?(var) || contains_double_splat?(var) end
#contains_double_splat?(node) ⇒ Boolean
(private)
# File 'lib/rubocop/cop/performance/fixed_size.rb', line 87
def contains_double_splat?(node) return false unless node.hash_type? node.each_child_node(:kwsplat).any? end
#contains_splat?(node) ⇒ Boolean
(private)
# File 'lib/rubocop/cop/performance/fixed_size.rb', line 81
def contains_splat?(node) return false unless node.array_type? node.each_child_node(:splat).any? end
#non_string_argument?(node) ⇒ Boolean
(private)
# File 'lib/rubocop/cop/performance/fixed_size.rb', line 93
def non_string_argument?(node) node && !node.str_type? end
#on_csend(node)
Alias for #on_send.
# File 'lib/rubocop/cop/performance/fixed_size.rb', line 65
alias on_csend on_send
#on_send(node) Also known as: #on_csend
[ GitHub ]# File 'lib/rubocop/cop/performance/fixed_size.rb', line 56
def on_send(node) return if node.ancestors.any? { |ancestor| allowed_parent?(ancestor) } counter(node) do |var, arg| return if allowed_variable?(var) || allowed_argument?(arg) add_offense(node) end end