Merge pull request #310 from crystal-ameba/Sija/refactor-rule-default-group-severity

This commit is contained in:
Sijawusz Pur Rahnama 2022-11-24 15:34:09 +01:00 committed by GitHub
commit f89e7c2d3c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 14 additions and 5 deletions

View file

@ -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,16 @@ class Ameba::Config
end
macro included
GROUP_SEVERITY = {
Lint: Ameba::Severity::Warning,
Metrics: Ameba::Severity::Warning,
Performance: 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

View file

@ -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"

View file

@ -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|
# # ...

View file

@ -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