class Ameba::Rule::Performance::CompactAfterMap
- Ameba::Rule::Performance::CompactAfterMap
- Ameba::Rule::Performance::Base
- Ameba::Rule::Base
- Reference
- Object
Overview
This rule is used to identify usage of compact
calls that follow map
.
For example, this is considered inefficient:
%w[Alice Bob].map(&.match(/^A./)).compact
And can be written as this:
%w[Alice Bob].compact_map(&.match(/^A./))
YAML configuration example:
Performance/CompactAfterMap:
Enabled: true
Included Modules
- YAML::Serializable
- YAML::Serializable::Strict
Defined in:
ameba/rule/performance/compact_after_map.crConstant Summary
-
COMPACT_NAME =
"compact"
-
MAP_NAME =
"map"
-
MSG =
"Use `compact_map {...}` instead of `map {...}.compact`"
Constructors
-
.new(ctx : YAML::ParseContext, node : YAML::Nodes::Node)
This rule is used to identify usage of
compact
calls that followmap
. -
.new(config = nil)
This rule is used to identify usage of
compact
calls that followmap
.
Instance Method Summary
- #description : String
- #description=(description : String)
- #enabled : Bool
- #enabled=(enabled : Bool)
- #excluded : Array(String) | Nil
- #excluded=(excluded : Array(String) | Nil)
- #severity : Ameba::Severity
- #severity=(severity : Ameba::Severity)
- #test(source, node : Crystal::Call)
- #test(source)
Instance methods inherited from class Ameba::Rule::Performance::Base
catch(source : Source)
catch
Constructor methods inherited from class Ameba::Rule::Performance::Base
new(ctx : YAML::ParseContext, node : YAML::Nodes::Node)new(config = nil) new
Instance methods inherited from class 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
Class methods inherited from class Ameba::Rule::Base
parsed_doc
parsed_doc
Constructor Detail
def self.new(ctx : YAML::ParseContext, node : YAML::Nodes::Node)
#
This rule is used to identify usage of compact
calls that follow map
.
For example, this is considered inefficient:
%w[Alice Bob].map(&.match(/^A./)).compact
And can be written as this:
%w[Alice Bob].compact_map(&.match(/^A./))
YAML configuration example:
Performance/CompactAfterMap:
Enabled: true
def self.new(config = nil)
#
This rule is used to identify usage of compact
calls that follow map
.
For example, this is considered inefficient:
%w[Alice Bob].map(&.match(/^A./)).compact
And can be written as this:
%w[Alice Bob].compact_map(&.match(/^A./))
YAML configuration example:
Performance/CompactAfterMap:
Enabled: true