Class: Ace::Lint::Models::LintResult

Inherits:
Struct
  • Object
show all
Defined in:
lib/ace/lint/models/lint_result.rb

Overview

Represents the validation result for a single file

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_path:, success: true, errors: [], warnings: [], formatted: false, skipped: false, skip_reason: "Unsupported file type", runner: nil) ⇒ LintResult

Returns a new instance of LintResult.



18
19
20
# File 'lib/ace/lint/models/lint_result.rb', line 18

def initialize(file_path:, success: true, errors: [], warnings: [], formatted: false, skipped: false, skip_reason: "Unsupported file type", runner: nil)
  super
end

Instance Attribute Details

#errorsArray<ValidationError>

List of errors

Returns:



17
18
19
# File 'lib/ace/lint/models/lint_result.rb', line 17

def errors
  @errors
end

#file_pathString

Path to the validated file

Returns:

  • (String)

    the current value of file_path



17
18
19
# File 'lib/ace/lint/models/lint_result.rb', line 17

def file_path
  @file_path
end

#formattedBoolean

Whether file was formatted

Returns:

  • (Boolean)

    the current value of formatted



17
18
19
# File 'lib/ace/lint/models/lint_result.rb', line 17

def formatted
  @formatted
end

#runnerSymbol

Which linter was used (:standardrb, :rubocop, nil)

Returns:

  • (Symbol)

    the current value of runner



17
18
19
# File 'lib/ace/lint/models/lint_result.rb', line 17

def runner
  @runner
end

#skip_reasonString

Reason for skipping (when skipped is true)

Returns:

  • (String)

    the current value of skip_reason



17
18
19
# File 'lib/ace/lint/models/lint_result.rb', line 17

def skip_reason
  @skip_reason
end

#skippedBoolean

Whether file was skipped (unsupported type)

Returns:

  • (Boolean)

    the current value of skipped



17
18
19
# File 'lib/ace/lint/models/lint_result.rb', line 17

def skipped
  @skipped
end

#successBoolean

Whether validation passed

Returns:

  • (Boolean)

    the current value of success



17
18
19
# File 'lib/ace/lint/models/lint_result.rb', line 17

def success
  @success
end

#warningsArray<ValidationError>

List of warnings

Returns:



17
18
19
# File 'lib/ace/lint/models/lint_result.rb', line 17

def warnings
  @warnings
end

Class Method Details

.skipped(file_path:, reason: "Unsupported file type") ⇒ LintResult

Factory method for skipped results

Parameters:

  • file_path (String)

    Path to the skipped file

  • reason (String) (defaults to: "Unsupported file type")

    Reason for skipping

Returns:



58
59
60
61
62
63
64
65
66
67
68
# File 'lib/ace/lint/models/lint_result.rb', line 58

def self.skipped(file_path:, reason: "Unsupported file type")
  new(
    file_path: file_path,
    success: true,
    errors: [],
    warnings: [],
    formatted: false,
    skipped: true,
    skip_reason: reason
  )
end

Instance Method Details

#error_countObject



46
47
48
# File 'lib/ace/lint/models/lint_result.rb', line 46

def error_count
  errors.size
end

#failed?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/ace/lint/models/lint_result.rb', line 26

def failed?
  !success && !skipped
end

#formatted?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/ace/lint/models/lint_result.rb', line 30

def formatted?
  formatted
end

#has_errors?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/ace/lint/models/lint_result.rb', line 38

def has_errors?
  errors.any?
end

#has_warnings?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/ace/lint/models/lint_result.rb', line 42

def has_warnings?
  warnings.any?
end

#skipped?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/ace/lint/models/lint_result.rb', line 34

def skipped?
  skipped
end

#success?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/ace/lint/models/lint_result.rb', line 22

def success?
  success
end

#to_hHash

Convert result to hash for JSON serialization

Returns:

  • (Hash)

    Result as hash



72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/ace/lint/models/lint_result.rb', line 72

def to_h
  {
    file_path: file_path,
    success: success,
    errors: errors.map(&:to_h),
    warnings: warnings.map(&:to_h),
    formatted: formatted,
    runner: runner,
    skipped: skipped,
    skip_reason: skip_reason
  }
end

#warning_countObject



50
51
52
# File 'lib/ace/lint/models/lint_result.rb', line 50

def warning_count
  warnings.size
end