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

supplemental: test cases added #12833

Merged
merged 1 commit into from Mar 14, 2023
Merged
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 @@ -42,6 +42,7 @@
import com.puppycrawl.tools.checkstyle.checks.naming.AbstractNameCheck;
import com.puppycrawl.tools.checkstyle.checks.naming.ConstantNameCheck;
import com.puppycrawl.tools.checkstyle.checks.naming.MemberNameCheck;
import com.puppycrawl.tools.checkstyle.checks.sizes.ParameterNumberCheck;
import com.puppycrawl.tools.checkstyle.checks.whitespace.AbstractParenPadCheck;
import com.puppycrawl.tools.checkstyle.checks.whitespace.TypecastParenPadCheck;
import com.puppycrawl.tools.checkstyle.internal.utils.TestUtil;
Expand Down Expand Up @@ -479,4 +480,31 @@ public void testWithAndWithoutCheckSuffixDifferentCases() throws Exception {
expected);
}

@Test
public void testAliasList() throws Exception {
final String[] expected = {
"16:17: " + getCheckMessage(ParameterNumberCheck.class,
ParameterNumberCheck.MSG_KEY, 7, 8),
"28:17: " + getCheckMessage(ParameterNumberCheck.class,
ParameterNumberCheck.MSG_KEY, 7, 8),
};
verifyWithInlineConfigParser(
getPath("InputSuppressWarningsHolderAlias.java"),
expected);
}

@Test
public void testAliasList2() throws Exception {
final String pattern = "^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$";
final String[] expected = {
"16:29: " + getCheckMessage(ConstantNameCheck.class,
AbstractNameCheck.MSG_INVALID_PATTERN, "a", pattern),
"19:30: " + getCheckMessage(ConstantNameCheck.class,
AbstractNameCheck.MSG_INVALID_PATTERN, "b", pattern),
};

verifyWithInlineConfigParser(
getPath("InputSuppressWarningsHolderAlias2.java"),
expected);
}
}
@@ -0,0 +1,56 @@
/*
com.puppycrawl.tools.checkstyle.checks.SuppressWarningsHolder
aliasList = com.puppycrawl.tools.checkstyle.checks.sizes.ParameterNumberCheck=paramnum
Copy link
Member

Choose a reason for hiding this comment

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

It is not same as <property name="aliasList" value="ParameterNumber=paramnum" />
As you reference in issue.
You should have aliasList=ParameterNumber=paramnum
Or second = to be escaped.

Copy link
Member

Choose a reason for hiding this comment

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

Or we need both formats in tests

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@romani the issue #11641 is all about supporting the simple name aliasList=ParameterNumber=paramnum.

Right now it only supports the fully qualified name #11542 (comment)

I will most probably send pr for fixing this by today #11641.

Copy link
Member

Choose a reason for hiding this comment

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

Ok.


com.puppycrawl.tools.checkstyle.filters.SuppressWarningsFilter

com.puppycrawl.tools.checkstyle.checks.sizes.ParameterNumberCheck
max = (default)7

*/

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

public class InputSuppressWarningsHolderAlias {

public void needsLotsOfParameters0(int a, // violation 'More than 7 parameters (found 8)'
int b, int c, int d, int e, int f, int g, int h) {
// ...
}

@SuppressWarnings("paramnum")
public void needsLotsOfParameters(int a, // filtered violation 'max parameter'
int b, int c, int d, int e, int f, int g, int h) {
// ...
}

@SuppressWarnings("ParamnumUnknown")
public void needsLotsOfParameters2(int a, // violation 'More than 7 parameters (found 8)'
int b, int c, int d, int e, int f, int g, int h) {
// ...
}

@SuppressWarnings("PAramnuM")
public void needsLotsOfParameters3(int a, // filtered violation 'max parameter'
int b, int c, int d, int e, int f, int g, int h) {
// ...
}

@SuppressWarnings("PARAMNUM")
public void needsLotsOfParameters4(int a, // filtered violation 'max parameter'
int b, int c, int d, int e, int f, int g, int h) {
// ...
}

@SuppressWarnings("paRAMnum")
public void needsLotsOfParameters5(int a, // filtered violation 'max parameter'
int b, int c, int d, int e, int f, int g, int h) {
// ...
}

@SuppressWarnings("pAramNUm")
public void needsLotsOfParameters6(int a, // filtered violation 'max parameter'
int b, int c, int d, int e, int f, int g, int h) {
// ...
}
}
@@ -0,0 +1,35 @@
/*
com.puppycrawl.tools.checkstyle.checks.SuppressWarningsHolder
aliasList = com.puppycrawl.tools.checkstyle.checks.naming.ConstantNameCheck=constant

com.puppycrawl.tools.checkstyle.filters.SuppressWarningsFilter

com.puppycrawl.tools.checkstyle.checks.naming.ConstantNameCheck
format = (default)^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$


*/

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

public class InputSuppressWarningsHolderAlias2 {
private static final int a = 0; // violation 'Name 'a' must match pattern'

@SuppressWarnings("Notconstant")
private static final int b = 0; // violation 'Name 'b' must match pattern'

@SuppressWarnings("CONSTANT") // filtered violation 'invalid pattern'
private static final int c = 0;

@SuppressWarnings("CONstant") // filtered violation 'invalid pattern'
private static final int d = 0;

@SuppressWarnings("consTant") // filtered violation 'invalid pattern'
private static final int e = 0;

@SuppressWarnings("cOnStAnT") // filtered violation 'invalid pattern'
private static final int f = 0;

@SuppressWarnings("cOnStAnT") // filtered violation 'invalid pattern'
private static final int g = 0;
}