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 %} {% end %}
{% if properties["severity".id] == nil %} {% 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)] @[YAML::Field(key: "Severity", converter: Ameba::SeverityYamlConverter)]
property severity = {{ default }} property severity = {{ @type }}.default_severity
{% end %} {% end %}
{% if properties["excluded".id] == nil %} {% if properties["excluded".id] == nil %}
@ -267,6 +266,16 @@ class Ameba::Config
end end
macro included 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 macro inherited
include YAML::Serializable include YAML::Serializable
include YAML::Serializable::Strict include YAML::Serializable::Strict

View file

@ -9,7 +9,7 @@ module Ameba::Rule::Layout
# ``` # ```
class TrailingWhitespace < Base class TrailingWhitespace < Base
properties do properties do
description "Disallows trailing whitespaces" description "Disallows trailing whitespace"
end end
MSG = "Trailing whitespace detected" MSG = "Trailing whitespace detected"

View file

@ -2,6 +2,7 @@ module Ameba::Rule::Lint
# A rule that disallows redundant `with_index` calls. # A rule that disallows redundant `with_index` calls.
# #
# For example, this is considered invalid: # For example, this is considered invalid:
#
# ``` # ```
# collection.each.with_index do |e| # collection.each.with_index do |e|
# # ... # # ...

View file

@ -88,8 +88,7 @@ module Ameba
@formatter.started @sources @formatter.started @sources
channels = @sources.map { Channel(Exception?).new } channels = @sources.map { Channel(Exception?).new }
@sources.each_with_index do |source, idx| @sources.zip(channels).each do |source, channel|
channel = channels[idx]
spawn do spawn do
run_source(source) run_source(source)
rescue e rescue e