diff --git a/src/ameba/ast/visitors/scope_visitor.cr b/src/ameba/ast/visitors/scope_visitor.cr index 95b550cf..73aa89bc 100644 --- a/src/ameba/ast/visitors/scope_visitor.cr +++ b/src/ameba/ast/visitors/scope_visitor.cr @@ -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) diff --git a/src/ameba/rule/lint/not_nil.cr b/src/ameba/rule/lint/not_nil.cr index be4268dc..653d0272 100644 --- a/src/ameba/rule/lint/not_nil.cr +++ b/src/ameba/rule/lint/not_nil.cr @@ -32,15 +32,14 @@ module Ameba::Rule::Lint description "Identifies usage of `not_nil!` calls" end - NOT_NIL_NAME = "not_nil!" - MSG = "Avoid using `not_nil!`" + MSG = "Avoid using `not_nil!`" def test(source) AST::NodeVisitor.new self, source, skip: :macro 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 diff --git a/src/ameba/rule/lint/not_nil_after_no_bang.cr b/src/ameba/rule/lint/not_nil_after_no_bang.cr index dbde7ab8..b69a4927 100644 --- a/src/ameba/rule/lint/not_nil_after_no_bang.cr +++ b/src/ameba/rule/lint/not_nil_after_no_bang.cr @@ -30,15 +30,14 @@ 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!`" + MSG = "Use `%s! {...}` instead of `%s {...}.not_nil!`" def test(source) AST::NodeVisitor.new self, source, skip: :macro 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) diff --git a/src/ameba/rule/performance/any_after_filter.cr b/src/ameba/rule/performance/any_after_filter.cr index 3dafb598..c16d9412 100644 --- a/src/ameba/rule/performance/any_after_filter.cr +++ b/src/ameba/rule/performance/any_after_filter.cr @@ -32,11 +32,10 @@ module Ameba::Rule::Performance filter_names %w(select reject) end - ANY_NAME = "any?" - MSG = "Use `any? {...}` instead of `%s {...}.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) diff --git a/src/ameba/rule/performance/any_instead_of_empty.cr b/src/ameba/rule/performance/any_instead_of_empty.cr index cee76ef6..41be7eec 100644 --- a/src/ameba/rule/performance/any_instead_of_empty.cr +++ b/src/ameba/rule/performance/any_instead_of_empty.cr @@ -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?`" + 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 diff --git a/src/ameba/rule/performance/compact_after_map.cr b/src/ameba/rule/performance/compact_after_map.cr index 6d3e0099..e7807a1b 100644 --- a/src/ameba/rule/performance/compact_after_map.cr +++ b/src/ameba/rule/performance/compact_after_map.cr @@ -26,18 +26,16 @@ 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`" + MSG = "Use `compact_map {...}` instead of `map {...}.compact`" def test(source) AST::NodeVisitor.new self, source, skip: :macro 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 diff --git a/src/ameba/rule/performance/flatten_after_map.cr b/src/ameba/rule/performance/flatten_after_map.cr index 3051681c..34576240 100644 --- a/src/ameba/rule/performance/flatten_after_map.cr +++ b/src/ameba/rule/performance/flatten_after_map.cr @@ -26,18 +26,16 @@ 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`" + MSG = "Use `flat_map {...}` instead of `map {...}.flatten`" def test(source) AST::NodeVisitor.new self, source, skip: :macro 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 diff --git a/src/ameba/rule/performance/size_after_filter.cr b/src/ameba/rule/performance/size_after_filter.cr index 2e5dbbb0..1f1e1857 100644 --- a/src/ameba/rule/performance/size_after_filter.cr +++ b/src/ameba/rule/performance/size_after_filter.cr @@ -38,15 +38,14 @@ module Ameba::Rule::Performance filter_names %w(select reject) end - SIZE_NAME = "size" - MSG = "Use `count {...}` instead of `%s {...}.size`." + MSG = "Use `count {...}` instead of `%s {...}.size`." def test(source) AST::NodeVisitor.new self, source, skip: :macro 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)