Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #13345: enable example test for SeverityMatchFilterExamplesTest #14784

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -629,12 +629,21 @@ private static String getMessageBundle(String className) {
final String messageBundle;
final String messages = "messages";
final int endIndex = className.lastIndexOf('.');
final Map<String, String> messageBundleMappings = new HashMap<>();
messageBundleMappings.put("SeverityMatchFilterExamplesTest",
"com.puppycrawl.tools.checkstyle.checks.naming.messages");

if (endIndex < 0) {
messageBundle = messages;
}
else {
final String packageName = className.substring(0, endIndex);
messageBundle = packageName + "." + messages;
if ("com.puppycrawl.tools.checkstyle.filters".equals(packageName)) {
messageBundle = messageBundleMappings.get(className.substring(endIndex + 1));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change logic to use value from manual mapping if mapping is present.
If present in special map then use it , else use packageName

}
else {
messageBundle = packageName + "." + messages;
}
}
return messageBundle;
}
Expand Down
Expand Up @@ -368,6 +368,10 @@ private static String getFullyQualifiedClassName(String filePath, String moduleN
"com.puppycrawl.tools.checkstyle.checks.javadoc.SummaryJavadocCheck");
moduleMappings.put("LineLength",
"com.puppycrawl.tools.checkstyle.checks.sizes.LineLengthCheck");
moduleMappings.put("ParameterName",
"com.puppycrawl.tools.checkstyle.checks.naming.ParameterNameCheck");
moduleMappings.put("MethodName",
"com.puppycrawl.tools.checkstyle.checks.naming.MethodNameCheck");

String fullyQualifiedClassName;
if (moduleMappings.containsKey(moduleName)) {
Expand Down
Expand Up @@ -19,24 +19,26 @@

package com.puppycrawl.tools.checkstyle.filters;

import org.junit.jupiter.api.Disabled;
import static com.puppycrawl.tools.checkstyle.checks.naming.AbstractNameCheck.MSG_INVALID_PATTERN;

import org.junit.jupiter.api.Test;

import com.puppycrawl.tools.checkstyle.AbstractExamplesModuleTestSupport;

@Disabled("until https://github.com/checkstyle/checkstyle/issues/13345")
public class SeverityMatchFilterExamplesTest extends AbstractExamplesModuleTestSupport {
@Override
protected String getPackageLocation() {
return "com/puppycrawl/tools/checkstyle/filters/severitymatchfilter";
}

@Test
public void testExample1() throws Exception {
final String[] expected = {
public void testExample() throws Exception {
final String pattern = "^[a-z][a-zA-Z0-9]*$";

final String[] expected = {
"22:15: " + getCheckMessage(MSG_INVALID_PATTERN, "Method2", pattern),
};

verifyWithInlineConfigParser(getPath("Example1.txt"), expected);
verifyWithInlineConfigParser(getPath("Example1.java"), expected);
}
}
@@ -0,0 +1,24 @@
/*xml
<module name="Checker">
<module name="TreeWalker">
<module name="ParameterName">
<property name="severity" value="info"/>
</module>
<module name="MethodName"/>
</module>
<module name="SeverityMatchFilter">
<property name="severity" value="info"/>
<property name="acceptOnMatch" value="false"/>
</module>
</module>
*/
package com.puppycrawl.tools.checkstyle.filters.severitymatchfilter;

// xdoc section -- start
public class Example1 {

public void method1(int V1){} // ok, ParameterNameCheck's severity is info

public void Method2(){} // violation
}
// xdoc section -- end

This file was deleted.

17 changes: 17 additions & 0 deletions src/xdocs/filters/severitymatchfilter.xml
Expand Up @@ -55,12 +55,29 @@
</p>
<source>
&lt;module name=&quot;Checker&quot;&gt;
&lt;module name=&quot;TreeWalker&quot;&gt;
romani marked this conversation as resolved.
Show resolved Hide resolved
&lt;module name=&quot;ParameterName&quot;&gt;
&lt;property name=&quot;severity&quot; value=&quot;info&quot;/&gt;
&lt;/module&gt;
&lt;module name=&quot;MethodName&quot;/&gt;
&lt;/module&gt;
&lt;module name=&quot;SeverityMatchFilter&quot;&gt;
&lt;property name=&quot;severity&quot; value=&quot;info&quot;/&gt;
&lt;property name=&quot;acceptOnMatch&quot; value=&quot;false&quot;/&gt;
&lt;/module&gt;
&lt;/module&gt;
</source>
<p id="Example1-code">
Code Example:
</p>
<source>
public class Example1 {

public void method1(int V1){} // ok, ParameterNameCheck's severity is info
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// ok, ParameterName's severity is info


public void Method2(){} // violation
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

// violation, as default severity is error

}
</source>
</subsection>
<subsection name="Example of Usage" id="Example_of_Usage">
<ul>
Expand Down
10 changes: 9 additions & 1 deletion src/xdocs/filters/severitymatchfilter.xml.template
Expand Up @@ -36,9 +36,17 @@
</p>
<macro name="example">
<param name="path"
value="resources/com/puppycrawl/tools/checkstyle/filters/severitymatchfilter/Example1.txt"/>
value="resources/com/puppycrawl/tools/checkstyle/filters/severitymatchfilter/Example1.java"/>
<param name="type" value="config"/>
</macro>
<p id="Example1-code">
Code Example:
</p>
<macro name="example">
<param name="path"
value="resources/com/puppycrawl/tools/checkstyle/filters/severitymatchfilter/Example1.java"/>
<param name="type" value="code"/>
</macro>
</subsection>
<subsection name="Example of Usage" id="Example_of_Usage">
<ul>
Expand Down