struct Ameba::Rule::Lint::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

YAML configuration example:

Lint/LiteralInCondition:
  Enabled: true

Included Modules

Defined in:

Constant Summary

MSG = "Literal value found in conditional"

Constructors

Instance Method Summary

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

abort?(node) abort?, exit?(node) exit?, flow_command?(node, in_loop) flow_command?, flow_expression?(node, in_loop = false) flow_expression?, literal?(node) literal?, loop?(node) loop?, node_source(node, code_lines) node_source, raise?(node) raise?

Instance methods inherited from struct Ameba::Rule::Base

==(other) ==, catch(source : Source) catch, excluded?(source) excluded?, group group, hash hash, name name, special? special?, test(source : Source, node : Crystal::ASTNode, *opts)
test(source : Source)
test

Constructor methods inherited from struct Ameba::Rule::Base

new new

Class methods inherited from struct Ameba::Rule::Base

parsed_doc parsed_doc

Constructor Detail

def self.new(ctx : YAML::ParseContext, node : YAML::Nodes::Node) #

def self.new(config = nil) #

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

YAML configuration example:

Lint/LiteralInCondition:
  Enabled: true

Instance Method Detail

def check_node(source, node) #

def description : String #

def description=(description : String) #

def enabled : Bool #

def enabled=(enabled) #

def excluded : Array(String)? #

def excluded=(excluded : Array(String)?) #

def severity : Ameba::Severity #

def severity=(severity) #

def test(source, node : Crystal::If) #

def test(source, node : Crystal::Unless) #

def test(source, node : Crystal::Case) #