Class: RuboCop::Cop::Sidekiq::SymbolArgument
- Inherits:
-
Base
- Object
- Base
- RuboCop::Cop::Sidekiq::SymbolArgument
- Extended by:
- AutoCorrector
- Includes:
- Helpers
- Defined in:
- lib/rubocop/cop/sidekiq/symbol_argument.rb
Overview
This cop checks for symbols passed as arguments to a Sidekiq worker’s perform method. Symbols cannot be properly serialized for Redis and should be avoided. Use strings instead.
Constant Summary collapse
- MSG =
'Symbols are not native JSON types; use strings instead.'
Constants included from Helpers
Instance Method Summary collapse
Methods included from Helpers
#approve_node, #expand_array_node, #expand_hash_array_node, #expand_hash_node, #expand_node, #expand_nodes, #in_sidekiq_worker?, included, #node_approved?, #sidekiq_arguments, #within?
Instance Method Details
#on_send(node) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/rubocop/cop/sidekiq/symbol_argument.rb', line 74 def on_send(node) sidekiq_arguments(node) .lazy .select { |n| node_contains_symbol?(n) } .each do |selected_node| offense_data(selected_node) do |offense_node, replace_node, replace_value| add_offense(offense_node) do |corrector| corrector.replace(replace_node, replace_value) end end end end |