From 16141a376ea3e9956481cd01a9452841e9847fb1 Mon Sep 17 00:00:00 2001 From: Sijawusz Pur Rahnama Date: Wed, 14 Jun 2023 15:08:19 +0200 Subject: [PATCH] Cleanup properties definition macro --- src/ameba/config.cr | 8 +++----- src/ameba/rule/lint/debug_calls.cr | 2 +- src/ameba/rule/performance/any_after_filter.cr | 2 +- src/ameba/rule/performance/chained_call_with_no_bang.cr | 2 +- src/ameba/rule/performance/first_last_after_filter.cr | 2 +- src/ameba/rule/performance/size_after_filter.cr | 2 +- src/ameba/rule/style/is_a_filter.cr | 2 +- 7 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/ameba/config.cr b/src/ameba/config.cr index b2da95e8..3d3a3c71 100644 --- a/src/ameba/config.cr +++ b/src/ameba/config.cr @@ -292,17 +292,15 @@ class Ameba::Config {% type = Float64 %} {% end %} {% end %} - - {% type = Nil if type == nil %} {% end %} {% properties[name] = {key: key, default: value, type: type, converter: converter} %} - @[YAML::Field(key: {{ key }}, converter: {{ converter }}, type: {{ type }})] + @[YAML::Field(key: {{ key }}, converter: {{ converter }})] {% if type == Bool %} - property? {{ name }} : {{ type }} = {{ value }} + property? {{ name }}{{ " : #{type}".id if type }} = {{ value }} {% else %} - property {{ name }} : {{ type }} = {{ value }} + property {{ name }}{{ " : #{type}".id if type }} = {{ value }} {% end %} {% end %} diff --git a/src/ameba/rule/lint/debug_calls.cr b/src/ameba/rule/lint/debug_calls.cr index 0e02be29..fc4e3e2f 100644 --- a/src/ameba/rule/lint/debug_calls.cr +++ b/src/ameba/rule/lint/debug_calls.cr @@ -18,7 +18,7 @@ module Ameba::Rule::Lint class DebugCalls < Base properties do description "Disallows debug-related calls" - method_names : Array(String) = %w(p p! pp pp!) + method_names %w(p p! pp pp!) end MSG = "Possibly forgotten debug-related `%s` call detected" diff --git a/src/ameba/rule/performance/any_after_filter.cr b/src/ameba/rule/performance/any_after_filter.cr index f40fbbca..3dafb598 100644 --- a/src/ameba/rule/performance/any_after_filter.cr +++ b/src/ameba/rule/performance/any_after_filter.cr @@ -29,7 +29,7 @@ module Ameba::Rule::Performance class AnyAfterFilter < Base properties do description "Identifies usage of `any?` calls that follow filters" - filter_names : Array(String) = %w(select reject) + filter_names %w(select reject) end ANY_NAME = "any?" diff --git a/src/ameba/rule/performance/chained_call_with_no_bang.cr b/src/ameba/rule/performance/chained_call_with_no_bang.cr index d9285726..ef505b73 100644 --- a/src/ameba/rule/performance/chained_call_with_no_bang.cr +++ b/src/ameba/rule/performance/chained_call_with_no_bang.cr @@ -45,7 +45,7 @@ module Ameba::Rule::Performance # All of those have bang method variants returning `self` # and are not modifying the receiver type (like `compact` does), # thus are safe to switch to the bang variant. - call_names : Array(String) = %w(uniq sort sort_by shuffle reverse) + call_names %w(uniq sort sort_by shuffle reverse) end # All these methods are allocating a new object diff --git a/src/ameba/rule/performance/first_last_after_filter.cr b/src/ameba/rule/performance/first_last_after_filter.cr index a995fcae..9127ccd5 100644 --- a/src/ameba/rule/performance/first_last_after_filter.cr +++ b/src/ameba/rule/performance/first_last_after_filter.cr @@ -28,7 +28,7 @@ module Ameba::Rule::Performance class FirstLastAfterFilter < Base properties do description "Identifies usage of `first/last/first?/last?` calls that follow filters" - filter_names : Array(String) = %w(select) + filter_names %w(select) end CALL_NAMES = %w(first last first? last?) diff --git a/src/ameba/rule/performance/size_after_filter.cr b/src/ameba/rule/performance/size_after_filter.cr index ba952586..2e5dbbb0 100644 --- a/src/ameba/rule/performance/size_after_filter.cr +++ b/src/ameba/rule/performance/size_after_filter.cr @@ -35,7 +35,7 @@ module Ameba::Rule::Performance class SizeAfterFilter < Base properties do description "Identifies usage of `size` calls that follow filter" - filter_names : Array(String) = %w(select reject) + filter_names %w(select reject) end SIZE_NAME = "size" diff --git a/src/ameba/rule/style/is_a_filter.cr b/src/ameba/rule/style/is_a_filter.cr index 8b07f3a9..97c131fa 100644 --- a/src/ameba/rule/style/is_a_filter.cr +++ b/src/ameba/rule/style/is_a_filter.cr @@ -41,7 +41,7 @@ module Ameba::Rule::Style class IsAFilter < Base properties do description "Identifies usage of `is_a?/nil?` calls within filters" - filter_names : Array(String) = %w(select reject any? all? none? one?) + filter_names %w(select reject any? all? none? one?) end MSG = "Use `%s` instead of `%s`"