Class: Audition::Finding

Inherits:
Data
  • Object
show all
Defined in:
lib/audition/finding.rb

Overview

One diagnosed problem: what was found (message), the Ractor rule it violates (why), what to write instead (fix), where (path/line/source), and optionally a machine-applicable Autofix. Produced by static checks, the graph audit, and the dynamic prober alike.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source: nil, autofix: nil, dependency: false, test: false, subject: nil, **rest) ⇒ Finding

Returns a new instance of Finding.



77
78
79
80
# File 'lib/audition/finding.rb', line 77

def initialize(source: nil, autofix: nil, dependency: false,
  test: false, subject: nil, **rest)
  super
end

Instance Attribute Details

#autofix ⇒ Autofix? (readonly)

Returns machine-applicable correction.

Returns:

  • (Autofix, nil) —

    machine-applicable correction



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/audition/finding.rb', line 73

Finding = Data.define(
  :check, :severity, :message, :why, :fix,
  :path, :line, :source, :autofix, :dependency, :test, :subject
) do
  def initialize(source: nil, autofix: nil, dependency: false,
    test: false, subject: nil, **rest)
    super
  end

  # @return [Boolean] whether severity is `:error`
  def error? = severity == :error

  # True when the problem lives in a dependency's source, not the
  # audited target: real, but not the target's bug to fix.
  #
  # @return [Boolean]
  def dependency? = dependency

  # True when the problem lives in the target's test or spec
  # code: real, but never loaded by the production boot.
  #
  # @return [Boolean]
  def test? = test

  # @return [Boolean] whether an {Autofix} is attached
  def fixable? = !autofix.nil?

  # @return [Integer] rank from {SEVERITIES}, higher is worse
  def severity_rank = SEVERITIES.fetch(severity)

  # @return [String] "path:line", or just the path label
  def location = line ? "#{path}:#{line}" : path
end

#check ⇒ String (readonly)

Returns kebab-case check identifier.

Returns:

  • (String) —

    kebab-case check identifier



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/audition/finding.rb', line 73

Finding = Data.define(
  :check, :severity, :message, :why, :fix,
  :path, :line, :source, :autofix, :dependency, :test, :subject
) do
  def initialize(source: nil, autofix: nil, dependency: false,
    test: false, subject: nil, **rest)
    super
  end

  # @return [Boolean] whether severity is `:error`
  def error? = severity == :error

  # True when the problem lives in a dependency's source, not the
  # audited target: real, but not the target's bug to fix.
  #
  # @return [Boolean]
  def dependency? = dependency

  # True when the problem lives in the target's test or spec
  # code: real, but never loaded by the production boot.
  #
  # @return [Boolean]
  def test? = test

  # @return [Boolean] whether an {Autofix} is attached
  def fixable? = !autofix.nil?

  # @return [Integer] rank from {SEVERITIES}, higher is worse
  def severity_rank = SEVERITIES.fetch(severity)

  # @return [String] "path:line", or just the path label
  def location = line ? "#{path}:#{line}" : path
end

#dependency ⇒ Boolean (readonly)

Returns see #dependency?.

Returns:



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/audition/finding.rb', line 73

Finding = Data.define(
  :check, :severity, :message, :why, :fix,
  :path, :line, :source, :autofix, :dependency, :test, :subject
) do
  def initialize(source: nil, autofix: nil, dependency: false,
    test: false, subject: nil, **rest)
    super
  end

  # @return [Boolean] whether severity is `:error`
  def error? = severity == :error

  # True when the problem lives in a dependency's source, not the
  # audited target: real, but not the target's bug to fix.
  #
  # @return [Boolean]
  def dependency? = dependency

  # True when the problem lives in the target's test or spec
  # code: real, but never loaded by the production boot.
  #
  # @return [Boolean]
  def test? = test

  # @return [Boolean] whether an {Autofix} is attached
  def fixable? = !autofix.nil?

  # @return [Integer] rank from {SEVERITIES}, higher is worse
  def severity_rank = SEVERITIES.fetch(severity)

  # @return [String] "path:line", or just the path label
  def location = line ? "#{path}:#{line}" : path
