/
block_parameter_name.rb
49 lines (46 loc) · 1.54 KB
/
block_parameter_name.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# frozen_string_literal: true
module RuboCop
module Cop
module Naming
# This cop checks block parameter names for how descriptive they
# are. It is highly configurable.
#
# The `MinNameLength` config option takes an integer. It represents
# the minimum amount of characters the name must be. Its default is 1.
# The `AllowNamesEndingInNumbers` config option takes a boolean. When
# set to false, this cop will register offenses for names ending with
# numbers. Its default is false. The `AllowedNames` config option
# takes an array of whitelisted names that will never register an
# offense. The `ForbiddenNames` config option takes an array of
# blacklisted names that will always register an offense.
#
# @example
# # bad
# bar do |varOne, varTwo|
# varOne + varTwo
# end
#
# # With `AllowNamesEndingInNumbers` set to false
# foo { |num1, num2| num1 * num2 }
#
# # With `MinParamNameLength` set to number greater than 1
# baz { |a, b, c| do_stuff(a, b, c) }
#
# # good
# bar do |thud, fred|
# thud + fred
# end
#
# foo { |speed, distance| speed * distance }
#
# baz { |age, height, gender| do_stuff(age, height, gender) }
class BlockParameterName < Cop
include UncommunicativeName
def on_block(node)
return unless node.arguments?
check(node, node.arguments)
end
end
end
end
end