Skip to content

Commit

Permalink
Issue checkstyle#45: resolve AbbreviationAsWordInName violations
Browse files Browse the repository at this point in the history
  • Loading branch information
romani authored and tsjensen committed Mar 21, 2019
1 parent c08a6fc commit d6d732d
Show file tree
Hide file tree
Showing 8 changed files with 23 additions and 25 deletions.
2 changes: 0 additions & 2 deletions checkstyle-sonar-plugin/config/suppressions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
<suppress checks="RightCurly" files=".*[\\/]src[\\/]main[\\/]"/>
<suppress checks="IllegalCatch" files=".*[\\/]src[\\/]main[\\/]"/>
<suppress checks="CatchParameterName" files=".*[\\/]src[\\/]main[\\/]"/>
<suppress checks="AbbreviationAsWordInName" files=".*[\\/]src[\\/]main[\\/]"/>
<suppress checks="EmptyLineSeparator" files=".*[\\/]src[\\/]main[\\/]"/>
<suppress checks="OperatorWrap" files=".*[\\/]src[\\/]main[\\/]"/>
<suppress checks="MemberName" files=".*[\\/]src[\\/]main[\\/]"/>
Expand Down Expand Up @@ -47,7 +46,6 @@
<suppress checks="ClassDataAbstractionCoupling" files=".*[\/]src[\/]test[\/]"/>
<suppress checks="CyclomaticComplexity" files=".*[\/]src[\/]test[\/]"/>
<suppress checks="NPathComplexity" files=".*[\/]src[\/]test[\/]"/>
<suppress checks="AbbreviationAsWordInName" files=".*[\/]src[\/]test[\/]"/>
<suppress checks="CatchParameterName" files=".*[\/]src[\/]test[\/]"/>
<suppress checks="MemberName" files=".*[\/]src[\/]test[\/]"/>
<suppress checks="RegexpMultiline" files=".*[\/]src[\/]test[\/]"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public CheckstyleConfiguration(Settings conf, CheckstyleProfileExporter confExpo
this.fileSystem = fileSystem;
}

