Class: OpsProcessor

Inherits:
Parser::AST::Processor
  • Object
show all
Includes:
RuboCop::Cop::Util, RuboCop::Yast::TrackVariableScope
Defined in:
lib/rubocop/cop/yast/ops.rb

Overview

Niceness processor really

Constant Summary collapse

MSG =
"Obsolete Ops.%s call found"

Constants included from Niceness

Niceness::NICE_GLOBAL_METHODS, Niceness::NICE_LITERAL_NODE_TYPES, Niceness::NICE_OPERATORS

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from RuboCop::Yast::TrackVariableScope

#on_and_asgn, #on_block, #on_case, #on_class, #on_def, #on_defs, #on_ensure, #on_if, #on_lvasgn, #on_module, #on_or_asgn, #on_resbody, #on_rescue, #on_sclass, #on_while, #scope, #scopes, #with_new_scope_rescuing_oops

Methods included from Niceness

#call?, #nice, #nice_begin, #nice_literal, #nice_send, #nice_sformat, #nice_variable

Constructor Details

#initialize(cop) ⇒ OpsProcessor

Returns a new instance of OpsProcessor.



80
81
82
# File 'lib/rubocop/cop/yast/ops.rb', line 80

def initialize(cop)
  @cop = cop
end

Instance Attribute Details

#copObject (readonly)

Returns the value of attribute cop.



78
79
80
# File 'lib/rubocop/cop/yast/ops.rb', line 78

def cop
  @cop
end

Instance Method Details

#autocorrectable?(node) ⇒ Boolean

assumes node is an Ops.add

Returns:

  • (Boolean)


101
102
103
104
105
106
107
# File 'lib/rubocop/cop/yast/ops.rb', line 101

def autocorrectable?(node)
  RuboCop::Yast.logger.debug "AUTOCORRECTABLE?(#{node.inspect})"
  RuboCop::Yast.logger.debug "CUR SCOPE #{scope.inspect}"

  _ops, _method, a, b = *node
  nice(a) && nice(b)
end

#investigate(processed_source) ⇒ Object



84
85
86
# File 'lib/rubocop/cop/yast/ops.rb', line 84

def investigate(processed_source)
  process(processed_source.ast)
end

#on_send(node) ⇒ Object



90
91
92
93
94
95
96
97
98
# File 'lib/rubocop/cop/yast/ops.rb', line 90

def on_send(node)
  super

  receiver, message = *node
  return unless const_name(receiver) == "Ops"
  return unless RuboCop::Cop::Yast::Ops::REPLACEMENT.key?(message)
  return unless cop.strict_mode || autocorrectable?(node)
  cop.add_offense(node, :selector, format(MSG, message))
end