Skip to content

Commit

Permalink
Simplify logic for UncommunicativeName. If not having a name is a pos…
Browse files Browse the repository at this point in the history
…sible syntax, it is acceptable
  • Loading branch information
marcandre committed Jul 2, 2020
1 parent 0cad1a2 commit 3aeadd9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
6 changes: 4 additions & 2 deletions lib/rubocop/cop/mixin/uncommunicative_name.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,13 @@ def check(node, args)
args.each do |arg|
# Argument names might be "_" or prefixed with "_" to indicate they
# are unused. Trim away this prefix and only analyse the basename.
full_name = arg.children.first.to_s
name_child = arg.children.first
next if name_child.nil?

full_name = name_child.to_s
next if full_name == '_'

name = full_name.gsub(/\A(_+)/, '')
next if (arg.restarg_type? || arg.kwrestarg_type?) && name.empty?
next if allowed_names.include?(name)

range = arg_range(arg, name.size)
Expand Down
2 changes: 1 addition & 1 deletion lib/rubocop/cop/naming/method_parameter_name.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class MethodParameterName < Cop
def on_def(node)
return unless node.arguments?

check(node, node.arguments.reject(&:forward_args_type?))
check(node, node.arguments)
end
alias on_defs on_def
end
Expand Down

0 comments on commit 3aeadd9

Please sign in to comment.