Class: Reviewer::Runner::FailedFiles

Inherits:
Object
  • Object
show all
Defined in:
lib/reviewer/runner/failed_files.rb

Overview

Extracts file paths from tool output so that subsequent re-runs can be scoped to only the files that had issues.

Merges stdout and stderr before scanning because linters (rubocop, reek, etc.) write findings to stdout, not stderr. No common tool splits output with “passing files” on stdout and “failing files” on stderr, so merging is safe. The regex pattern and File.exist? guard filter out any incidental matches.

Constant Summary collapse

FILE_PATH_PATTERN =

Matches relative path-like tokens at or near the start of a line, allowing leading whitespace for tools that indent output (reek groupings, rspec nesting). Rejects absolute paths (starting with /) to exclude Ruby runtime warnings and gem internals that would otherwise match. Tool findings always use relative paths from the project root. Supports any file extension so non-Ruby tools (eslint, stylelint) also work. File.exist? in to_a provides a final guard.

lib/foo.rb:45:3: C: Style/... (rubocop)
test/foo_test.rb:45 (minitest)
lib/foo.rb -- message (reek)
src/app.js:10:5: error ... (eslint)
%r{^\s*([^/\s]\S*\.\w+)(?::\d| -- )}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stdout, stderr) ⇒ FailedFiles

Creates a failed-file extractor from captured tool output

Parameters:

  • stdout (String, nil)

    captured standard output from the tool

  • stderr (String, nil)

    captured standard error from the tool



33
34
35
36
# File 'lib/reviewer/runner/failed_files.rb', line 33

def initialize(stdout, stderr)
  @stdout = stdout
  @stderr = stderr
end

Instance Attribute Details

#stderrObject (readonly)

Returns the value of attribute stderr.



26
27
28
# File 'lib/reviewer/runner/failed_files.rb', line 26

def stderr
  @stderr
end

#stdoutObject (readonly)

Returns the value of attribute stdout.



26
27
28
# File 'lib/reviewer/runner/failed_files.rb', line 26

def stdout
  @stdout
end

Instance Method Details

#matched_pathsArray<String>

All regex-matched paths before filesystem filtering. Useful for testing pattern matching without requiring real files on disk.

Returns:

  • (Array<String>)

    raw paths extracted from combined output



47
48
49
# File 'lib/reviewer/runner/failed_files.rb', line 47

def matched_paths
  combined_output.scan(FILE_PATH_PATTERN).flatten
end

#to_aArray<String>

Regex-matched paths filtered to only those that exist on disk, deduplicated.

Returns:

  • (Array<String>)

    unique file paths that exist in the working directory



40
41
42
# File 'lib/reviewer/runner/failed_files.rb', line 40

def to_a
  matched_paths.select { |path| File.exist?(path) }.uniq
end