Early return in CountVisitor if macro node

Co-authored-by: Sijawusz Pur Rahnama <sija@sija.pl>
This commit is contained in:
Caspian Baska 2021-06-06 04:12:56 +10:00 committed by GitHub
parent 0ea6238dc6
commit c49c69ed9f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -32,10 +32,12 @@ module Ameba::AST
# :nodoc:
def visit(node : Crystal::Case)
return true if macro_condition
# Count the complexity of an exhaustive `Case` as 1
# Otherwise count the number of `When`s
case_complexity = node.exhaustive? ? 1 : node.whens.size
@complexity += case_complexity unless macro_condition
@complexity += node.exhaustive? ? 1 : node.whens.size
true
end