Class: RuboCop::Cop::Yast::Builtins

Inherits:
RuboCop::Cop show all
Includes:
AST::Sexp
Defined in:
lib/rubocop/cop/yast/builtins.rb

Overview

This cop checks for using obsoleted Yast Builtins calls

Constant Summary collapse

MSG =
"Builtin call `%s` is obsolete, use native Ruby function instead."
BUILTINS_NODES =
[
  # Builtins.*
  s(:const, nil, :Builtins),
  # Yast::Builtins.*
  s(:const, s(:const, nil, :Yast), :Builtins),
  # ::Yast::Builtins.*
  s(:const, s(:const, s(:cbase), :Yast), :Builtins)
]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = nil, options = nil) ⇒ Builtins

Returns a new instance of Builtins.



28
29
30
31
32
33
# 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

Instance Attribute Details

#default_handlerObject (readonly)

Returns the value of attribute default_handler.



15
16
17
# File 'lib/rubocop/cop/yast/builtins.rb', line 15

def default_handler
  @default_handler
end

#handlersObject (readonly)

Returns the value of attribute handlers.



15
16
17
# File 'lib/rubocop/cop/yast/builtins.rb', line 15

def handlers
  @handlers
end

Instance Method Details

#autocorrect(node) ⇒ Object



45
46
47
48
49
# 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) ⇒ Object



35
36
37
38
39
40
41
42
43
# 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