Move constant definitions after properties call

This commit is contained in:
Sijawusz Pur Rahnama 2021-01-17 17:39:32 +01:00
parent 66a4b283d4
commit 5e58a60ade
4 changed files with 14 additions and 14 deletions

View file

@ -25,14 +25,14 @@ module Ameba::Rule::Performance
# - reject
# ```
struct AnyAfterFilter < Base
ANY_NAME = "any?"
MSG = "Use `any? {...}` instead of `%s {...}.any?`"
properties do
filter_names : Array(String) = %w(select reject)
description "Identifies usage of `any?` calls that follow filters."
end
ANY_NAME = "any?"
MSG = "Use `any? {...}` instead of `%s {...}.any?`"
def test(source, node : Crystal::Call)
return unless node.name == ANY_NAME && (obj = node.obj)
return unless obj.is_a?(Crystal::Call) && obj.block && node.block.nil?

View file

@ -24,15 +24,15 @@ module Ameba::Rule::Performance
# - select
# ```
struct FirstLastAfterFilter < Base
CALL_NAMES = %w(first last first? last?)
MSG = "Use `find {...}` instead of `%s {...}.%s`"
MSG_REVERSE = "Use `reverse_each.find {...}` instead of `%s {...}.%s`"
properties do
filter_names : Array(String) = %w(select)
description "Identifies usage of `first/last/first?/last?` calls that follow filters."
end
CALL_NAMES = %w(first last first? last?)
MSG = "Use `find {...}` instead of `%s {...}.%s`"
MSG_REVERSE = "Use `reverse_each.find {...}` instead of `%s {...}.%s`"
def test(source)
AST::NodeVisitor.new self, source, skip: [
Crystal::Macro,

View file

@ -20,14 +20,14 @@ module Ameba::Rule::Performance
# Enabled: true
# ```
struct JoinAfterMap < Base
MAP_NAME = "map"
JOIN_NAME = "join"
MSG = "Use `join(separator) {...}` instead of `map {...}.join(separator)`"
properties do
description "Identifies usage of `join` calls that follow `map`."
end
MAP_NAME = "map"
JOIN_NAME = "join"
MSG = "Use `join(separator) {...}` instead of `map {...}.join(separator)`"
def test(source)
AST::NodeVisitor.new self, source, skip: [
Crystal::Macro,

View file

@ -31,14 +31,14 @@ module Ameba::Rule::Performance
# - reject
# ```
struct SizeAfterFilter < Base
SIZE_NAME = "size"
MSG = "Use `count {...}` instead of `%s {...}.size`."
properties do
filter_names : Array(String) = %w(select reject)
description "Identifies usage of `size` calls that follow filter"
end
SIZE_NAME = "size"
MSG = "Use `count {...}` instead of `%s {...}.size`."
def test(source)
AST::NodeVisitor.new self, source, skip: [
Crystal::Macro,