Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor rules’ default group severity handling #310

Merged
merged 4 commits into from
Nov 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/ameba/config.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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 %}
Expand All @@ -267,6 +266,16 @@ class Ameba::Config
end

macro included
GROUP_SEVERITY = {
Lint: Ameba::Severity::Warning,
Metrics: Ameba::Severity::Warning,
Performance: Ameba::Severity::Warning,
}
Sija marked this conversation as resolved.
Show resolved Hide resolved

class_getter default_severity : Ameba::Severity do
GROUP_SEVERITY[group_name]? || Ameba::Severity::Convention
end

macro inherited
include YAML::Serializable
include YAML::Serializable::Strict
Expand Down
2 changes: 1 addition & 1 deletion src/ameba/rule/layout/trailing_whitespace.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions src/ameba/rule/lint/redundant_with_index.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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|
# # ...
Expand Down
3 changes: 1 addition & 2 deletions src/ameba/runner.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down