Created
February 16, 2021 23:09
-
-
Save zorbash/7c4e9e605a81f3c4e503f3c7b5006835 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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