From 3b7cd3723c2a069f212f64e287ac1bb5a63980ed Mon Sep 17 00:00:00 2001 From: Sijawusz Pur Rahnama Date: Wed, 23 Nov 2022 15:04:47 +0100 Subject: [PATCH 1/4] =?UTF-8?q?Refactor=20rules=E2=80=99=20default=20group?= =?UTF-8?q?=20severity=20handling?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/ameba/config.cr | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/ameba/config.cr b/src/ameba/config.cr index 47a4e49b..b4625064 100644 --- a/src/ameba/config.cr +++ b/src/ameba/config.cr @@ -255,9 +255,8 @@ class Ameba::Config {% end %} {% if properties["severity".id] == nil %} - {% default = @type.name.starts_with?("Ameba::Rule::Lint") ? "Ameba::Severity::Warning".id : "Ameba::Severity::Convention".id %} @[YAML::Field(key: "Severity", converter: Ameba::SeverityYamlConverter)] - property severity = {{ default }} + property severity = {{ @type }}.default_severity {% end %} {% if properties["excluded".id] == nil %} @@ -267,6 +266,14 @@ class Ameba::Config end macro included + GROUP_SEVERITY = { + Lint: Ameba::Severity::Warning, + } + + class_getter default_severity : Ameba::Severity do + GROUP_SEVERITY[group_name]? || Ameba::Severity::Convention + end + macro inherited include YAML::Serializable include YAML::Serializable::Strict From 75482a06cffb16f43f5e5fb05d3cbc62b10d5f36 Mon Sep 17 00:00:00 2001 From: Sijawusz Pur Rahnama Date: Wed, 23 Nov 2022 15:06:24 +0100 Subject: [PATCH 2/4] Use warning as a default severity for `Metrics` and `Performance` groups --- src/ameba/config.cr | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/ameba/config.cr b/src/ameba/config.cr index b4625064..d376cdc6 100644 --- a/src/ameba/config.cr +++ b/src/ameba/config.cr @@ -267,7 +267,9 @@ class Ameba::Config macro included GROUP_SEVERITY = { - Lint: Ameba::Severity::Warning, + Lint: Ameba::Severity::Warning, + Metrics: Ameba::Severity::Warning, + Performance: Ameba::Severity::Warning, } class_getter default_severity : Ameba::Severity do From 1399aa3cdfe907637d2e9253e75a932f28615f3a Mon Sep 17 00:00:00 2001 From: Sijawusz Pur Rahnama Date: Wed, 23 Nov 2022 16:15:46 +0100 Subject: [PATCH 3/4] Doc fixes --- src/ameba/rule/layout/trailing_whitespace.cr | 2 +- src/ameba/rule/lint/redundant_with_index.cr | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/ameba/rule/layout/trailing_whitespace.cr b/src/ameba/rule/layout/trailing_whitespace.cr index 471f3795..48561a96 100644 --- a/src/ameba/rule/layout/trailing_whitespace.cr +++ b/src/ameba/rule/layout/trailing_whitespace.cr @@ -9,7 +9,7 @@ module Ameba::Rule::Layout # ``` class TrailingWhitespace < Base properties do - description "Disallows trailing whitespaces" + description "Disallows trailing whitespace" end MSG = "Trailing whitespace detected" diff --git a/src/ameba/rule/lint/redundant_with_index.cr b/src/ameba/rule/lint/redundant_with_index.cr index 6f622986..5ae815b5 100644 --- a/src/ameba/rule/lint/redundant_with_index.cr +++ b/src/ameba/rule/lint/redundant_with_index.cr @@ -2,6 +2,7 @@ module Ameba::Rule::Lint # A rule that disallows redundant `with_index` calls. # # For example, this is considered invalid: + # # ``` # collection.each.with_index do |e| # # ... From 6a180757f3afb819ed353cc7432cc276e1f65d77 Mon Sep 17 00:00:00 2001 From: Sijawusz Pur Rahnama Date: Wed, 23 Nov 2022 16:16:34 +0100 Subject: [PATCH 4/4] Use `Enumerable#zip` ftw --- src/ameba/runner.cr | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/ameba/runner.cr b/src/ameba/runner.cr index 2f8ee72b..6023fcd6 100644 --- a/src/ameba/runner.cr +++ b/src/ameba/runner.cr @@ -88,8 +88,7 @@ module Ameba @formatter.started @sources channels = @sources.map { Channel(Exception?).new } - @sources.each_with_index do |source, idx| - channel = channels[idx] + @sources.zip(channels).each do |source, channel| spawn do run_source(source) rescue e