Skip to content

Commit

Permalink
Issue checkstyle#10745: Added functionality for module parent
Browse files Browse the repository at this point in the history
  • Loading branch information
shashwatj07 committed Aug 29, 2021
1 parent 87a8533 commit 6a85ee5
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 12 deletions.
Expand Up @@ -224,21 +224,23 @@ protected final void verifyFilterWithInlineConfigParser(Configuration aConfig,
throws Exception {
final TestInputConfiguration checkTestInputConfiguration =
InlineConfigParser.parseWithFilteredViolations(filePath);
final Configuration parsedCheckConfig = checkTestInputConfiguration.createConfiguration();
verifyConfig(aConfig, parsedCheckConfig,
checkTestInputConfiguration.getChildrenModules().get(0));
final DefaultConfiguration parsedCheckConfig =
checkTestInputConfiguration.createConfiguration();
final ModuleInputConfiguration checkModule =
checkTestInputConfiguration.getChildrenModules().get(0);
verifyConfig(aConfig, checkModule.createConfiguration(), checkModule);
verifyViolations(parsedCheckConfig, filePath, checkTestInputConfiguration);
verify(parsedCheckConfig, filePath, expectedUnfiltered);
final TestInputConfiguration filterTestInputConfiguration =
InlineConfigParser.parseFilter(filePath);
final Configuration parsedFilterConfig =
final DefaultConfiguration parsedFilterConfig =
filterTestInputConfiguration.createConfiguration();
verifyConfig(filterConfig, parsedFilterConfig,
filterTestInputConfiguration.getChildrenModules().get(0));
final DefaultConfiguration rootConfig = createRootConfig(parsedCheckConfig);
rootConfig.addChild(parsedFilterConfig);
verifyViolations(rootConfig, filePath, filterTestInputConfiguration);
verify(rootConfig, filePath, expectedFiltered);
final ModuleInputConfiguration filterModule =
filterTestInputConfiguration.getChildrenModules().get(0);
verifyConfig(filterConfig, filterModule.createConfiguration(), filterModule);
parsedCheckConfig.addChild(filterModule.createConfiguration());
verifyViolations(parsedCheckConfig, filePath, filterTestInputConfiguration);
verify(parsedCheckConfig, filePath, expectedFiltered);
}

/**
Expand All @@ -257,7 +259,9 @@ protected final void verifyWithInlineConfigParser(Configuration aConfig,
final TestInputConfiguration testInputConfiguration =
InlineConfigParser.parse(filePath);
final Configuration parsedConfig = testInputConfiguration.createConfiguration();
verifyConfig(aConfig, parsedConfig, testInputConfiguration.getChildrenModules().get(0));
final ModuleInputConfiguration checkModule =
testInputConfiguration.getChildrenModules().get(0);
verifyConfig(aConfig, checkModule.createConfiguration(), checkModule);
verifyViolations(parsedConfig, filePath, testInputConfiguration);
verify(parsedConfig, filePath, expected);
}
Expand Down
Expand Up @@ -19,14 +19,42 @@

package com.puppycrawl.tools.checkstyle.bdd;

import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
import com.puppycrawl.tools.checkstyle.TreeWalker;

public final class TestInputConfiguration {

private static final String ROOT_MODULE_NAME = "root";

private static final Set<String> CHECKER_CHILDREN = new HashSet<>(Arrays.asList(
"com.puppycrawl.tools.checkstyle.filefilters.BeforeExecutionExclusionFileFilter",
"com.puppycrawl.tools.checkstyle.filters.SeverityMatchFilter",
"com.puppycrawl.tools.checkstyle.filters.SuppressionFilter",
"com.puppycrawl.tools.checkstyle.filters.SuppressionSingleFilter",
"com.puppycrawl.tools.checkstyle.filters.SuppressWarningsFilter",
"com.puppycrawl.tools.checkstyle.filters.SuppressWithPlainTextCommentFilter",
"com.puppycrawl.tools.checkstyle.checks.header.HeaderCheck",
"com.puppycrawl.tools.checkstyle.checks.header.RegexpHeaderCheck",
"com.puppycrawl.tools.checkstyle.checks.javadoc.JavadocPackageCheck",
"com.puppycrawl.tools.checkstyle.checks.NewlineAtEndOfFileCheck",
"com.puppycrawl.tools.checkstyle.checks.UniquePropertiesCheck",
"com.puppycrawl.tools.checkstyle.checks.OrderedPropertiesCheck",
"com.puppycrawl.tools.checkstyle.checks.regexp.RegexpMultilineCheck",
"com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineCheck",
"com.puppycrawl.tools.checkstyle.checks.regexp.RegexpOnFilenameCheck",
"com.puppycrawl.tools.checkstyle.checks.sizes.FileLengthCheck",
"com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck",
"com.puppycrawl.tools.checkstyle.checks.whitespace.FileTabCharacterCheck"
));

private final List<ModuleInputConfiguration> childrenModules;

private final List<TestInputViolation> violations;
Expand All @@ -46,7 +74,23 @@ public List<ModuleInputConfiguration> getChildrenModules() {
}

public DefaultConfiguration createConfiguration() {
return childrenModules.get(0).createConfiguration();
final DefaultConfiguration root = new DefaultConfiguration(ROOT_MODULE_NAME);
final DefaultConfiguration treeWalker =
new DefaultConfiguration(TreeWalker.class.getName());
root.addProperty("charset", StandardCharsets.UTF_8.name());
childrenModules
.stream()
.map(ModuleInputConfiguration::createConfiguration)
.forEach(moduleConfig -> {
if (CHECKER_CHILDREN.contains(moduleConfig.getName())) {
root.addChild(moduleConfig);
}
else {
treeWalker.addChild(moduleConfig);
}
});
root.addChild(treeWalker);
return root;
}

public static final class Builder {
Expand Down

0 comments on commit 6a85ee5

Please sign in to comment.