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 # - reject
# ``` # ```
struct AnyAfterFilter < Base struct AnyAfterFilter < Base
ANY_NAME = "any?"
MSG = "Use `any? {...}` instead of `%s {...}.any?`"
properties do properties do
filter_names : Array(String) = %w(select reject) filter_names : Array(String) = %w(select reject)
description "Identifies usage of `any?` calls that follow filters." description "Identifies usage of `any?` calls that follow filters."
end end
ANY_NAME = "any?"
MSG = "Use `any? {...}` instead of `%s {...}.any?`"
def test(source, node : Crystal::Call) def test(source, node : Crystal::Call)
return unless node.name == ANY_NAME && (obj = node.obj) return unless node.name == ANY_NAME && (obj = node.obj)
return unless obj.is_a?(Crystal::Call) && obj.block && node.block.nil? return unless obj.is_a?(Crystal::Call) && obj.block && node.block.nil?

View file

@ -24,15 +24,15 @@ module Ameba::Rule::Performance
# - select # - select
# ``` # ```
struct FirstLastAfterFilter < Base 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 properties do
filter_names : Array(String) = %w(select) filter_names : Array(String) = %w(select)
description "Identifies usage of `first/last/first?/last?` calls that follow filters." description "Identifies usage of `first/last/first?/last?` calls that follow filters."
end 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) def test(source)
AST::NodeVisitor.new self, source, skip: [ AST::NodeVisitor.new self, source, skip: [
Crystal::Macro, Crystal::Macro,

View file

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

View file

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