Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/python/review/inspectors/checkstyle/files/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,9 @@
<module name="MissingSwitchDefault"/>
<module name="ModifiedControlVariable"/>
<module name="MultipleStringLiterals">
<property name="allowedDuplicates" value="2"/>
<property name="ignoreStringsRegexp" value="^.{1,5}$"/>
<!-- Consistent with AvoidDuplicateLiterals from PMD -->
<property name="allowedDuplicates" value="3"/>
<property name="ignoreStringsRegexp" value='^".{0,2}"$'/>
</module>
<module name="MultipleVariableDeclarations"/>
<module name="NoFinalizer"/>
Expand Down
1 change: 1 addition & 0 deletions test/python/inspectors/test_checkstyle_inspector.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
('test_indentation_with_spaces.java', 0),
('test_indentation_with_tabs.java', 0),
('test_indentation_google_style.java', 4),
('test_multiple_literals.java', 1),
]


Expand Down
1 change: 1 addition & 0 deletions test/python/inspectors/test_pmd_inspector.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
('test_valid_curly_braces.java', 0),
('test_when_only_equals_overridden.java', 1),
('test_valid_spaces.java', 0),
('test_multiple_literals.java', 1),
]


Expand Down
32 changes: 32 additions & 0 deletions test/resources/inspectors/java/test_multiple_literals.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
class Main {
public static void main(String[] args) {
// ok
String shortRareLiteral1 = "12";
String shortRareLiteral2 = "12";
String shortRareLiteral3 = "12";

// ok
String longRareLiteral1 = "123";
String longRareLiteral2 = "123";
String longRareLiteral3 = "123";

// ok
String shortFrequentLiteral1 = "34";
String shortFrequentLiteral2 = "34";
String shortFrequentLiteral3 = "34";
String shortFrequentLiteral4 = "34";

// warning
String longFrequentLiteral1 = "456";
String longFrequentLiteral2 = "456";
String longFrequentLiteral3 = "456";
String longFrequentLiteral4 = "456";

System.out.println(
shortRareLiteral1 + shortRareLiteral2 + shortRareLiteral3 +
longRareLiteral1 + longRareLiteral2 + longRareLiteral3 +
shortFrequentLiteral1 + shortFrequentLiteral2 + shortFrequentLiteral3 + shortFrequentLiteral4 +
longFrequentLiteral1 + longFrequentLiteral2 + longFrequentLiteral3 + longFrequentLiteral4
);
}
}