Class: OpsProcessor
- Inherits:
-
Parser::AST::Processor
- Object
- Parser::AST::Processor
- OpsProcessor
- 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
-
#cop ⇒ Object
readonly
Returns the value of attribute cop.
Instance Method Summary collapse
-
#autocorrectable?(node) ⇒ Boolean
assumes node is an Ops.add.
-
#initialize(cop) ⇒ OpsProcessor
constructor
A new instance of OpsProcessor.
- #investigate(processed_source) ⇒ Object
- #on_send(node) ⇒ Object
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
#cop ⇒ Object (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
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, = *node return unless const_name(receiver) == "Ops" return unless RuboCop::Cop::Yast::Ops::REPLACEMENT.key?() return unless cop.strict_mode || autocorrectable?(node) cop.add_offense(node, :selector, format(MSG, )) end |