Skip to content

Commit

Permalink
Issue checkstyle#5879: Suppression xpath single filter
Browse files Browse the repository at this point in the history
  • Loading branch information
tsunghanjacktsai committed Nov 15, 2018
1 parent e2f7bb6 commit c0b85b5
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 0 deletions.
1 change: 1 addition & 0 deletions config/checkstyle_checks.xml
Expand Up @@ -350,6 +350,7 @@
<module name="SuppressionXpathFilter">
<property name="file" value="${checkstyle.suppressions-xpath.file}"/>
</module>
<module name="SuppressionXpathSingleFilter"/>
<module name="SuppressWithNearbyCommentFilter">
<property name="commentFormat"
value="-@cs\[(\w{8,}(\|\w{8,})*)\] \w[\(\)\-\.\'\`\,\:\;\w ]{10,}"/>
Expand Down
@@ -0,0 +1,63 @@
package com.puppycrawl.tools.checkstyle.filters;

import com.puppycrawl.tools.checkstyle.TreeWalkerAuditEvent;
import com.puppycrawl.tools.checkstyle.TreeWalkerFilter;
import com.puppycrawl.tools.checkstyle.api.AutomaticBean;
import com.puppycrawl.tools.checkstyle.api.CheckstyleException;

/**
*
*/
public class SuppressionXpathSingleFilter extends AutomaticBean implements
TreeWalkerFilter {
private XpathFilter xpathFilter;

/** The pattern for file names. */
private String filePattern;

/** The pattern for check class names. */
private String checkPattern;

/** The pattern for message names. */
private String messagePattern;

/** Module id filter. */
private String moduleId;

/** Xpath query. */
private String xpathQuery;

public void setFilePattern(String filePattern) {
this.filePattern = filePattern;
}

public void setCheckPattern(String checkPattern) {
this.checkPattern = checkPattern;
}

public void setMessagePattern(String messagePattern) {
this.messagePattern = messagePattern;
}

public void setModuleId(String moduleId) {
this.moduleId = moduleId;
}

public void setXpathQuery(String xpathQuery) {
this.xpathQuery = xpathQuery;
}

public SuppressionXpathSingleFilter() {
xpathFilter = new XpathFilter(filePattern, checkPattern, messagePattern, moduleId, xpathQuery);
}

@Override
public boolean accept(TreeWalkerAuditEvent treeWalkerAuditEvent) {
return xpathFilter.accept(treeWalkerAuditEvent);
}

@Override
protected void finishLocalSetup() throws CheckstyleException {
// No code by default
}
}
21 changes: 21 additions & 0 deletions src/xdocs/config_filters.xml
Expand Up @@ -985,6 +985,27 @@ public class InputTest {
</subsection>
</section>

<section name="SupperssionXpathSingleFilter">
<subsection name="Description" id="SuppressionXpathSingleFilter">

</subsection>
<subsection name="Properties" id="SuppressWithXpathSingleFilter_Properties">

</subsection>
<subsection name="Examples" id="SuppressionXpathSingleFilter_Examples">

</subsection>
<subsection name="Example of Usage" id="SuppressionXpathSingleFilter_Example_of_Usage">

</subsection>
<subsection name="Package" id="SuppressionXpathSingleFilter_Package">

</subsection>
<subsection name="Parent Module" id="SuppressXpathSingleFilter_Parent_Module">

</subsection>
</section>

<section name="SuppressWarningsFilter">
<subsection name="Description" id="SuppressWarningsFilter_Description">
<p>Since Checkstyle 5.7</p>
Expand Down

0 comments on commit c0b85b5

Please sign in to comment.