struct Ameba::Rules::LiteralInCondition

Overview

A rule that disallows useless conditional statements that contain a literal in place of a variable or predicate function.

This is because a conditional construct with a literal predicate will always result in the same behaviour at run time, meaning it can be replaced with either the body of the construct, or deleted entirely.

This is considered invalid:

if "something"
  :ok
end

Included Modules

Defined in:

ameba/rules/literal_in_condition.cr

Instance Method Summary

Instance methods inherited from module Ameba::AST::Util

literal?(node) literal?, string_literal?(node) string_literal?

Instance methods inherited from struct Ameba::Rule

catch(source : Source) catch, initialize initialize, name name, test(source : Source, node : Crystal::ASTNode)
test(source : Source)
test

Constructor methods inherited from struct Ameba::Rule

new new

Class methods inherited from struct Ameba::Rule

rules rules

Instance Method Detail

def check_node(source, node) #

[View source]
def test(source, node : Crystal::If) #

[View source]
def test(source, node : Crystal::Unless) #

[View source]
def test(source, node : Crystal::Case) #

[View source]
def test(source) #

[View source]