Skip to content

Commit bfac1bc

Browse files
committed
add offense conversions for relevant cases
1 parent cf8ac89 commit bfac1bc

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

lib/checkstyle_output_token.rb

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,17 @@
44
class CheckstyleOutputToken
55
attr_reader :severity, :file_name, :offense
66

7+
OFFENSE_CONVERSION = {
8+
'noTrailingWhitespace' => 'RegexpSinglelineCheck',
9+
'noConsecutiveLines' => 'RegexpMultilineCheck',
10+
'commentFirstSentenceMultiline' => 'RegexpMultilineCheck',
11+
'commentFirstSentenceSingleline' => 'RegexpSinglelineCheck'
12+
}.freeze
13+
714
def initialize(token_data)
815
@severity = token_data[1]
916
@file_name = token_data[2]
10-
@offense = token_data[3]
17+
@offense = OFFENSE_CONVERSION[token_data[3]] || token_data[3]
1118
end
1219

1320
def to_suppression

test/checkstyle_output_token_test.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,14 @@ def test_initialize
1212
assert_equal 'WhitespaceAround', token.offense
1313
assert_equal ' <suppress checks="WhitespaceAround" files="file.java"/>', token.to_suppression
1414
end
15+
16+
def test_initialize_offense_conversion
17+
token_data = ['', 'WARNING', 'file.java', 'noTrailingWhitespace']
18+
token = CheckstyleOutputToken.new(token_data)
19+
20+
assert_equal 'WARNING', token.severity
21+
assert_equal 'file.java', token.file_name
22+
assert_equal 'RegexpSinglelineCheck', token.offense
23+
assert_equal ' <suppress checks="RegexpSinglelineCheck" files="file.java"/>', token.to_suppression
24+
end
1525
end

0 commit comments

Comments
 (0)