Merge pull request #311 from crystal-ameba/Sija/add-severity-color

Add `Severity#color`
This commit is contained in:
Sijawusz Pur Rahnama 2022-11-28 11:24:31 +01:00 committed by GitHub
commit 20935ae381
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 1 deletions

View file

@ -49,7 +49,7 @@ module Ameba::Formatter
issue.rule.severity.symbol, issue.rule.severity.symbol,
issue.rule.name, issue.rule.name,
issue.message, issue.message,
}).colorize(:red) }).colorize(issue.rule.severity.color)
if show_affected_code && (code = affected_code(issue)) if show_affected_code && (code = affected_code(issue))
output << code.colorize(:default) output << code.colorize(:default)

View file

@ -1,3 +1,5 @@
require "colorize"
module Ameba module Ameba
enum Severity enum Severity
Error Error
@ -17,6 +19,19 @@ module Ameba
end end
end end
# Returns a color uniquely indicating severity.
#
# ```
# Severity::Warning.color # => Colorize::ColorANSI::Red
# ```
def color : Colorize::Color
case self
in Error then Colorize::ColorANSI::Red
in Warning then Colorize::ColorANSI::Red
in Convention then Colorize::ColorANSI::Blue
end
end
# Creates Severity by the name. # Creates Severity by the name.
# #
# ``` # ```