Skip to content

Commit d20b6a3

Browse files
committed
Issue #130: fix ReturnCount checkstyle violations
1 parent 96fa938 commit d20b6a3

File tree

5 files changed

+20
-12
lines changed

5 files changed

+20
-12
lines changed

checkstyle-sonar-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleAuditListener.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,16 @@ static String getRuleKey(AuditEvent event) {
127127

128128
@VisibleForTesting
129129
static String getMessage(AuditEvent event) {
130+
String result;
130131
try {
131-
return event.getMessage();
132+
result = event.getMessage();
132133

133134
}
134135
catch (Exception ex) {
135136
LOG.warn("AuditEvent is created incorrectly. Exception happen during getMessage()", ex);
136-
return null;
137+
result = null;
137138
}
139+
return result;
138140
}
139141

140142
@VisibleForTesting

checkstyle-sonar-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleConfiguration.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,10 +94,11 @@ public List<File> getSourceFiles() {
9494
}
9595

9696
public File getTargetXmlReport() {
97+
File result = null;
9798
if (conf.getBoolean(PROPERTY_GENERATE_XML)) {
98-
return new File(fileSystem.workDir(), "checkstyle-result.xml");
99+
result = new File(fileSystem.workDir(), "checkstyle-result.xml");
99100
}
100-
return null;
101+
return result;
101102
}
102103

103104
public Configuration getCheckstyleConfiguration() throws CheckstyleException {

checkstyle-sonar-plugin/src/main/java/org/sonar/plugins/checkstyle/CheckstyleProfileImporter.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,14 @@ static boolean isIgnored(String configKey) {
154154

155155
@VisibleForTesting
156156
static boolean isFilter(String configKey) {
157+
boolean result = false;
157158
for (String filter : FILTERS) {
158159
if (StringUtils.equals(configKey, filter)) {
159-
return true;
160+
result = true;
161+
break;
160162
}
161163
}
162-
return false;
164+
return result;
163165
}
164166

165167
private void processRule(RulesProfile profile, String path, String moduleName,

checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/internal/CheckUtil.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,16 +201,18 @@ else if (module == RegexpSinglelineCheck.class
201201
*/
202202
public static String getCheckMessage(Class<?> module, String messageKey,
203203
Object... arguments) {
204+
String result;
204205
final Properties pr = new Properties();
205206
try {
206207
pr.load(module.getResourceAsStream("messages.properties"));
208+
final MessageFormat formatter =
209+
new MessageFormat(pr.getProperty(messageKey), Locale.ENGLISH);
210+
result = formatter.format(arguments);
207211
}
208212
catch (IOException ex) {
209-
return null;
213+
result = null;
210214
}
211-
final MessageFormat formatter =
212-
new MessageFormat(pr.getProperty(messageKey), Locale.ENGLISH);
213-
return formatter.format(arguments);
215+
return result;
214216
}
215217

216218
public static String getTokenText(int[] tokens, int... subtractions) {

checkstyle-sonar-plugin/src/test/java/org/sonar/plugins/checkstyle/internal/XmlUtil.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,21 +41,22 @@ private XmlUtil() {
4141

4242
public static Document getRawXml(String fileName, String code, String unserializedSource)
4343
throws ParserConfigurationException {
44+
Document result = null;
4445
try {
4546
final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
4647
factory.setValidating(false);
4748
factory.setNamespaceAware(true);
4849

4950
final DocumentBuilder builder = factory.newDocumentBuilder();
5051

51-
return builder.parse(new InputSource(new StringReader(code)));
52+
result = builder.parse(new InputSource(new StringReader(code)));
5253
}
5354
catch (IOException | SAXException ex) {
5455
Assert.fail(fileName + " has invalid xml (" + ex.getMessage() + "): "
5556
+ unserializedSource);
5657
}
5758

58-
return null;
59+
return result;
5960
}
6061

6162
public static Set<Node> getChildrenElements(Node node) {

0 commit comments

Comments
 (0)