Skip to content

Commit

Permalink
Issue checkstyle#13345: Enable UnusedImportCheckExamplesTest
Browse files Browse the repository at this point in the history
  • Loading branch information
TanayMorakhia authored and nrmancuso committed Oct 20, 2023
1 parent fd6dd14 commit 0861344
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@

package com.puppycrawl.tools.checkstyle.checks.imports;

import org.junit.jupiter.api.Disabled;
import static com.puppycrawl.tools.checkstyle.checks.imports.UnusedImportsCheck.MSG_KEY;

import org.junit.jupiter.api.Test;

import com.puppycrawl.tools.checkstyle.AbstractExamplesModuleTestSupport;

@Disabled("until https://github.com/checkstyle/checkstyle/issues/13345")
public class UnusedImportsCheckExamplesTest extends AbstractExamplesModuleTestSupport {
@Override
protected String getPackageLocation() {
Expand All @@ -34,18 +34,21 @@ protected String getPackageLocation() {
@Test
public void testExample1() throws Exception {
final String[] expected = {

"19:8: " + getCheckMessage(MSG_KEY, "java.lang.String"),
"22:8: " + getCheckMessage(MSG_KEY, "java.util.Map"),
};

verifyWithInlineConfigParser(getPath("Example1.txt"), expected);
verifyWithInlineConfigParser(getPath("Example1.java"), expected);
}

@Test
public void testExample2() throws Exception {
final String[] expected = {

"21:8: " + getCheckMessage(MSG_KEY, "java.lang.String"),
"24:8: " + getCheckMessage(MSG_KEY, "java.util.Map"),
"26:8: " + getCheckMessage(MSG_KEY, "java.util.List"),
};

verifyWithInlineConfigParser(getPath("Example2.txt"), expected);
verifyWithInlineConfigParser(getPath("Example2.java"), expected);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
</module>
*/

package com.puppycrawl.tools.checkstyle.checks.imports.unusedimports;

// xdoc section -- start
// limitation as it match field name in code
import java.awt.Component; //OK
Expand All @@ -16,18 +18,18 @@

import java.lang.String; // violation

import java.util.Stack; // OK
import java.util.Stack;
import java.util.Map; // violation

import java.util.List; // OK
import java.util.List;

/**
* @link List
*/
class MyClass{
Stack stack = new Stack();
private Object Component;
int[] arr = {0,0};
int[] array = copyOf(arr , 1);
class Example1{
Stack stack = new Stack();
private Object Component;
int[] arr = {0,0};
int[] array = copyOf(arr , 1);
}
// xdoc section -- end
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
</module>
*/

package com.puppycrawl.tools.checkstyle.checks.imports.unusedimports;

// xdoc section -- start
// limitation as it match field name in code
import java.awt.Component; //OK
Expand All @@ -18,18 +20,18 @@

import java.lang.String; // violation

import java.util.Stack; // OK
import java.util.Stack;
import java.util.Map; // violation

import java.util.List; // violation

/**
* @link List
*/
class MyClass{
Stack stack = new Stack();
private Object Component;
int[] arr = {0,0};
int[] array = copyOf(arr , 1);
class Example2{
Stack stack = new Stack();
private Object Component;
int[] arr = {0,0};
int[] array = copyOf(arr , 1);
}
// xdoc section -- end
26 changes: 13 additions & 13 deletions src/xdocs/checks/imports/unusedimports.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,19 +100,19 @@ import static java.util.Arrays.copyOf; //OK

import java.lang.String; // violation

import java.util.Stack; // OK
import java.util.Stack;
import java.util.Map; // violation

import java.util.List; // OK
import java.util.List;

/**
* @link List
*/
class MyClass{
Stack stack = new Stack();
private Object Component;
int[] arr = {0,0};
int[] array = copyOf(arr , 1);
class Example1{
Stack stack = new Stack();
private Object Component;
int[] arr = {0,0};
int[] array = copyOf(arr , 1);
}
</source>
<p id="Example2-config">
Expand All @@ -138,19 +138,19 @@ import static java.util.Arrays.copyOf; //OK

import java.lang.String; // violation

import java.util.Stack; // OK
import java.util.Stack;
import java.util.Map; // violation

import java.util.List; // violation

/**
* @link List
*/
class MyClass{
Stack stack = new Stack();
private Object Component;
int[] arr = {0,0};
int[] array = copyOf(arr , 1);
class Example2{
Stack stack = new Stack();
private Object Component;
int[] arr = {0,0};
int[] array = copyOf(arr , 1);
}
</source>
</subsection>
Expand Down
8 changes: 4 additions & 4 deletions src/xdocs/checks/imports/unusedimports.xml.template
Original file line number Diff line number Diff line change
Expand Up @@ -84,27 +84,27 @@
</p>
<macro name="example">
<param name="path"
value="resources/com/puppycrawl/tools/checkstyle/checks/imports/unusedimports/Example1.txt"/>
value="resources/com/puppycrawl/tools/checkstyle/checks/imports/unusedimports/Example1.java"/>
<param name="type" value="config"/>
</macro>
<p id="Example1-code">Example:</p>
<macro name="example">
<param name="path"
value="resources/com/puppycrawl/tools/checkstyle/checks/imports/unusedimports/Example1.txt"/>
value="resources/com/puppycrawl/tools/checkstyle/checks/imports/unusedimports/Example1.java"/>
<param name="type" value="code"/>
</macro>
<p id="Example2-config">
To configure the check so that it ignores the imports referenced in Javadoc comments:
</p>
<macro name="example">
<param name="path"
value="resources/com/puppycrawl/tools/checkstyle/checks/imports/unusedimports/Example2.txt"/>
value="resources/com/puppycrawl/tools/checkstyle/checks/imports/unusedimports/Example2.java"/>
<param name="type" value="config"/>
</macro>
<p id="Example2-code">Example:</p>
<macro name="example">
<param name="path"
value="resources/com/puppycrawl/tools/checkstyle/checks/imports/unusedimports/Example2.txt"/>
value="resources/com/puppycrawl/tools/checkstyle/checks/imports/unusedimports/Example2.java"/>
<param name="type" value="code"/>
</macro>
</subsection>
Expand Down

0 comments on commit 0861344

Please sign in to comment.