From fd1ff9e575b7778ecd97573794e47b8c44f4c238 Mon Sep 17 00:00:00 2001 From: Aslan Dukaev Date: Sun, 8 Mar 2020 02:00:23 +0300 Subject: [PATCH] Improve performance --- lib/fasterer/file_traverser.rb | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/fasterer/file_traverser.rb b/lib/fasterer/file_traverser.rb index c562ac6..ac80241 100644 --- a/lib/fasterer/file_traverser.rb +++ b/lib/fasterer/file_traverser.rb @@ -21,6 +21,7 @@ def initialize(path) @parse_error_paths = [] @config = Config.new @offenses_total_count = 0 + @explanation = {} end def traverse @@ -84,9 +85,7 @@ def output(analyzer) offenses_grouped_by_type(analyzer).each do |error_group_name, error_occurences| error_occurences.map(&:line_number).each do |line| file_and_line = "#{analyzer.file_path}:#{line}" - message = Fasterer::Explanation.new(error_group_name).call - - print "#{file_and_line.colorize(:red)} #{message}\n" + print "#{file_and_line.colorize(:red)} #{explanation(error_group_name)}\n" end end @@ -129,6 +128,10 @@ def ignored_files def nil_config_file config.nil_file end + + def explanation(offense_name) + @explanations[offense_name] ||= Fasterer::Explanation.new(offense_name).call + end end ErrorData = Struct.new(:file_path, :error_class, :error_message) do