shard-ameba/src/ameba/rule/empty_expression.cr
2017-11-08 00:02:32 +02:00

39 lines
651 B
Crystal

module Ameba::Rule
# A rule that disallows empty expressions.
#
# This is considered invalid:
#
# ```
# foo = ()
#
# if ()
# bar
# end
# ```
#
# And this is valid:
#
# ```
# foo = (some_expression)
#
# if (some_expression)
# bar
# end
# ```
#
struct EmptyExpression < Base
include AST::Util
def test(source)
AST::Visitor.new self, source
end
def test(source, node : Crystal::NilLiteral)
exp = node_source(node, source.lines).try &.join
return if exp.nil? || exp == "nil"
source.error self, node.location, "Avoid empty expression '#{exp}'"
end
end
end