mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
No need for such micro-optimizations, LLVM takes care of those
This commit is contained in:
parent
29e29b8e1d
commit
5cff76071a
8 changed files with 17 additions and 27 deletions
|
@ -21,7 +21,6 @@ module Ameba::AST
|
|||
}
|
||||
|
||||
SPECIAL_NODE_NAMES = %w[super previous_def]
|
||||
RECORD_NODE_NAME = "record"
|
||||
|
||||
@scope_queue = [] of Scope
|
||||
@current_scope : Scope
|
||||
|
@ -190,7 +189,7 @@ module Ameba::AST
|
|||
end
|
||||
|
||||
private def record_macro?(node)
|
||||
node.name == RECORD_NODE_NAME && node.args.first?.is_a?(Crystal::Path)
|
||||
node.name == "record" && node.args.first?.is_a?(Crystal::Path)
|
||||
end
|
||||
|
||||
private def skip?(node)
|
||||
|
|
|
@ -32,7 +32,6 @@ module Ameba::Rule::Lint
|
|||
description "Identifies usage of `not_nil!` calls"
|
||||
end
|
||||
|
||||
NOT_NIL_NAME = "not_nil!"
|
||||
MSG = "Avoid using `not_nil!`"
|
||||
|
||||
def test(source)
|
||||
|
@ -40,7 +39,7 @@ module Ameba::Rule::Lint
|
|||
end
|
||||
|
||||
def test(source, node : Crystal::Call)
|
||||
return unless node.name == NOT_NIL_NAME
|
||||
return unless node.name == "not_nil!"
|
||||
return unless node.obj && node.args.empty?
|
||||
|
||||
return unless name_location = node.name_location
|
||||
|
|
|
@ -30,7 +30,6 @@ module Ameba::Rule::Lint
|
|||
BLOCK_CALL_NAMES = %w(index rindex find)
|
||||
CALL_NAMES = %w(index rindex)
|
||||
|
||||
NOT_NIL_NAME = "not_nil!"
|
||||
MSG = "Use `%s! {...}` instead of `%s {...}.not_nil!`"
|
||||
|
||||
def test(source)
|
||||
|
@ -38,7 +37,7 @@ module Ameba::Rule::Lint
|
|||
end
|
||||
|
||||
def test(source, node : Crystal::Call)
|
||||
return unless node.name == NOT_NIL_NAME && node.args.empty?
|
||||
return unless node.name == "not_nil!" && node.args.empty?
|
||||
return unless (obj = node.obj).is_a?(Crystal::Call)
|
||||
return unless obj.name.in?(obj.block ? BLOCK_CALL_NAMES : CALL_NAMES)
|
||||
|
||||
|
|
|
@ -32,11 +32,10 @@ module Ameba::Rule::Performance
|
|||
filter_names %w(select reject)
|
||||
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 node.name == "any?" && (obj = node.obj)
|
||||
return unless obj.is_a?(Crystal::Call) && obj.block && node.block.nil?
|
||||
return unless obj.name.in?(filter_names)
|
||||
|
||||
|
|
|
@ -34,11 +34,10 @@ module Ameba::Rule::Performance
|
|||
description "Identifies usage of arg-less `any?` calls"
|
||||
end
|
||||
|
||||
ANY_NAME = "any?"
|
||||
MSG = "Use `!{...}.empty?` instead of `{...}.any?`"
|
||||
|
||||
def test(source, node : Crystal::Call)
|
||||
return unless node.name == ANY_NAME
|
||||
return unless node.name == "any?"
|
||||
return unless node.block.nil? && node.args.empty?
|
||||
return unless node.obj
|
||||
|
||||
|
|
|
@ -26,8 +26,6 @@ module Ameba::Rule::Performance
|
|||
description "Identifies usage of `compact` calls that follow `map`"
|
||||
end
|
||||
|
||||
COMPACT_NAME = "compact"
|
||||
MAP_NAME = "map"
|
||||
MSG = "Use `compact_map {...}` instead of `map {...}.compact`"
|
||||
|
||||
def test(source)
|
||||
|
@ -35,9 +33,9 @@ module Ameba::Rule::Performance
|
|||
end
|
||||
|
||||
def test(source, node : Crystal::Call)
|
||||
return unless node.name == COMPACT_NAME && (obj = node.obj)
|
||||
return unless node.name == "compact" && (obj = node.obj)
|
||||
return unless obj.is_a?(Crystal::Call) && obj.block
|
||||
return unless obj.name == MAP_NAME
|
||||
return unless obj.name == "map"
|
||||
|
||||
issue_for obj.name_location, node.name_end_location, MSG
|
||||
end
|
||||
|
|
|
@ -26,8 +26,6 @@ module Ameba::Rule::Performance
|
|||
description "Identifies usage of `flatten` calls that follow `map`"
|
||||
end
|
||||
|
||||
FLATTEN_NAME = "flatten"
|
||||
MAP_NAME = "map"
|
||||
MSG = "Use `flat_map {...}` instead of `map {...}.flatten`"
|
||||
|
||||
def test(source)
|
||||
|
@ -35,9 +33,9 @@ module Ameba::Rule::Performance
|
|||
end
|
||||
|
||||
def test(source, node : Crystal::Call)
|
||||
return unless node.name == FLATTEN_NAME && (obj = node.obj)
|
||||
return unless node.name == "flatten" && (obj = node.obj)
|
||||
return unless obj.is_a?(Crystal::Call) && obj.block
|
||||
return unless obj.name == MAP_NAME
|
||||
return unless obj.name == "map"
|
||||
|
||||
issue_for obj.name_location, node.name_end_location, MSG
|
||||
end
|
||||
|
|
|
@ -38,7 +38,6 @@ module Ameba::Rule::Performance
|
|||
filter_names %w(select reject)
|
||||
end
|
||||
|
||||
SIZE_NAME = "size"
|
||||
MSG = "Use `count {...}` instead of `%s {...}.size`."
|
||||
|
||||
def test(source)
|
||||
|
@ -46,7 +45,7 @@ module Ameba::Rule::Performance
|
|||
end
|
||||
|
||||
def test(source, node : Crystal::Call)
|
||||
return unless node.name == SIZE_NAME && (obj = node.obj)
|
||||
return unless node.name == "size" && (obj = node.obj)
|
||||
return unless obj.is_a?(Crystal::Call) && obj.block
|
||||
return unless obj.name.in?(filter_names)
|
||||
|
||||
|
|
Loading…
Reference in a new issue