Module: MetzScan::Commands::Scan::ProjectCopScope

Defined in:
lib/metz_scan/commands/scan/runner.rb

Overview

Default mode forces stock Metz tuning (--force-default-config) but must still honor the project's per-cop file scope (Include/Exclude), the same way #33 honors AllCops: Exclude. RuboCop's own excluded_file? resolves the project config's scope per cop; offenses on files a cop is scoped off are dropped here. Invalid project config -> nothing to honor (matches the forced-default target-discovery fallback). See #37.

Class Method Summary collapse

Class Method Details

.honor(report) ⇒ Object



151
152
153
154
155
156
157
# File 'lib/metz_scan/commands/scan/runner.rb', line 151

def honor(report)
  store = ProjectConfigScope.store
  files = Array(report["files"]).map { |file| reject_scoped_off(store, file) }
  recount(report.merge("files" => files))
rescue RuboCop::Error, Psych::Exception
  report
end

.recount(report) ⇒ Object



172
173
174
175
176
177
# File 'lib/metz_scan/commands/scan/runner.rb', line 172

def recount(report)
  return report unless report["summary"]

  count = Array(report["files"]).sum { |file| Array(file["offenses"]).size }
  report.merge("summary" => report["summary"].merge("offense_count" => count))
end

.reject_scoped_off(store, file) ⇒ Object



159
160
161
162
163
# File 'lib/metz_scan/commands/scan/runner.rb', line 159

def reject_scoped_off(store, file)
  absolute = File.expand_path(file.fetch("path"))
  kept = Array(file["offenses"]).reject { |o| scoped_off?(store, o.fetch("cop_name"), absolute) }
  file.merge("offenses" => kept)
end

.scoped_off?(store, cop_name, absolute_path) ⇒ Boolean

Returns:

  • (Boolean)


165
166
167
168
169
170
# File 'lib/metz_scan/commands/scan/runner.rb', line 165

def scoped_off?(store, cop_name, absolute_path)
  cop_class = RuboCop::Cop::Registry.global.find_by_cop_name(cop_name)
  return false unless cop_class

  cop_class.new(store.for_file(absolute_path)).excluded_file?(absolute_path)
end