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]
|
SPECIAL_NODE_NAMES = %w[super previous_def]
|
||||||
RECORD_NODE_NAME = "record"
|
|
||||||
|
|
||||||
@scope_queue = [] of Scope
|
@scope_queue = [] of Scope
|
||||||
@current_scope : Scope
|
@current_scope : Scope
|
||||||
|
@ -190,7 +189,7 @@ module Ameba::AST
|
||||||
end
|
end
|
||||||
|
|
||||||
private def record_macro?(node)
|
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
|
end
|
||||||
|
|
||||||
private def skip?(node)
|
private def skip?(node)
|
||||||
|
|
|
@ -32,15 +32,14 @@ module Ameba::Rule::Lint
|
||||||
description "Identifies usage of `not_nil!` calls"
|
description "Identifies usage of `not_nil!` calls"
|
||||||
end
|
end
|
||||||
|
|
||||||
NOT_NIL_NAME = "not_nil!"
|
MSG = "Avoid using `not_nil!`"
|
||||||
MSG = "Avoid using `not_nil!`"
|
|
||||||
|
|
||||||
def test(source)
|
def test(source)
|
||||||
AST::NodeVisitor.new self, source, skip: :macro
|
AST::NodeVisitor.new self, source, skip: :macro
|
||||||
end
|
end
|
||||||
|
|
||||||
def test(source, node : Crystal::Call)
|
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 node.obj && node.args.empty?
|
||||||
|
|
||||||
return unless name_location = node.name_location
|
return unless name_location = node.name_location
|
||||||
|
|
|
@ -30,15 +30,14 @@ module Ameba::Rule::Lint
|
||||||
BLOCK_CALL_NAMES = %w(index rindex find)
|
BLOCK_CALL_NAMES = %w(index rindex find)
|
||||||
CALL_NAMES = %w(index rindex)
|
CALL_NAMES = %w(index rindex)
|
||||||
|
|
||||||
NOT_NIL_NAME = "not_nil!"
|
MSG = "Use `%s! {...}` instead of `%s {...}.not_nil!`"
|
||||||
MSG = "Use `%s! {...}` instead of `%s {...}.not_nil!`"
|
|
||||||
|
|
||||||
def test(source)
|
def test(source)
|
||||||
AST::NodeVisitor.new self, source, skip: :macro
|
AST::NodeVisitor.new self, source, skip: :macro
|
||||||
end
|
end
|
||||||
|
|
||||||
def test(source, node : Crystal::Call)
|
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 = node.obj).is_a?(Crystal::Call)
|
||||||
return unless obj.name.in?(obj.block ? BLOCK_CALL_NAMES : CALL_NAMES)
|
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)
|
filter_names %w(select reject)
|
||||||
end
|
end
|
||||||
|
|
||||||
ANY_NAME = "any?"
|
MSG = "Use `any? {...}` instead of `%s {...}.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?" && (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?
|
||||||
return unless obj.name.in?(filter_names)
|
return unless obj.name.in?(filter_names)
|
||||||
|
|
||||||
|
|
|
@ -34,11 +34,10 @@ module Ameba::Rule::Performance
|
||||||
description "Identifies usage of arg-less `any?` calls"
|
description "Identifies usage of arg-less `any?` calls"
|
||||||
end
|
end
|
||||||
|
|
||||||
ANY_NAME = "any?"
|
MSG = "Use `!{...}.empty?` instead of `{...}.any?`"
|
||||||
MSG = "Use `!{...}.empty?` instead of `{...}.any?`"
|
|
||||||
|
|
||||||
def test(source, node : Crystal::Call)
|
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.block.nil? && node.args.empty?
|
||||||
return unless node.obj
|
return unless node.obj
|
||||||
|
|
||||||
|
|
|
@ -26,18 +26,16 @@ module Ameba::Rule::Performance
|
||||||
description "Identifies usage of `compact` calls that follow `map`"
|
description "Identifies usage of `compact` calls that follow `map`"
|
||||||
end
|
end
|
||||||
|
|
||||||
COMPACT_NAME = "compact"
|
MSG = "Use `compact_map {...}` instead of `map {...}.compact`"
|
||||||
MAP_NAME = "map"
|
|
||||||
MSG = "Use `compact_map {...}` instead of `map {...}.compact`"
|
|
||||||
|
|
||||||
def test(source)
|
def test(source)
|
||||||
AST::NodeVisitor.new self, source, skip: :macro
|
AST::NodeVisitor.new self, source, skip: :macro
|
||||||
end
|
end
|
||||||
|
|
||||||
def test(source, node : Crystal::Call)
|
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.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
|
issue_for obj.name_location, node.name_end_location, MSG
|
||||||
end
|
end
|
||||||
|
|
|
@ -26,18 +26,16 @@ module Ameba::Rule::Performance
|
||||||
description "Identifies usage of `flatten` calls that follow `map`"
|
description "Identifies usage of `flatten` calls that follow `map`"
|
||||||
end
|
end
|
||||||
|
|
||||||
FLATTEN_NAME = "flatten"
|
MSG = "Use `flat_map {...}` instead of `map {...}.flatten`"
|
||||||
MAP_NAME = "map"
|
|
||||||
MSG = "Use `flat_map {...}` instead of `map {...}.flatten`"
|
|
||||||
|
|
||||||
def test(source)
|
def test(source)
|
||||||
AST::NodeVisitor.new self, source, skip: :macro
|
AST::NodeVisitor.new self, source, skip: :macro
|
||||||
end
|
end
|
||||||
|
|
||||||
def test(source, node : Crystal::Call)
|
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.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
|
issue_for obj.name_location, node.name_end_location, MSG
|
||||||
end
|
end
|
||||||
|
|
|
@ -38,15 +38,14 @@ module Ameba::Rule::Performance
|
||||||
filter_names %w(select reject)
|
filter_names %w(select reject)
|
||||||
end
|
end
|
||||||
|
|
||||||
SIZE_NAME = "size"
|
MSG = "Use `count {...}` instead of `%s {...}.size`."
|
||||||
MSG = "Use `count {...}` instead of `%s {...}.size`."
|
|
||||||
|
|
||||||
def test(source)
|
def test(source)
|
||||||
AST::NodeVisitor.new self, source, skip: :macro
|
AST::NodeVisitor.new self, source, skip: :macro
|
||||||
end
|
end
|
||||||
|
|
||||||
def test(source, node : Crystal::Call)
|
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.is_a?(Crystal::Call) && obj.block
|
||||||
return unless obj.name.in?(filter_names)
|
return unless obj.name.in?(filter_names)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue