class RuboCop::Cop::Yast::Builtins

This cop checks for using obsoleted Yast Builtins calls

Constants

BUILTINS_NODES
MSG

Attributes

default_handler[R]
handlers[R]

Public Class Methods

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

  @handlers = builtin_mapping
  @default_handler = RuboCop::Yast::Builtins::Builtin.new
end

Public Instance Methods

autocorrect(node) click to toggle source
# File lib/rubocop/cop/yast/builtins.rb, line 45
def autocorrect(node)
  _builtins, method_name, *_args = *node

  @corrections << builtin_handler(method_name).correction(node)
end
on_send(node) click to toggle source
# File lib/rubocop/cop/yast/builtins.rb, line 35
def on_send(node)
  receiver, method_name, *_args = *node

  # not an Yast builtin call or not an offense
  return if !BUILTINS_NODES.include?(receiver) ||
      !builtin_handler(method_name).offense?(node)

  add_offense(node, :selector, format(MSG, method_name))
end

Private Instance Methods

builtin_handler(method) click to toggle source

rubocop:enable Metrics/MethodLength

# File lib/rubocop/cop/yast/builtins.rb, line 72
def builtin_handler(method)
  handlers[method] || default_handler
end
builtin_mapping() click to toggle source

rubocop:disable Metrics/MethodLength

# File lib/rubocop/cop/yast/builtins.rb, line 54
def builtin_mapping
  # use the same instance for all logging functions
  logging = RuboCop::Yast::Builtins::Y2log.new

  {
    y2debug: logging,
    y2milestone: logging,
    y2warning: logging,
    y2error: logging,
    y2security: logging,
    y2internal: logging,

    getenv: RuboCop::Yast::Builtins::Getenv.new,
    time: RuboCop::Yast::Builtins::Time.new
  }
end