mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
39 lines
651 B
Crystal
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
|