lib/rubocop/cop/style/for.rb in rubocop-0.52.1 vs lib/rubocop/cop/style/for.rb in rubocop-0.53.0
- old
+ new
@@ -5,11 +5,44 @@
module Style
# This cop looks for uses of the *for* keyword, or *each* method. The
# preferred alternative is set in the EnforcedStyle configuration
# parameter. An *each* call with a block on a single line is always
# allowed, however.
+ #
+ # @example EnforcedStyle: each (default)
+ # # bad
+ # def foo
+ # for n in [1, 2, 3] do
+ # puts n
+ # end
+ # end
+ #
+ # # good
+ # def foo
+ # [1, 2, 3].each do |n|
+ # puts n
+ # end
+ # end
+ #
+ # @example EnforcedStyle: for
+ # # bad
+ # def foo
+ # [1, 2, 3].each do |n|
+ # puts n
+ # end
+ # end
+ #
+ # # good
+ # def foo
+ # for n in [1, 2, 3] do
+ # puts n
+ # end
+ # end
+ #
class For < Cop
include ConfigurableEnforcedStyle
+ include RangeHelp
+
EACH_LENGTH = 'each'.length
def on_for(node)
if style == :each
msg = 'Prefer `each` over `for`.'