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

minor: update checks(related to checkstyle issue#10100) #851

Merged
merged 2 commits into from
Aug 9, 2021

Conversation

nrmancuso
Copy link
Contributor

@nrmancuso nrmancuso commented Jun 15, 2021

Related to checkstyle/checkstyle#10104

Original reports from Checkstyle PR showing regression:

https://nmancus1.github.io/issue-10100_check_diff_reports_2021_06_11/diff_sevntu-check-regression_part_1/index.html

NoMainMethodInAbstractClassCheck- new NPE
ForbidWildcardAsReturnType - lots of new legit violations, we were missing violations on methods like public Class<?>[] getClasses() {}
InnerClass - symmetrical column changes
StaticMethodCandidate - new violations, we were missing violations previously on methods with String return type


https://nmancus1.github.io/issue-10100_check_diff_reports_2021_06_11/diff_sevntu-check-regression_part_2/index.html

MoveVariableInsideIf - symmetrical column number changes
SimpleAccessorNameNotation - symmetrical column number changes
CustomDeclarationOrder - symmetrical column number changes


New reports showing no regression:

https://nmancus1.github.io/issue-10100_check_diff_reports_2021_06_16/diff_sevntu-check-regression_part_1/index.html

Symmetric column changes and new legitimate violations
NoMainMethodInAbstractClassCheck- NPE is gone


https://nmancus1.github.io/issue-10100_check_diff_reports_2021_06_16/diff_sevntu-check-regression_part_2/index.html

Symmetric column changes only


All other changes were because of failing existing unit tests (found via mvn clean verify).

I will let the build fail to show that the changes in this PR are dependent on the changes at checkstyle/checkstyle#10104, then I will change the Checkstyle repo to my PR to show that all pass.

Failed build (I had to add mvn clean verify to CI):

Results :

Failed tests: 
  NoMainMethodInAbstractClassCheckTest.testDefault:87->AbstractModuleTestSupport.verify:229->AbstractModuleTestSupport.verify:267->AbstractModuleTestSupport.verify:304 error message 0 expected:<...actClassCheck.java:1[00]:5: Main method insi...> but was:<...actClassCheck.java:1[16]:5: Main method insi...>
  ForbidWildcardAsReturnTypeCheckTest.testNewArrayStructure:461->AbstractModuleTestSupport.verify:229->AbstractModuleTestSupport.verify:267->AbstractModuleTestSupport.verify:304 error message 0 expected:<[/pipeline/source/sevntu-checks/src/test/resources/com/github/sevntu/checkstyle/checks/design/InputForbidWildcardAsReturnTypeCheckNewArrayStructure.java:4:5: Wildcard as return type should be avoided].> but was:<[Audit done].>
  PreferMethodReferenceCheckTest.testObjectCreation:146->AbstractModuleTestSupport.verify:229->AbstractModuleTestSupport.verify:267->AbstractModuleTestSupport.verify:304 error message 2 expected:<...ferenceCheck4.java:1[7]:39: Lambda can be r...> but was:<...ferenceCheck4.java:1[8]:39: Lambda can be r...>
  PreferMethodReferenceCheckTest.testStatementsListsWithExpressions:128->AbstractModuleTestSupport.verify:229->AbstractModuleTestSupport.verify:267->AbstractModuleTestSupport.verify:304 error message 11 expected:<...eferenceCheck3.java:[46]:40: Lambda can be r...> but was:<...eferenceCheck3.java:[50]:40: Lambda can be r...>
  Jsr305AnnotationsCheckTest.testArrays:161->AbstractModuleTestSupport.verify:229->AbstractModuleTestSupport.verify:267->AbstractModuleTestSupport.verify:304 error message 6 expected:<...kWithArrays.java:90:[5]: Return value must ...> but was:<...kWithArrays.java:90:[8]: Return value must ...>
  CustomDeclarationOrderCheckTest.mainMethod:189->AbstractModuleTestSupport.verify:229->AbstractModuleTestSupport.verify:267->AbstractModuleTestSupport.verify:304 error message 0 expected:<...d(private )' then 'M[ainM]ethod(.*)'.> but was:<...d(private )' then 'M[]ethod(.*)'.>

Tests run: 411, Failures: 6, Errors: 0, Skipped: 0

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 32.994 s
[INFO] Finished at: 2021-06-16T11:42:15Z
[INFO] Final Memory: 56M/980M
[INFO] ---------------------------------------------------------------------

Full log at https://app.wercker.com/checkstyle/sevntu.checkstyle/runs/build/60c9e32c237ec900086455fa?step=60c9e3678ea84100087595c9


mvn clean verify is passing with Checkstyle version from checkstyle/checkstyle#10104

@nrmancuso nrmancuso marked this pull request as draft June 15, 2021 19:38
@rnveach
Copy link
Contributor

rnveach commented Jun 16, 2021

the changes in this PR are dependent on the changes at checkstyle/checkstyle#10104

This means this PR is dependent on 4 things before it can be merged:

  1. Issue #10100: Extract parameter type from nested array declarator brackets checkstyle/checkstyle#10104 must be merged (UPDATE: DONE)
  2. checkstyle must release those changes (DONE - merged and released as 8.44)
  3. eclipse-cs must release with that new version of checkstyle
  4. The version of checkstyle in sevntu must update to the new eclipse-cs version (see https://github.com/sevntu-checkstyle/sevntu.checkstyle/blob/master/sevntu-checks/pom.xml#L18-L19 )

@nrmancuso nrmancuso force-pushed the checkstyle-10100 branch 2 times, most recently from 0f60cbe to ab6c95e Compare June 16, 2021 11:54
final String parameterName =
getIdentifier(arrayDeclaratorAST);
parameterTypeAST.getFirstChild().getText();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Parameter type is always first child now, it is no longer nested.

@@ -585,22 +586,17 @@ private static boolean isPrimitiveType(DetailAST ast) {
/**
* Checks whether token is array or elipsis.
*
* @param identToken
* @param typeToken
Copy link
Contributor Author

@nrmancuso nrmancuso Jun 16, 2021

Choose a reason for hiding this comment

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

Previously named identToken, this DetailAST was actually never an IDENT. In every UT we have, this method is passed a TYPE ast.

Comment on lines +593 to +599
private static boolean isArrayOrElipsis(final DetailAST typeToken) {
final DetailAST next = typeToken.getNextSibling();
final boolean isArrayDeclarator =
typeToken.findFirstToken(TokenTypes.ARRAY_DECLARATOR) != null;
final boolean hasArrayOrEllipses =
TokenUtil.isOfType(next, TokenTypes.ARRAY_DECLARATOR, TokenTypes.ELLIPSIS);
return hasArrayOrEllipses || isArrayDeclarator;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Switch was overkill for two branches, refactored this and modified logic a bit for new type ast.

@@ -167,9 +167,7 @@ private static DetailAST getLastNode(final DetailAST node) {
while (child != null) {
final DetailAST newNode = getLastNode(child);
if (newNode.getLineNo() > currentNode.getLineNo()
|| newNode.getLineNo()
== currentNode.getLineNo() && newNode
Copy link
Contributor Author

Choose a reason for hiding this comment

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

After main repo PR, this line was not covered, and no cases to cover it were discovered in regression testing.

result = ident != null && name.equals(ident.getText());
}
else if (nestedDecl != null && expr == null) {
result = isArgUsedInArrayInit(nestedDecl, name);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

No need for recursion here anymore, we can just iterate through the sequential ARRAY_DECLARATOR brackets and check if they have an EXPR child (i.e. [2]), then simply check the first [a] to make sure that the lambda parameter and expression match.

final String parameterName =
getIdentifier(arrayDeclaratorAST);
parameterTypeAST.getFirstChild().getText();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same as above, type is always the first child.

createModuleConfig(ForbidWildcardAsReturnTypeCheck.class);

final String[] expected = {
"4:5: " + getCheckMessage(MSG_KEY),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

New violation found in regression testing.

@nrmancuso nrmancuso marked this pull request as ready for review June 16, 2021 12:16
wercker.yml Outdated Show resolved Hide resolved
@rnveach
Copy link
Contributor

rnveach commented Jun 16, 2021

Added blocked label because of #851 (comment) to prevent accidental merging. Label can be removed when this PR can be safely merged.

@ghost
Copy link

ghost commented Jul 19, 2021

Hi, I am a beginner at this issue can you help me. How to start it?

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.0009%) to 98.796% when pulling 850a091 on nmancus1:checkstyle-10100 into b7c8c72 on sevntu-checkstyle:master.

@romani romani merged commit 9b12f7c into sevntu-checkstyle:master Aug 9, 2021
@nrmancuso nrmancuso deleted the checkstyle-10100 branch August 10, 2021 12:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants