Class: SpecGuard::RSpec::Linter::Result

Inherits:
Data
  • Object
show all
Defined in:
lib/specguard/rspec/linter.rb

Overview

One annotation's verdict. problem is set when discovery could not produce an intent at all; reasons when the schema rejected one. They are mutually exclusive by construction.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file:, line:, kind: nil, problem: nil, reasons: []) ⇒ Result

Returns a new instance of Result.



74
75
76
# File 'lib/specguard/rspec/linter.rb', line 74

def initialize(file:, line:, kind: nil, problem: nil, reasons: [])
  super
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file

Returns:

  • (Object)

    the current value of file



73
74
75
# File 'lib/specguard/rspec/linter.rb', line 73

def file
  @file
end

#kindObject (readonly)

Returns the value of attribute kind

Returns:

  • (Object)

    the current value of kind



73
74
75
# File 'lib/specguard/rspec/linter.rb', line 73

def kind
  @kind
end

#lineObject (readonly)

Returns the value of attribute line

Returns:

  • (Object)

    the current value of line



73
74
75
# File 'lib/specguard/rspec/linter.rb', line 73

def line
  @line
end

#problemObject (readonly)

Returns the value of attribute problem

Returns:

  • (Object)

    the current value of problem



73
74
75
# File 'lib/specguard/rspec/linter.rb', line 73

def problem
  @problem
end

#reasonsObject (readonly)

Returns the value of attribute reasons

Returns:

  • (Object)

    the current value of reasons



73
74
75
# File 'lib/specguard/rspec/linter.rb', line 73

def reasons
  @reasons
end

Instance Method Details

#failed?Boolean

Returns:

  • (Boolean)


82
83
84
# File 'lib/specguard/rspec/linter.rb', line 82

def failed?
  !ok?
end

#line_scoped?Boolean

A read failure is not line-scoped: nothing in the file was ever seen, and slice 1's line is a 0 sentinel rather than a location. The reference drops the line for exactly these findings (bin/validate-intent:521 — "when a finding is not line-scoped ... kind is null"), and :0 is not somewhere a reader can go: anything parsing file:line — CI annotations, editor quickfix, review comments — would point at a line that does not exist.

This is what makes kind load-bearing rather than decorative.

The rule is a predicate rather than an inline comparison because it now has two renderers: CLI#report_failure prints file instead of file:0, and JSONReporter emits "line": null for the same findings. Spelling kind == Finding::KIND_READ in both would let one of them keep emitting the sentinel after the rule changed here.

Returns:

  • (Boolean)


101
102
103
# File 'lib/specguard/rspec/linter.rb', line 101

def line_scoped?
  kind != Finding::KIND_READ
end

#locationObject



105
106
107
# File 'lib/specguard/rspec/linter.rb', line 105

def location
  line_scoped? ? "#{file}:#{line}" : file
end

#ok?Boolean

Returns:

  • (Boolean)


78
79
80
# File 'lib/specguard/rspec/linter.rb', line 78

def ok?
  problem.nil? && reasons.empty?
end