Class: RuboCop::Cop::Betterment::DynamicParams

Inherits:
RuboCop::Cop
  • Object
show all
Defined in:
lib/rubocop/cop/betterment/dynamic_params.rb

Constant Summary collapse

MSG_DYNAMIC_PARAMS =
<<~MSG
  Parameter names accessed dynamically, cannot determine safeness. Please inline the keys explicitly when calling `permit` or when accessing `params` like a hash.

  See here for more information on this error:
  https://github.com/Betterment/betterlint/blob/main/README.md#bettermentdynamicparams
MSG

Instance Method Summary collapse

Instance Method Details

#on_send(node) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/rubocop/cop/betterment/dynamic_params.rb', line 18

def on_send(node)
  _, _, *arg_nodes = *node # rubocop:disable InternalAffairs/NodeDestructuring
  return unless permit_or_hash?(node) && Utils::Parser.get_root_token(node) == :params

  dynamic_param = find_dynamic_param(arg_nodes)
  add_offense(dynamic_param, message: MSG_DYNAMIC_PARAMS) if dynamic_param
end