This commit is contained in:
Vitalii Elenhaupt 2018-05-08 22:18:15 +03:00
parent c2aa526e21
commit eab5499f8e
No known key found for this signature in database
GPG Key ID: 7558EF3A4056C706
5 changed files with 46 additions and 12 deletions

View File

@ -121,18 +121,16 @@ module Ameba::AST
end
context "Crystal::Case" do
# FIXME:
# https://github.com/crystal-lang/crystal/pull/6032
# it "constructs a branch in cond" do
# branch = branch_of_assign_in_def %(
# def method(a)
# case (a = 2)
# when true then nil
# end
# end
# )
# branch.to_s.should eq "(a = 2)"
# end
it "constructs a branch in cond" do
branch = branch_of_assign_in_def %(
def method(a)
case (a = 2)
when true then nil
end
end
)
branch.to_s.should eq "(a = 2)"
end
it "constructs a branch in when" do
branch = branch_of_assign_in_def %(

View File

@ -137,6 +137,17 @@ module Ameba::Rule
subject.catch(s).should be_valid
end
it "doesn't report if arg if referenced in case" do
s = Source.new %(
def foo(a)
case a
when /foo/
end
end
)
subject.catch(s).should be_valid
end
context "super" do
it "reports if variable is not referenced implicitly by super" do
s = Source.new %(

View File

@ -582,6 +582,18 @@ module Ameba::Rule
s.errors.first.location.to_s.should eq ":5:17"
s.errors.last.location.to_s.should eq ":7:17"
end
it "doesn't report if assignment is referenced in cond" do
s = Source.new %(
def method
a = 2
case a
when /foo/
end
end
)
subject.catch(s).should be_valid
end
end
context "binary operator" do

View File

@ -2,6 +2,7 @@ require "./ameba/*"
require "./ameba/ast/**"
require "./ameba/rule/*"
require "./ameba/formatter/*"
require "./ameba/support/*"
# Ameba's entry module.
#

12
src/ameba/support/ast.cr Normal file
View File

@ -0,0 +1,12 @@
{% if Crystal::VERSION == "0.24.2" %}
# workaround for https://github.com/crystal-lang/crystal/pull/6032
module Crystal
class Case < ASTNode
def accept_children(visitor)
@cond.try &.accept visitor
@whens.each &.accept visitor
@else.try &.accept visitor
end
end
end
{% end %}