mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
Mark begin; end
as empty expression
This commit is contained in:
parent
fb398b5056
commit
b3a9ff2fa0
3 changed files with 32 additions and 0 deletions
|
@ -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 %(
|
||||
|
|
|
@ -13,6 +13,7 @@ module Ameba::AST
|
|||
Def,
|
||||
EnumDef,
|
||||
ExceptionHandler,
|
||||
Expressions,
|
||||
If,
|
||||
InstanceVar,
|
||||
LibDef,
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue