Class: Stellwerk::Commands::Check

Inherits:
Object
  • Object
show all
Defined in:
lib/stellwerk/commands/check.rb

Instance Method Summary collapse

Constructor Details

#initialize(root_path, autoloaders: nil) ⇒ Check

Returns a new instance of Check.



13
14
15
16
# File 'lib/stellwerk/commands/check.rb', line 13

def initialize(root_path, autoloaders: nil)
  @root_path = Pathname.new(root_path)
  @autoloaders = autoloaders || fake_autoloaders
end

Instance Method Details

#runObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/stellwerk/commands/check.rb', line 18

def run
  puts "running check..."
  config = Stellwerk::Config.new(@root_path.join("stellwerk.yml"))

  # build graph using reference_extractor
  extractor = ReferenceExtractor::Extractor.new(
    autoloaders: @autoloaders,
    root_path: @root_path
  )

  all_files = Stellwerk::SourceFileCollector.new(@root_path).call
  puts "collected #{all_files.length} files"

  before = Time.now
  edgelist = Parallel.flat_map(all_files, in_processes: Parallel.processor_count - 1) do |file|
    extractor.references_from_file(file)
  end
  puts "extracted #{edgelist.length} references in #{(Time.now - before).round(2)} seconds"

  # check rules against graph, collect violations
  puts "checking rules..."
  violations = config.rules.flat_map do |rule|
    rule.find_violations(edgelist)
  end

  Stellwerk::Printer.new(violations).print

  violations
end