class RuboCop::Cop::Yast::Ops

This cop checks for Ops.* calls aka Zombies. Some of these can be autocorrected, mostly when we can prove that their arguments cannot be nil. In Strict Mode, it reports all zombies. In Permissive Mode, it report only zombies that can be autocorrected.

Constants

REPLACEMENT

Ops replacement mapping

Attributes

strict_mode[R]

Public Class Methods

new(config = nil, options = nil) click to toggle source
Calls superclass method
# File lib/rubocop/cop/yast/ops.rb, line 33
def initialize(config = nil, options = nil)
  super(config, options)

  @strict_mode = cop_config && cop_config["StrictMode"]
  @replaced_nodes = []
  @processor = OpsProcessor.new(self)
end

Public Instance Methods

investigate(processed_source) click to toggle source
# File lib/rubocop/cop/yast/ops.rb, line 41
def investigate(processed_source)
  @processor.investigate(processed_source)
end

Private Instance Methods

autocorrect(node) click to toggle source
# File lib/rubocop/cop/yast/ops.rb, line 49
def autocorrect(node)
  return unless @processor.autocorrectable?(node)

  _ops, message, arg1, arg2 = *node

  new_op = REPLACEMENT[message]
  return unless new_op

  @corrections << lambda do |corrector|
    source_range = node.loc.expression
    next if contains_comment?(source_range.source)
    new_node = Parser::AST::Node.new(:send, [arg1, new_op, arg2])
    corrector.replace(source_range, Unparser.unparse(new_node))
  end
end
contains_comment?(string) click to toggle source
# File lib/rubocop/cop/yast/ops.rb, line 65
def contains_comment?(string)
  /^[^'"\n]*#/.match(string)
end