Class: PmdTester::PmdViolation
- Inherits:
-
Object
- Object
- PmdTester::PmdViolation
- Defined in:
- lib/pmdtester/pmd_violation.rb
Overview
This class represents a ‘violation’ element of Pmd xml report and which pmd branch the ‘violation’ is from
Instance Attribute Summary collapse
-
#branch ⇒ Object
readonly
The pmd branch type, ‘base’ or ‘patch’.
-
#fname ⇒ Object
readonly
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 ⇒ Object
readonly
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>.
-
#language ⇒ Object
readonly
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 ⇒ Object
readonly
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 ⇒ Object
Returns the value of attribute message.
-
#old_line ⇒ Object
readonly
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 ⇒ Object
readonly
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 ⇒ Object
readonly
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 ⇒ Object
readonly
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>.
Instance Method Summary collapse
-
#added? ⇒ Boolean
only makes sense if this is a diff.
-
#changed? ⇒ Boolean
only makes sense if this is a diff.
- #eql?(other) ⇒ Boolean
- #hash ⇒ Object
-
#initialize(branch:, fname:, info_url:, bline:, rule_name:, ruleset_name:) ⇒ PmdViolation
constructor
A new instance of PmdViolation.
- #line_move?(other) ⇒ Boolean
-
#removed? ⇒ Boolean
only makes sense if this is a diff.
- #sort_key ⇒ Object
- #to_liquid ⇒ Object
- #try_merge?(other) ⇒ Boolean
Constructor Details
#initialize(branch:, fname:, info_url:, bline:, rule_name:, ruleset_name:) ⇒ PmdViolation
Returns a new instance of PmdViolation.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/pmdtester/pmd_violation.rb', line 33 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 @language = determine_language_from_info_url @changed = false @old_message = nil @old_line = nil end |
Instance Attribute Details
#branch ⇒ Object (readonly)
The pmd branch type, ‘base’ or ‘patch’
8 9 10 |
# File 'lib/pmdtester/pmd_violation.rb', line 8 def branch @branch end |
#fname ⇒ Object (readonly)
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>
30 31 32 |
# File 'lib/pmdtester/pmd_violation.rb', line 30 def fname @fname end |
#info_url ⇒ Object (readonly)
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>
30 31 32 |
# File 'lib/pmdtester/pmd_violation.rb', line 30 def info_url @info_url end |
#language ⇒ Object (readonly)
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>
30 31 32 |
# File 'lib/pmdtester/pmd_violation.rb', line 30 def language @language end |
#line ⇒ Object (readonly)
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>
30 31 32 |
# File 'lib/pmdtester/pmd_violation.rb', line 30 def line @line end |
#message ⇒ Object
Returns the value of attribute message.
31 32 33 |
# File 'lib/pmdtester/pmd_violation.rb', line 31 def @message end |
#old_line ⇒ Object (readonly)
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>
30 31 32 |
# File 'lib/pmdtester/pmd_violation.rb', line 30 def old_line @old_line end |
#old_message ⇒ Object (readonly)
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>
30 31 32 |
# File 'lib/pmdtester/pmd_violation.rb', line 30 def @old_message end |
#rule_name ⇒ Object (readonly)
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>
30 31 32 |
# File 'lib/pmdtester/pmd_violation.rb', line 30 def rule_name @rule_name end |
#ruleset_name ⇒ Object (readonly)
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>
30 31 32 |
# File 'lib/pmdtester/pmd_violation.rb', line 30 def ruleset_name @ruleset_name end |
Instance Method Details
#added? ⇒ Boolean
only makes sense if this is a diff
69 70 71 |
# File 'lib/pmdtester/pmd_violation.rb', line 69 def added? branch != BASE && !changed? end |
#changed? ⇒ Boolean
only makes sense if this is a diff
74 75 76 |
# File 'lib/pmdtester/pmd_violation.rb', line 74 def changed? @changed end |
#eql?(other) ⇒ Boolean
87 88 89 90 91 92 |
# File 'lib/pmdtester/pmd_violation.rb', line 87 def eql?(other) rule_name.eql?(other.rule_name) && line.eql?(other.line) && fname.eql?(other.fname) && .eql?(other.) end |
#hash ⇒ Object
94 95 96 |
# File 'lib/pmdtester/pmd_violation.rb', line 94 def hash [line, rule_name, ].hash end |
#line_move?(other) ⇒ Boolean
51 52 53 |
# File 'lib/pmdtester/pmd_violation.rb', line 51 def line_move?(other) .eql?(other.) && (line - other.line).abs <= 5 end |
#removed? ⇒ Boolean
only makes sense if this is a diff
79 80 81 |
# File 'lib/pmdtester/pmd_violation.rb', line 79 def removed? branch == BASE end |
#sort_key ⇒ Object
83 84 85 |
# File 'lib/pmdtester/pmd_violation.rb', line 83 def sort_key line end |
#to_liquid ⇒ Object
98 99 100 101 102 103 |
# File 'lib/pmdtester/pmd_violation.rb', line 98 def to_liquid { 'branch' => branch, 'changed' => changed? } end |
#try_merge?(other) ⇒ Boolean
55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/pmdtester/pmd_violation.rb', line 55 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. @old_line = other.line true else false end end |