From 4ae01956282efb5cd8810d1a339836b3f2d03577 Mon Sep 17 00:00:00 2001 From: Vitalii Elenhaupt Date: Sun, 27 Oct 2019 22:56:53 +0200 Subject: [PATCH] Avoid duplicated sections in a generated TODO file (additional fix) --- spec/ameba/formatter/todo_formatter_spec.cr | 1 + src/ameba/formatter/todo_formatter.cr | 3 +-- src/ameba/rule/base.cr | 6 +++++- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/spec/ameba/formatter/todo_formatter_spec.cr b/spec/ameba/formatter/todo_formatter_spec.cr index 8829f977..1abc9904 100644 --- a/spec/ameba/formatter/todo_formatter_spec.cr +++ b/spec/ameba/formatter/todo_formatter_spec.cr @@ -82,6 +82,7 @@ module Ameba s1 = Source.new "a = 1", "source1.cr" s2 = Source.new "a = 1", "source2.cr" s1.add_issue DummyRule.new, {1, 2}, "message1" + s1.add_issue NamedRule.new, {1, 2}, "message1" s1.add_issue DummyRule.new, {2, 2}, "message1" s2.add_issue DummyRule.new, {2, 2}, "message2" diff --git a/src/ameba/formatter/todo_formatter.cr b/src/ameba/formatter/todo_formatter.cr index 61cdd584..fd0b8100 100644 --- a/src/ameba/formatter/todo_formatter.cr +++ b/src/ameba/formatter/todo_formatter.cr @@ -41,8 +41,7 @@ module Ameba::Formatter Hash(Rule::Base, Array(Issue)).new.tap do |h| issues.each do |issue| next if issue.disabled? || issue.rule.is_a? Rule::Lint::Syntax - h[issue.rule] ||= Array(Issue).new - h[issue.rule] << issue + (h[issue.rule] ||= Array(Issue).new) << issue end end end diff --git a/src/ameba/rule/base.cr b/src/ameba/rule/base.cr index c3395e03..5c7c586b 100644 --- a/src/ameba/rule/base.cr +++ b/src/ameba/rule/base.cr @@ -106,7 +106,11 @@ module Ameba::Rule end def ==(other) - self.name == other.name + name == other.try &.name + end + + def hash + name.hash end macro issue_for(*args)