Class: RuboCop::Cop::Sidekiq::KeywordArguments
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Sidekiq::KeywordArguments
- Includes:
- Helpers
- Defined in:
- lib/rubocop/cop/sidekiq/keyword_arguments.rb
Overview
This cop checks for Sidekiq worker ‘perform` methods that use keyword args. Keyword args cannot be properly serialized to Redis and are thus not recommended. Use regular arguments instead.
Constant Summary collapse
- MSG =
"Keyword arguments are not allowed in a sidekiq worker's perform method."
- KWARG_TYPES =
%i[kwarg kwoptarg kwrestarg].freeze
Constants included from Helpers
Instance Method Summary collapse
Methods included from Helpers
#approve_node, #expand_arguments, #in_sidekiq_worker?, included, #node_approved?, #sidekiq_arguments, #within?
Instance Method Details
#on_def(node) ⇒ Object
39 40 41 42 43 44 45 46 47 48 |
# File 'lib/rubocop/cop/sidekiq/keyword_arguments.rb', line 39 def on_def(node) return unless perform_with_kwargs?(node) return unless in_sidekiq_worker?(node) node.arguments.each do |arg| next unless KWARG_TYPES.include?(arg.type) add_offense(arg) end end |