end

#fix ⇒ String (readonly)

Returns suggested remediation.

Returns:

  • (String) —

    suggested remediation



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/audition/finding.rb', line 73

Finding = Data.define(
  :check, :severity, :message, :why, :fix,
  :path, :line, :source, :autofix, :dependency, :test, :subject
) do
  def initialize(source: nil, autofix: nil, dependency: false,
    test: false, subject: nil, **rest)
    super
  end

  # @return [Boolean] whether severity is `:error`
  def error? = severity == :error

  # True when the problem lives in a dependency's source, not the
  # audited target: real, but not the target's bug to fix.
  #
  # @return [Boolean]
  def dependency? = dependency

  # True when the problem lives in the target's test or spec
  # code: real, but never loaded by the production boot.
  #
  # @return [Boolean]
  def test? = test

  # @return [Boolean] whether an {Autofix} is attached
  def fixable? = !autofix.nil?

  # @return [Integer] rank from {SEVERITIES}, higher is worse
  def severity_rank = SEVERITIES.fetch(severity)

  # @return [String] "path:line", or just the path label
  def location = line ? "#{path}:#{line}" : path
end

#line ⇒ Integer? (readonly)

Returns 1-based line, nil for whole-target.

Returns:

  • (Integer, nil) —

    1-based line, nil for whole-target



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/audition/finding.rb', line 73

Finding = Data.define(
  :check, :severity, :message, :why, :fix,
  :path, :line, :source, :autofix, :dependency, :test, :subject
) do
  def initialize(source: nil, autofix: nil, dependency: false,
    test: false, subject: nil, **rest)
    super
  end

  # @return [Boolean] whether severity is `:error`
  def error? = severity == :error

  # True when the problem lives in a dependency's source, not the
  # audited target: real, but not the target's bug to fix.
  #
  # @return [Boolean]
  def dependency? = dependency

  # True when the problem lives in the target's test or spec
  # code: real, but never loaded by the production boot.
  #
  # @return [Boolean]
  def test? = test

  # @return [Boolean] whether an {Autofix} is attached
  def fixable? = !autofix.nil?

  # @return [Integer] rank from {SEVERITIES}, higher is worse
  def severity_rank = SEVERITIES.fetch(severity)

  # @return [String] "path:line", or just the path label
  def location = line ? "#{path}:#{line}" : path
end

#message ⇒ String (readonly)

Returns one-line statement of the problem.

Returns:

  • (String) —

    one-line statement of the problem



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/audition/finding.rb', line 73

Finding = Data.define(
  :check, :severity, :message, :why, :fix,
  :path, :line, :source, :autofix, :dependency, :test, :subject
) do
  def initialize(source: nil, autofix: nil, dependency: false,
    test: false, subject: nil, **rest)
    super
  end

  # @return [Boolean] whether severity is `:error`
  def error? = severity == :error

  # True when the problem lives in a dependency's source, not the
  # audited target: real, but not the target's bug to fix.
  #
  # @return [Boolean]
  def dependency? = dependency

  # True when the problem lives in the target's test or spec
  # code: real, but never loaded by the production boot.
  #
  # @return [Boolean]
  def test? = test

  # @return [Boolean] whether an {Autofix} is attached
  def fixable? = !autofix.nil?

  # @return [Integer] rank from {SEVERITIES}, higher is worse
  def severity_rank = SEVERITIES.fetch(severity)

  # @return [String] "path:line", or just the path label
  def location = line ? "#{path}:#{line}" : path
end

#path ⇒ String (readonly)

Returns file path, or a label for runtime findings.

Returns:

  • (String) —

    file path, or a label for runtime findings



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/audition/finding.rb', line 73

