Class: Gitlab::Styles::Rubocop::Cop::Style::OpenStructUse

Inherits:
RuboCop::Cop::Cop
  • Object
show all
Defined in:
lib/gitlab/styles/rubocop/cop/style/open_struct_use.rb

Overview

This cop flags uses of OpenStruct, as it is now officially discouraged to be used for performance, version compatibility, and potential security issues.

See also:

Constant Summary collapse

MSG =
'Avoid using `OpenStruct`. It is officially discouraged. ' \
'Replace it with `Struct`, `Hash`, or RSpec doubles. ' \
'See https://docs.ruby-lang.org/en/3.0.0/OpenStruct.html#class-OpenStruct-label-Caveats'

Instance Method Summary collapse

Instance Method Details

#on_const(node) ⇒ Object



24
25
26
27
28
29
# File 'lib/gitlab/styles/rubocop/cop/style/open_struct_use.rb', line 24

def on_const(node)
  return unless uses_open_struct?(node)
  return if custom_class_or_module_definition?(node)

  add_offense(node)
end