Class: Ducalis::EvlisOverusing

Inherits:
RuboCop::Cop::Cop
  • Object
show all
Includes:
TypeResolving
Defined in:
lib/ducalis/cops/evlis_overusing.rb

Constant Summary collapse

OFFENSE =
<<-MESSAGE.gsub(/^ +\|\s/, '').strip
  | Seems like you are overusing safe navigation operator. Try to use right method (ex: `dig` for hashes), null object pattern or ensure types via explicit conversion (`to_a`, `to_s` and so on).
MESSAGE
DETAILS =
<<-MESSAGE.gsub(/^ +\|\s/, '').strip
  | Related article: https://karolgalanciak.com/blog/2017/09/24/do-or-do-not-there-is-no-try-object-number-try-considered-harmful/
MESSAGE

Constants included from TypeResolving

TypeResolving::CONTROLLER_SUFFIXES, TypeResolving::MODELS_CLASS_NAMES, TypeResolving::SERVICES_PATH, TypeResolving::WORKERS_SUFFIXES

Instance Method Summary collapse

Methods included from TypeResolving

#on_class, #on_module

Instance Method Details

#on_csend(node) ⇒ Object



23
24
25
26
27
# File 'lib/ducalis/cops/evlis_overusing.rb', line 23

def on_csend(node)
  return unless node.child_nodes.any?(&:csend_type?)

  add_offense(node, :expression, OFFENSE)
end

#on_send(node) ⇒ Object



17
18
19
20
21
# File 'lib/ducalis/cops/evlis_overusing.rb', line 17

def on_send(node)
  return unless nested_try?(node)

  add_offense(node, :expression, OFFENSE)
end