class PmdTester::PmdViolation

This class represents a 'violation' element of Pmd xml report and which pmd branch the 'violation' is from

Attributes

branch[R]

The pmd branch type, 'base' or 'patch'

fname[R]

The schema of 'violation' element: <xs:complexType name=“violation”>

<xs:simpleContent>
  <xs:extension base="xs:string">
    <xs:attribute name="beginline" type="xs:integer" use="required" />
    <xs:attribute name="endline" type="xs:integer" use="required" />
    <xs:attribute name="begincolumn" type="xs:integer" use="required" />
    <xs:attribute name="endcolumn" type="xs:integer" use="required" />
    <xs:attribute name="rule" type="xs:string" use="required" />
    <xs:attribute name="ruleset" type="xs:string" use="required" />
    <xs:attribute name="package" type="xs:string" use="optional" />
    <xs:attribute name="class" type="xs:string" use="optional" />
    <xs:attribute name="method" type="xs:string" use="optional" />
    <xs:attribute name="variable" type="xs:string" use="optional" />
    <xs:attribute name="externalInfoUrl" type="xs:string" use="optional" />
    <xs:attribute name="priority" type="xs:string" use="required" />
  </xs:extension>
</xs:simpleContent>

</xs:complexType>

info_url[R]

The schema of 'violation' element: <xs:complexType name=“violation”>

<xs:simpleContent>
  <xs:extension base="xs:string">
    <xs:attribute name="beginline" type="xs:integer" use="required" />
    <xs:attribute name="endline" type="xs:integer" use="required" />
    <xs:attribute name="begincolumn" type="xs:integer" use="required" />
    <xs:attribute name="endcolumn" type="xs:integer" use="required" />
    <xs:attribute name="rule" type="xs:string" use="required" />
    <xs:attribute name="ruleset" type="xs:string" use="required" />
    <xs:attribute name="package" type="xs:string" use="optional" />
    <xs:attribute name="class" type="xs:string" use="optional" />
    <xs:attribute name="method" type="xs:string" use="optional" />
    <xs:attribute name="variable" type="xs:string" use="optional" />
    <xs:attribute name="externalInfoUrl" type="xs:string" use="optional" />
    <xs:attribute name="priority" type="xs:string" use="required" />
  </xs:extension>
</xs:simpleContent>

</xs:complexType>

line[R]

The schema of 'violation' element: <xs:complexType name=“violation”>

<xs:simpleContent>
  <xs:extension base="xs:string">
    <xs:attribute name="beginline" type="xs:integer" use="required" />
    <xs:attribute name="endline" type="xs:integer" use="required" />
    <xs:attribute name="begincolumn" type="xs:integer" use="required" />
    <xs:attribute name="endcolumn" type="xs:integer" use="required" />
    <xs:attribute name="rule" type="xs:string" use="required" />
    <xs:attribute name="ruleset" type="xs:string" use="required" />
    <xs:attribute name="package" type="xs:string" use="optional" />
    <xs:attribute name="class" type="xs:string" use="optional" />
    <xs:attribute name="method" type="xs:string" use="optional" />
    <xs:attribute name="variable" type="xs:string" use="optional" />
    <xs:attribute name="externalInfoUrl" type="xs:string" use="optional" />
    <xs:attribute name="priority" type="xs:string" use="required" />
  </xs:extension>
</xs:simpleContent>

</xs:complexType>

message[RW]
old_line[R]

The schema of 'violation' element: <xs:complexType name=“violation”>

<xs:simpleContent>
  <xs:extension base="xs:string">
    <xs:attribute name="beginline" type="xs:integer" use="required" />
    <xs:attribute name="endline" type="xs:integer" use="required" />
    <xs:attribute name="begincolumn" type="xs:integer" use="required" />
    <xs:attribute name="endcolumn" type="xs:integer" use="required" />
    <xs:attribute name="rule" type="xs:string" use="required" />
    <xs:attribute name="ruleset" type="xs:string" use="required" />
    <xs:attribute name="package" type="xs:string" use="optional" />
    <xs:attribute name="class" type="xs:string" use="optional" />
    <xs:attribute name="method" type="xs:string" use="optional" />
    <xs:attribute name="variable" type="xs:string" use="optional" />
    <xs:attribute name="externalInfoUrl" type="xs:string" use="optional" />
    <xs:attribute name="priority" type="xs:string" use="required" />
  </xs:extension>
</xs:simpleContent>

</xs:complexType>

old_message[R]

The schema of 'violation' element: <xs:complexType name=“violation”>

<xs:simpleContent>
  <xs:extension base="xs:string">
    <xs:attribute name="beginline" type="xs:integer" use="required" />
    <xs:attribute name="endline" type="xs:integer" use="required" />
    <xs:attribute name="begincolumn" type="xs:integer" use="required" />
    <xs:attribute name="endcolumn" type="xs:integer" use="required" />
    <xs:attribute name="rule" type="xs:string" use="required" />
    <xs:attribute name="ruleset" type="xs:string" use="required" />
    <xs:attribute name="package" type="xs:string" use="optional" />
    <xs:attribute name="class" type="xs:string" use="optional" />
    <xs:attribute name="method" type="xs:string" use="optional" />
    <xs:attribute name="variable" type="xs:string" use="optional" />
    <xs:attribute name="externalInfoUrl" type="xs:string" use="optional" />
    <xs:attribute name="priority" type="xs:string" use="required" />
  </xs:extension>
