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."
ALLOWED_FUNCTIONS =

white list of allowed Builtins calls

[
  # locale dependent sorting in not available in Ruby stdlib
  :lsort,
  # gettext helpers
  :dgettext,
  :dngettext,
  :dpgettext
]
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 Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/rubocop/cop/yast/builtins.rb', line 31

def on_send(node)
  receiver, method_name, *_args = *node

  return if !BUILTINS_NODES.include?(receiver) ||
      ALLOWED_FUNCTIONS.include?(method_name)

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