Mark begin; end as empty expression

This commit is contained in:
Vitalii Elenhaupt 2017-11-17 18:32:40 +02:00
parent fb398b5056
commit b3a9ff2fa0
No known key found for this signature in database
GPG key ID: 7558EF3A4056C706
3 changed files with 32 additions and 0 deletions

View file

@ -24,6 +24,12 @@ module Ameba
a = nil
a = ""
a = 0
nil
:any.nil?
begin "" end
[nil] << nil
)
subject.catch(s).should be_valid
end
@ -69,6 +75,25 @@ module Ameba
()
end
)
it_detects_empty_expression %(
def method
begin
end
end
)
it_detects_empty_expression %(
begin; end
)
it_detects_empty_expression %(
begin
nil
end
)
it_detects_empty_expression %(
begin
()
end
)
it "reports rule, location and message" do
s = Source.new %(

View file

@ -13,6 +13,7 @@ module Ameba::AST
Def,
EnumDef,
ExceptionHandler,
Expressions,
If,
InstanceVar,
LibDef,

View file

@ -42,5 +42,11 @@ module Ameba::Rule
source.error self, node.location, "Avoid empty expression '#{exp}'"
end
def test(source, node : Crystal::Expressions)
if node.expressions.size == 1 && node.expressions.first.nop?
source.error self, node.location, "Avoid empty expressions"
end
end
end
end