class Ameba::Rule::Performance::MinMaxAfterMap
- Ameba::Rule::Performance::MinMaxAfterMap
- Ameba::Rule::Performance::Base
- Ameba::Rule::Base
- Reference
- Object
Overview
This rule is used to identify usage of min/max/minmax
calls that follow map
.
For example, this is considered invalid:
%w[Alice Bob].map(&.size).min
%w[Alice Bob].map(&.size).max
%w[Alice Bob].map(&.size).minmax
And it should be written as this:
%w[Alice Bob].min_of(&.size)
%w[Alice Bob].max_of(&.size)
%w[Alice Bob].minmax_of(&.size)
YAML configuration example:
Performance/MinMaxAfterMap:
Enabled: true
Included Modules
- YAML::Serializable
- YAML::Serializable::Strict
Defined in:
ameba/rule/performance/minmax_after_map.crConstant Summary
-
CALL_NAMES =
["min", "min?", "max", "max?", "minmax", "minmax?"] of ::String
-
MSG =
"Use `%s {...}` instead of `map {...}.%s`."
Constructors
-
.new(ctx : YAML::ParseContext, node : YAML::Nodes::Node)
This rule is used to identify usage of
min/max/minmax
calls that followmap
. -
.new(config = nil)
This rule is used to identify usage of
min/max/minmax
calls that followmap
.
Class Method Summary
-
.parsed_doc : String | Nil
Returns documentation for this rule, if there is any.
Instance Method Summary
- #description : String
- #description=(description : String)
- #enabled=(enabled : Bool)
- #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
Class methods inherited from class Ameba::Rule::Performance::Base
parsed_doc : String | Nil
parsed_doc
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
default_severity : Ameba::Severity
default_severity
Constructor Detail
This rule is used to identify usage of min/max/minmax
calls that follow map
.
For example, this is considered invalid:
%w[Alice Bob].map(&.size).min
%w[Alice Bob].map(&.size).max
%w[Alice Bob].map(&.size).minmax
And it should be written as this:
%w[Alice Bob].min_of(&.size)
%w[Alice Bob].max_of(&.size)
%w[Alice Bob].minmax_of(&.size)
YAML configuration example:
Performance/MinMaxAfterMap:
Enabled: true
This rule is used to identify usage of min/max/minmax
calls that follow map
.
For example, this is considered invalid:
%w[Alice Bob].map(&.size).min
%w[Alice Bob].map(&.size).max
%w[Alice Bob].map(&.size).minmax
And it should be written as this:
%w[Alice Bob].min_of(&.size)
%w[Alice Bob].max_of(&.size)
%w[Alice Bob].minmax_of(&.size)
YAML configuration example:
Performance/MinMaxAfterMap:
Enabled: true
Class Method Detail
Returns documentation for this rule, if there is any.
module Ameba
# This is a test rule.
# Does nothing.
class MyRule < Ameba::Rule::Base
def test(source)
end
end
end
MyRule.parsed_doc # => "This is a test rule.\nDoes nothing."