Finding = Data.define(
  :check, :severity, :message, :why, :fix,
  :path, :line, :source, :autofix, :dependency, :test, :subject
) do
  def initialize(source: nil, autofix: nil, dependency: false,
    test: false, subject: nil, **rest)
    super
  end

  # @return [Boolean] whether severity is `:error`
  def error? = severity == :error

  # True when the problem lives in a dependency's source, not the
  # audited target: real, but not the target's bug to fix.
  #
  # @return [Boolean]
  def dependency? = dependency

  # True when the problem lives in the target's test or spec
  # code: real, but never loaded by the production boot.
  #
  # @return [Boolean]
  def test? = test

  # @return [Boolean] whether an {Autofix} is attached
  def fixable? = !autofix.nil?

  # @return [Integer] rank from {SEVERITIES}, higher is worse
  def severity_rank = SEVERITIES.fetch(severity)

  # @return [String] "path:line", or just the path label
  def location = line ? "#{path}:#{line}" : path
end

#severity ⇒ Symbol (readonly)

Returns :error, :warning, or :info.

Returns:

  • (Symbol) —

    :error, :warning, or :info



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/audition/finding.rb', line 73

Finding = Data.define(
  :check, :severity, :message, :why, :fix,
  :path, :line, :source, :autofix, :dependency, :test, :subject
) do
  def initialize(source: nil, autofix: nil, dependency: false,
    test: false, subject: nil, **rest)
    super
  end

  # @return [Boolean] whether severity is `:error`
  def error? = severity == :error

  # True when the problem lives in a dependency's source, not the
  # audited target: real, but not the target's bug to fix.
  #
  # @return [Boolean]
  def dependency? = dependency

  # True when the problem lives in the target's test or spec
  # code: real, but never loaded by the production boot.
  #
  # @return [Boolean]
  def test? = test

  # @return [Boolean] whether an {Autofix} is attached
  def fixable? = !autofix.nil?

  # @return [Integer] rank from {SEVERITIES}, higher is worse
  def severity_rank = SEVERITIES.fetch(severity)

  # @return [String] "path:line", or just the path label
  def location = line ? "#{path}:#{line}" : path
end

#source ⇒ String? (readonly)

Returns the offending source line, stripped.

Returns:

  • (String, nil) —

    the offending source line, stripped



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/audition/finding.rb', line 73

Finding = Data.define(
  :check, :severity, :message, :why, :fix,
  :path, :line, :source, :autofix, :dependency, :test, :subject
) do
  def initialize(source: nil, autofix: nil, dependency: false,
    test: false, subject: nil, **rest)
    super
  end

  # @return [Boolean] whether severity is `:error`
  def error? = severity == :error

  # True when the problem lives in a dependency's source, not the
  # audited target: real, but not the target's bug to fix.
  #
  # @return [Boolean]
  def dependency? = dependency

  # True when the problem lives in the target's test or spec
  # code: real, but never loaded by the production boot.
  #
  # @return [Boolean]
  def test? = test

  # @return [Boolean] whether an {Autofix} is attached
  def fixable? = !autofix.nil?

  # @return [Integer] rank from {SEVERITIES}, higher is worse
  def severity_rank = SEVERITIES.fetch(severity)

  # @return [String] "path:line", or just the path label
  def location = line ? "#{path}:#{line}" : path
end

#subject ⇒ String? (readonly)

Returns the object a finding is about, in a form the dynamic probe can match ("Owner/@ivar"), so a runtime proof of shareability can retire the static guess.

Returns:

  • (String, nil) —

    the object a finding is about, in a form the dynamic probe can match ("Owner/@ivar"), so a runtime proof of shareability can retire the static guess



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/audition/finding.rb', line 73

Finding = Data.define(
  :check, :severity, :message, :why, :fix,
  :path, :line, :source, :autofix, :dependency, :test, :subject
) do
  def initialize(source: nil, autofix: nil, dependency: false,
    test: false, subject: nil, **rest)
    super
  end

  # @return [Boolean] whether severity is `:error`
  def error? = severity == :error

  # True when the problem lives in a dependency's source, not the
  # audited target: real, but not the target's bug to fix.
  #
  # @return [Boolean]
  def dependency? = dependency

  # True when the problem lives in the target's test or spec
  # code: real, but never loaded by the production boot.
  #
  # @return [Boolean]
  def test? = test

  # @return [Boolean] whether an {Autofix} is attached
  def fixable? = !autofix.nil?

  # @return [Integer] rank from {SEVERITIES}, higher is worse
  def severity_rank = SEVERITIES.fetch(severity)

  # @return [String] "path:line", or just the path label
  def location = line ? "#{path}:#{line}" : path
