diff --git a/lib/cc/engine/analyzers/engine_config.rb b/lib/cc/engine/analyzers/engine_config.rb index 17d01bac..9c5bdc54 100644 --- a/lib/cc/engine/analyzers/engine_config.rb +++ b/lib/cc/engine/analyzers/engine_config.rb @@ -6,6 +6,10 @@ def initialize(hash) @config = normalize(hash) end + def debug? + config.fetch("config", {}).fetch("debug", false) + end + def include_paths config.fetch("include_paths", ["./"]) end diff --git a/lib/cc/engine/analyzers/reporter.rb b/lib/cc/engine/analyzers/reporter.rb index 91ea3ef7..90c6b79e 100644 --- a/lib/cc/engine/analyzers/reporter.rb +++ b/lib/cc/engine/analyzers/reporter.rb @@ -16,8 +16,12 @@ def initialize(engine_config, language_strategy, io) end def run + debug("Processing #{language_strategy.files.count} files concurrency=#{engine_config.concurrency}") + process_files report + + debug("Reported #{reports.size} violations...") end def process_files @@ -26,12 +30,20 @@ def process_files concurrency: engine_config.concurrency ) + processed_files_count = Concurrent::AtomicFixnum.new + pool.run do |file| + debug("Processing file: #{file}") + sexp = language_strategy.run(file) process_sexp(sexp) + + processed_files_count.increment end pool.join + + debug("Processed #{processed_files_count.value} files") end def report @@ -39,6 +51,8 @@ def report violations = new_violations(issue) violations.each do |violation| + debug("Violation name=#{violation.report_name} mass=#{violation.mass}") + unless reports.include?(violation.report_name) reports.add(violation.report_name) io.puts "#{violation.format.to_json}\0" @@ -80,6 +94,10 @@ def flay_options only: nil } end + + def debug(message) + $stderr.puts(message) if engine_config.debug? + end end end end diff --git a/spec/support/helpers/analyzer_spec_helpers.rb b/spec/support/helpers/analyzer_spec_helpers.rb index 1968057f..83f28d65 100644 --- a/spec/support/helpers/analyzer_spec_helpers.rb +++ b/spec/support/helpers/analyzer_spec_helpers.rb @@ -11,7 +11,7 @@ def run_engine(config = nil) io = StringIO.new engine = described_class.new(engine_config: config) - reporter = ::CC::Engine::Analyzers::Reporter.new(double(concurrency: 2), engine, io) + reporter = ::CC::Engine::Analyzers::Reporter.new(config, engine, io) reporter.run