From d19d3b78c4afade4b62513f6377869c0277b9a46 Mon Sep 17 00:00:00 2001 From: Sijawusz Pur Rahnama Date: Fri, 25 Nov 2022 04:01:34 +0100 Subject: [PATCH] Implement `Severity#color` property --- src/ameba/formatter/dot_formatter.cr | 2 +- src/ameba/severity.cr | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/ameba/formatter/dot_formatter.cr b/src/ameba/formatter/dot_formatter.cr index 38575e18..97982622 100644 --- a/src/ameba/formatter/dot_formatter.cr +++ b/src/ameba/formatter/dot_formatter.cr @@ -49,7 +49,7 @@ module Ameba::Formatter issue.rule.severity.symbol, issue.rule.name, issue.message, - }).colorize(:red) + }).colorize(issue.rule.severity.color) if show_affected_code && (code = affected_code(issue)) output << code.colorize(:default) diff --git a/src/ameba/severity.cr b/src/ameba/severity.cr index 6444a79d..ed350a96 100644 --- a/src/ameba/severity.cr +++ b/src/ameba/severity.cr @@ -1,3 +1,5 @@ +require "colorize" + module Ameba enum Severity Error @@ -17,6 +19,19 @@ module Ameba 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. # # ```