From 12aa48c98f42b2ea304a755f11bec806ef173eb9 Mon Sep 17 00:00:00 2001 From: Vitalii Elenhaupt Date: Sat, 22 Sep 2018 21:58:38 +0300 Subject: [PATCH] Fix Style/RedundantBegin: begin-end in a proc literal closes #80 --- spec/ameba/rule/style/redundant_begin_spec.cr | 13 +++++++++++++ src/ameba/rule/style/redundant_begin.cr | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/spec/ameba/rule/style/redundant_begin_spec.cr b/spec/ameba/rule/style/redundant_begin_spec.cr index 5e0fd465..d50c324d 100644 --- a/spec/ameba/rule/style/redundant_begin_spec.cr +++ b/spec/ameba/rule/style/redundant_begin_spec.cr @@ -192,6 +192,19 @@ module Ameba::Rule::Style subject.catch(s).should_not be_valid end + it "doesn't report if begin-end block in a proc literal" do + s = Source.new %q( + foo = ->{ + begin + raise "Foo!" + rescue ex + pp ex + end + } + ) + subject.catch(s).should be_valid + end + it "reports rule, pos and message" do s = Source.new %q( def method diff --git a/src/ameba/rule/style/redundant_begin.cr b/src/ameba/rule/style/redundant_begin.cr index c4a60940..df5bd621 100644 --- a/src/ameba/rule/style/redundant_begin.cr +++ b/src/ameba/rule/style/redundant_begin.cr @@ -113,7 +113,7 @@ module Ameba::Rule::Style token = lexer.next_token case token.type - when :EOF + when :EOF, :"->" break when :IDENT return token.value == :begin if in_body?