mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
Move constant definitions after properties
call
This commit is contained in:
parent
66a4b283d4
commit
5e58a60ade
4 changed files with 14 additions and 14 deletions
|
@ -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?
|
||||||
|
|
|
@ -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,
|
||||||
|
|
|
@ -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,
|
||||||
|
|
|
@ -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,
|
||||||
|
|
Loading…
Reference in a new issue