Skip to content

Instantly share code, notes, and snippets.

@zorbash
Created February 16, 2021 23:09
Show Gist options
  • Save zorbash/7c4e9e605a81f3c4e503f3c7b5006835 to your computer and use it in GitHub Desktop.
Save zorbash/7c4e9e605a81f3c4e503f3c7b5006835 to your computer and use it in GitHub Desktop.
module RuboCop
module Cops
module Jobs
class Arguments < RuboCop::Cop::Cop
MAX_JOB_ARGUMENTS = 3
MSG = 'Replace %<args_count>d arguments with a single Dry::Struct'.freeze
def on_args(node)
return unless perform_method?(node.parent)
args_count = node.children.size
return if args_count <= MAX_JOB_ARGUMENTS
add_offense(node.parent, message: MSG % { args_count: args_count })
end
private
def_node_matcher :perform_method?, <<~PATTERN
(def :perform (args ...) ...)
PATTERN
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment