mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
Add a workaround for https://github.com/crystal-lang/crystal/pull/6032
This commit is contained in:
parent
c2aa526e21
commit
eab5499f8e
5 changed files with 46 additions and 12 deletions
|
@ -121,18 +121,16 @@ module Ameba::AST
|
||||||
end
|
end
|
||||||
|
|
||||||
context "Crystal::Case" do
|
context "Crystal::Case" do
|
||||||
# FIXME:
|
it "constructs a branch in cond" do
|
||||||
# https://github.com/crystal-lang/crystal/pull/6032
|
branch = branch_of_assign_in_def %(
|
||||||
# it "constructs a branch in cond" do
|
def method(a)
|
||||||
# branch = branch_of_assign_in_def %(
|
case (a = 2)
|
||||||
# def method(a)
|
when true then nil
|
||||||
# case (a = 2)
|
end
|
||||||
# when true then nil
|
end
|
||||||
# end
|
)
|
||||||
# end
|
branch.to_s.should eq "(a = 2)"
|
||||||
# )
|
end
|
||||||
# branch.to_s.should eq "(a = 2)"
|
|
||||||
# end
|
|
||||||
|
|
||||||
it "constructs a branch in when" do
|
it "constructs a branch in when" do
|
||||||
branch = branch_of_assign_in_def %(
|
branch = branch_of_assign_in_def %(
|
||||||
|
|
|
@ -137,6 +137,17 @@ module Ameba::Rule
|
||||||
subject.catch(s).should be_valid
|
subject.catch(s).should be_valid
|
||||||
end
|
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
|
context "super" do
|
||||||
it "reports if variable is not referenced implicitly by super" do
|
it "reports if variable is not referenced implicitly by super" do
|
||||||
s = Source.new %(
|
s = Source.new %(
|
||||||
|
|
|
@ -582,6 +582,18 @@ module Ameba::Rule
|
||||||
s.errors.first.location.to_s.should eq ":5:17"
|
s.errors.first.location.to_s.should eq ":5:17"
|
||||||
s.errors.last.location.to_s.should eq ":7:17"
|
s.errors.last.location.to_s.should eq ":7:17"
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
context "binary operator" do
|
context "binary operator" do
|
||||||
|
|
|
@ -2,6 +2,7 @@ require "./ameba/*"
|
||||||
require "./ameba/ast/**"
|
require "./ameba/ast/**"
|
||||||
require "./ameba/rule/*"
|
require "./ameba/rule/*"
|
||||||
require "./ameba/formatter/*"
|
require "./ameba/formatter/*"
|
||||||
|
require "./ameba/support/*"
|
||||||
|
|
||||||
# Ameba's entry module.
|
# Ameba's entry module.
|
||||||
#
|
#
|
||||||
|
|
12
src/ameba/support/ast.cr
Normal file
12
src/ameba/support/ast.cr
Normal 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 %}
|
Loading…
Reference in a new issue