</xs:simpleContent>

</xs:complexType>

rule_name[R]

The schema of 'violation' element: <xs:complexType name=“violation”>

<xs:simpleContent>
  <xs:extension base="xs:string">
    <xs:attribute name="beginline" type="xs:integer" use="required" />
    <xs:attribute name="endline" type="xs:integer" use="required" />
    <xs:attribute name="begincolumn" type="xs:integer" use="required" />
    <xs:attribute name="endcolumn" type="xs:integer" use="required" />
    <xs:attribute name="rule" type="xs:string" use="required" />
    <xs:attribute name="ruleset" type="xs:string" use="required" />
    <xs:attribute name="package" type="xs:string" use="optional" />
    <xs:attribute name="class" type="xs:string" use="optional" />
    <xs:attribute name="method" type="xs:string" use="optional" />
    <xs:attribute name="variable" type="xs:string" use="optional" />
    <xs:attribute name="externalInfoUrl" type="xs:string" use="optional" />
    <xs:attribute name="priority" type="xs:string" use="required" />
  </xs:extension>
</xs:simpleContent>

</xs:complexType>

ruleset_name[R]

The schema of 'violation' element: <xs:complexType name=“violation”>

<xs:simpleContent>
  <xs:extension base="xs:string">
    <xs:attribute name="beginline" type="xs:integer" use="required" />
    <xs:attribute name="endline" type="xs:integer" use="required" />
    <xs:attribute name="begincolumn" type="xs:integer" use="required" />
    <xs:attribute name="endcolumn" type="xs:integer" use="required" />
    <xs:attribute name="rule" type="xs:string" use="required" />
    <xs:attribute name="ruleset" type="xs:string" use="required" />
    <xs:attribute name="package" type="xs:string" use="optional" />
    <xs:attribute name="class" type="xs:string" use="optional" />
    <xs:attribute name="method" type="xs:string" use="optional" />
    <xs:attribute name="variable" type="xs:string" use="optional" />
    <xs:attribute name="externalInfoUrl" type="xs:string" use="optional" />
    <xs:attribute name="priority" type="xs:string" use="required" />
  </xs:extension>
</xs:simpleContent>

</xs:complexType>

Public Class Methods

new(branch:, fname:, info_url:, bline:, rule_name:, ruleset_name:) click to toggle source

rubocop:disable Metrics/ParameterLists Disable it: how is replacing a long parameter list with a single hash helping?

# File lib/pmdtester/pmd_violation.rb, line 35
def initialize(branch:, fname:, info_url:, bline:, rule_name:, ruleset_name:)
  @branch = branch
  @fname = fname
  @message = ''

  @info_url = info_url
  @line = bline
  @rule_name = rule_name

  @ruleset_name = ruleset_name

  @changed = false
  @old_message = nil
  @old_line = nil
end

Public Instance Methods

added?() click to toggle source

only makes sense if this is a diff

# File lib/pmdtester/pmd_violation.rb, line 70
def added?
  branch != BASE && !changed?
end
changed?() click to toggle source

only makes sense if this is a diff

# File lib/pmdtester/pmd_violation.rb, line 75
def changed?
  @changed
end
eql?(other) click to toggle source
# File lib/pmdtester/pmd_violation.rb, line 88
def eql?(other)
  rule_name.eql?(other.rule_name) &&
    line.eql?(other.line) &&
    fname.eql?(other.fname) &&
    message.eql?(other.message)
end
hash() click to toggle source
# File lib/pmdtester/pmd_violation.rb, line 95
def hash
  [line, rule_name, message].hash
end
line_move?(other) click to toggle source

rubocop:enable Metrics/ParameterLists

# File lib/pmdtester/pmd_violation.rb, line 52
def line_move?(other)
  message.eql?(other.message) && (line - other.line).abs <= 5
end
removed?() click to toggle source

only makes sense if this is a diff

# File lib/pmdtester/pmd_violation.rb, line 80
def removed?
  branch == BASE
end
sort_key() click to toggle source
# File lib/pmdtester/pmd_violation.rb, line 84
def sort_key
  line
end
to_liquid() click to toggle source
# File lib/pmdtester/pmd_violation.rb, line 99
def to_liquid
  {
    'branch' => branch,
    'changed' => changed?
  }
end
try_merge?(other) click to toggle source
# File lib/pmdtester/pmd_violation.rb, line 56
def try_merge?(other)
  if branch != BASE && branch != other.branch && rule_name == other.rule_name &&
     !changed? && # not already changed
     (line == other.line || line_move?(other))
    @changed = true
    @old_message = other.message
    @old_line = other.line
    true
  else
    false
  end
end