public File getXMLDefinitionFile() {
public File getXmlDefinitionFile() {
Writer writer = null;
File xmlFile = new File(fileSystem.workDir(), "checkstyle.xml");
try {
Expand All @@ -89,15 +89,15 @@ public List<File> getSourceFiles() {
return ImmutableList.<File>builder().addAll(files).build();
}

public File getTargetXMLReport() {
public File getTargetXmlReport() {
if (conf.getBoolean(PROPERTY_GENERATE_XML)) {
return new File(fileSystem.workDir(), "checkstyle-result.xml");
}
return null;
}

public Configuration getCheckstyleConfiguration() throws CheckstyleException {
File xmlConfig = getXMLDefinitionFile();
File xmlConfig = getXmlDefinitionFile();

LOG.info("Checkstyle configuration: " + xmlConfig.getAbsolutePath());
Configuration configuration = toCheckstyleConfiguration(xmlConfig);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void execute() {
checker.setModuleClassLoader(Thread.currentThread().getContextClassLoader());
checker.addListener(listener);

File xmlReport = configuration.getTargetXMLReport();
File xmlReport = configuration.getTargetXmlReport();
if (xmlReport != null) {
LOG.info("Checkstyle output report: " + xmlReport.getAbsolutePath());
xmlOutput = FileUtils.openOutputStream(xmlReport);
Expand All @@ -99,7 +99,7 @@ public void execute() {
}

@VisibleForTesting
URL getURL(URI uri) {
URL getUrl(URI uri) {
try {
return uri.toURL();
} catch (MalformedURLException e) {
Expand All @@ -111,7 +111,7 @@ private URLClassLoader createClassloader() {
Collection<File> classpathElements = javaResourceLocator.classpath();
List<URL> urls = Lists.newArrayList();
for (File file : classpathElements) {
urls.add(getURL(file.toURI()));
urls.add(getUrl(file.toURI()));
}
return new URLClassLoader(urls.toArray(new URL[urls.size()]), null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ public CheckstyleProfileExporter(Settings settings) {
public void exportProfile(RulesProfile profile, Writer writer) {
try {
ListMultimap<String, ActiveRule> activeRulesByConfigKey = arrangeByConfigKey(profile.getActiveRulesByRepository(CheckstyleConstants.REPOSITORY_KEY));
generateXML(writer, activeRulesByConfigKey);
generateXml(writer, activeRulesByConfigKey);

} catch (IOException e) {
throw new IllegalStateException("Fail to export the profile " + profile, e);
}

}

private void generateXML(Writer writer, ListMultimap<String, ActiveRule> activeRulesByConfigKey) throws IOException {
private void generateXml(Writer writer, ListMultimap<String, ActiveRule> activeRulesByConfigKey) throws IOException {
appendXmlHeader(writer);
appendCustomFilters(writer);
appendCheckerModules(writer, activeRulesByConfigKey);
Expand All @@ -78,9 +78,9 @@ private static void appendXmlHeader(Writer writer) throws IOException {
}

private void appendCustomFilters(Writer writer) throws IOException {
String filtersXML = settings.getString(CheckstyleConstants.FILTERS_KEY);
if (StringUtils.isNotBlank(filtersXML)) {
writer.append(filtersXML);
String filtersXml = settings.getString(CheckstyleConstants.FILTERS_KEY);
if (StringUtils.isNotBlank(filtersXml)) {
writer.append(filtersXml);
}
}

Expand Down Expand Up @@ -115,8 +115,8 @@ private void appendTreeWalker(Writer writer, ListMultimap<String, ActiveRule> ac
}

private boolean isSuppressWarningsEnabled() {
String filtersXML = settings.getString(CheckstyleConstants.FILTERS_KEY);
return filtersXML.contains("<module name=\"SuppressWarningsFilter\" />");
String filtersXml = settings.getString(CheckstyleConstants.FILTERS_KEY);
return filtersXml.contains("<module name=\"SuppressWarningsFilter\" />");
}

private static void appendXmlFooter(Writer writer) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,21 @@ public void getSourceFiles() {
}

@Test
public void getTargetXMLReport() {
public void getTargetXmlReport() {
Settings conf = new Settings();
CheckstyleConfiguration configuration = new CheckstyleConfiguration(conf, null, null, fileSystem);
assertThat(configuration.getTargetXMLReport()).isNull();
assertThat(configuration.getTargetXmlReport()).isNull();

conf.setProperty(CheckstyleConfiguration.PROPERTY_GENERATE_XML, "true");
configuration = new CheckstyleConfiguration(conf, null, null, fileSystem);
assertThat(configuration.getTargetXMLReport()).isEqualTo(new File(fileSystem.workDir(), "checkstyle-result.xml"));
assertThat(configuration.getTargetXmlReport()).isEqualTo(new File(fileSystem.workDir(), "checkstyle-result.xml"));
}

@Test
public void writeConfigurationToWorkingDir() throws IOException {
CheckstyleProfileExporter exporter = new FakeExporter();
CheckstyleConfiguration configuration = new CheckstyleConfiguration(null, exporter, null, fileSystem);
File xmlFile = configuration.getXMLDefinitionFile();
File xmlFile = configuration.getXmlDefinitionFile();

assertThat(xmlFile.exists()).isTrue();
assertThat(FileUtils.readFileToString(xmlFile)).isEqualTo("<conf/>");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ public void executeException() throws CheckstyleException {
}

@Test
public void getURLException() throws URISyntaxException {
public void getUrlException() throws URISyntaxException {
thrown.expect(IllegalStateException.class);
thrown.expectMessage("Fail to create the project classloader. Classpath element is invalid: htp://aa");
CheckstyleExecutor executor = new CheckstyleExecutor(null, null, createJavaResourceLocator());
executor.getURL(new URI("htp://aa"));
executor.getUrl(new URI("htp://aa"));
}

private static JavaResourceLocator createJavaResourceLocator() {
Expand All @@ -107,14 +107,14 @@ private static JavaResourceLocator createJavaResourceLocator() {
}

@Test
public void canGenerateXMLReportInEnglish() throws CheckstyleException, IOException {
public void canGenerateXmlReportInEnglish() throws CheckstyleException, IOException {
Locale initialLocale = Locale.getDefault();
Locale.setDefault(Locale.FRENCH);

try {
CheckstyleConfiguration conf = mockConf();
File report = new File("target/test-tmp/checkstyle-report.xml");
when(conf.getTargetXMLReport()).thenReturn(report);
when(conf.getTargetXmlReport()).thenReturn(report);
CheckstyleAuditListener listener = mockListener();
CheckstyleExecutor executor = new CheckstyleExecutor(conf, listener, createJavaResourceLocator());
executor.execute();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public void shouldUseTheIdPropertyToFindRule() {
}

@Test
public void testUnvalidXML() {
public void testUnvalidXml() {
Reader reader = new StringReader("not xml");
importer.importProfile(reader, messages);
assertThat(messages.getErrors().size()).isEqualTo(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@

public class CheckstyleRulesDefinitionTest {

private final List<String> NO_SQALE = ImmutableList.of(
private static final List<String> NO_SQALE = ImmutableList.of(
"com.puppycrawl.tools.checkstyle.checks.TranslationCheck",
"com.puppycrawl.tools.checkstyle.checks.TodoCommentCheck",
"com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineCheck",
Expand Down

0 comments on commit d6d732d

Please sign in to comment.