end

#test ⇒ Boolean (readonly)

Returns see #test?.

Returns:



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/audition/finding.rb', line 73

Finding = Data.define(
  :check, :severity, :message, :why, :fix,
  :path, :line, :source, :autofix, :dependency, :test, :subject
) do
  def initialize(source: nil, autofix: nil, dependency: false,
    test: false, subject: nil, **rest)
    super
  end

  # @return [Boolean] whether severity is `:error`
  def error? = severity == :error

  # True when the problem lives in a dependency's source, not the
  # audited target: real, but not the target's bug to fix.
  #
  # @return [Boolean]
  def dependency? = dependency

  # True when the problem lives in the target's test or spec
  # code: real, but never loaded by the production boot.
  #
  # @return [Boolean]
  def test? = test

  # @return [Boolean] whether an {Autofix} is attached
  def fixable? = !autofix.nil?

  # @return [Integer] rank from {SEVERITIES}, higher is worse
  def severity_rank = SEVERITIES.fetch(severity)

  # @return [String] "path:line", or just the path label
  def location = line ? "#{path}:#{line}" : path
end

#why ⇒ String (readonly)

Returns the Ractor rule behind the finding.

Returns:

  • (String) —

    the Ractor rule behind the finding



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/audition/finding.rb', line 73

Finding = Data.define(
  :check, :severity, :message, :why, :fix,
  :path, :line, :source, :autofix, :dependency, :test, :subject
) do
  def initialize(source: nil, autofix: nil, dependency: false,
    test: false, subject: nil, **rest)
    super
  end

  # @return [Boolean] whether severity is `:error`
  def error? = severity == :error

  # True when the problem lives in a dependency's source, not the
  # audited target: real, but not the target's bug to fix.
  #
  # @return [Boolean]
  def dependency? = dependency

  # True when the problem lives in the target's test or spec
  # code: real, but never loaded by the production boot.
  #
  # @return [Boolean]
  def test? = test

  # @return [Boolean] whether an {Autofix} is attached
  def fixable? = !autofix.nil?

  # @return [Integer] rank from {SEVERITIES}, higher is worse
  def severity_rank = SEVERITIES.fetch(severity)

  # @return [String] "path:line", or just the path label
  def location = line ? "#{path}:#{line}" : path
end

Instance Method Details

#dependency? ⇒ Boolean

True when the problem lives in a dependency's source, not the audited target: real, but not the target's bug to fix.

Returns:

  • (Boolean)


89
# File 'lib/audition/finding.rb', line 89

def dependency? = dependency

#error? ⇒ Boolean

Returns whether severity is :error.

Returns:

  • (Boolean) —

    whether severity is :error



83
# File 'lib/audition/finding.rb', line 83

def error? = severity == :error

#fixable? ⇒ Boolean

Returns whether an Autofix is attached.

Returns:

  • (Boolean) —

    whether an Autofix is attached



98
# File 'lib/audition/finding.rb', line 98

def fixable? = !autofix.nil?

#location ⇒ String

Returns "path:line", or just the path label.

Returns:

  • (String) —

    "path:line", or just the path label



104
# File 'lib/audition/finding.rb', line 104

def location = line ? "#{path}:#{line}" : path

#severity_rank ⇒ Integer

Returns rank from SEVERITIES, higher is worse.

Returns:

  • (Integer) —

    rank from SEVERITIES, higher is worse



101
# File 'lib/audition/finding.rb', line 101

def severity_rank = SEVERITIES.fetch(severity)

#test? ⇒ Boolean

True when the problem lives in the target's test or spec code: real, but never loaded by the production boot.

Returns:

  • (Boolean)


95
# File 'lib/audition/finding.rb', line 95

def test? = test