lib/rubocop/cop/style/lambda.rb in rubocop-0.89.0 vs lib/rubocop/cop/style/lambda.rb in rubocop-0.89.1

- old
+ new

@@ -44,12 +44,13 @@ # # good # f = ->(x) { x } # f = ->(x) do # x # end - class Lambda < Cop + class Lambda < Base include ConfigurableEnforcedStyle + extend AutoCorrector LITERAL_MESSAGE = 'Use the `-> { ... }` lambda literal syntax for ' \ '%<modifier>s lambdas.' METHOD_MESSAGE = 'Use the `lambda` method for %<modifier>s ' \ 'lambdas.' @@ -67,24 +68,18 @@ selector = node.send_node.source return unless offending_selector?(node, selector) - add_offense(node, - location: node.send_node.source_range, - message: message(node, selector)) - end - alias on_numblock on_block - - def autocorrect(node) - if node.send_node.source == 'lambda' - lambda do |corrector| + add_offense(node.send_node.source_range, message: message(node, selector)) do |corrector| + if node.send_node.source == 'lambda' autocorrect_method_to_literal(corrector, node) + else + LambdaLiteralToMethodCorrector.new(node).call(corrector) end - else - LambdaLiteralToMethodCorrector.new(node) end end + alias on_numblock on_block private def offending_selector?(node, selector) lines = node.multiline? ? :multiline : :single_line