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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #6981: Renamed Complete IT Regression codebase & Added new Pattern check for input file naming convention #14595

Closed
wants to merge 2 commits into from

Conversation

MANISH-K-07
Copy link
Contributor

@MANISH-K-07 MANISH-K-07 commented Mar 3, 2024

Closes Issue #6981
:)

Updates in PR :

Complete IT Regression codebase ( 997 Files Changed )of our project has been renamed in this PR to follow newly discussed pattern --> InputXpath{CheckName}Xxxx.java
XpathRegressionTest has been updated to check for the above mention new pattern.

---------------------------------------------------------------------------------------------------------------

<-- OUTDATED -->
Response to #6207 (comment) :

For Detailed Explanation : #14595 (comment)

I have added a new pattern check that verifies file name to comply with naming convention InputXpath{CheckName}Xxxx.java

XpathRegressionTest now tests the input file names to be either-

This can be removed after final fix of the mentioned issue.

Unrelated : I just found out that checkstyle doesn't allow collapsible nested ifs 馃槄

@MANISH-K-07 MANISH-K-07 force-pushed the renameIT branch 2 times, most recently from 940ee42 to 7dd1fa6 Compare March 3, 2024 13:16
@MANISH-K-07 MANISH-K-07 changed the title Issue #6981: Enforced naming convention in It executablestatementcount Issue #6981: Added new Pattern check for It Regression input file naming convention Mar 3, 2024
@MANISH-K-07

This comment was marked as outdated.

@nrmancuso
Copy link
Member

nrmancuso commented Mar 3, 2024

@rnveach , @romani , @nrmancuso
Please review and suggest

My suggestion is to get existing PRs across the finish line, and not keep opening new ones and spamming maintainers.

https://github.com/checkstyle/checkstyle/pulls/MANISH-K-07

We generally recommend for contributors to have only three PRs open at a time.

@MANISH-K-07
Copy link
Contributor Author

https://github.com/checkstyle/checkstyle/pulls/MANISH-K-07
We generally recommend for contributors to have only three PRs open at a time.

Sorry about that, I will focus on getting my existing PRs to success.

Rgarding the changes of this current PR, I have added the Test to accept a new pattern which was proposed as a permanent fix in discussions of Issue #6981 and following up with @romani 's suggestion at #6207 (comment)

Ok, IT pattern should be Input{CheckName}Xxxx.java.
I recommend to add such pattern in validation and allow two patterns (with input prefix and existing ) while work in progress.

This PR was a requirement inorder to fix the mentioned Issue #6981

Copy link
Member

@romani romani left a comment

Choose a reason for hiding this comment

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

Ok to merge

final String check = ALLOWED_DIRECTORY_AND_CHECKS.get(checkDir.toFile().getName());

try (DirectoryStream<Path> inputPaths = Files.newDirectoryStream(checkDir)) {
for (Path inputPath : inputPaths) {
final String filename = inputPath.toFile().getName();
if (filename.endsWith("java")) {
final Matcher matcher = pattern.matcher(filename);
if (filename.contains("SuppressionXpathRegression") && filename.endsWith("java")) {
Copy link
Member

Choose a reason for hiding this comment

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

I am not seeing why we have this check for SuppressionXpathRegression explicitly, why we have 2 chunks of duplicated code, and how this somehow only applies to ExecutableStatementCheck when there are still other checks to do.

Also the first post says this is the first part of this issue, but I am not seeing explanation on what is the other parts.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rnveach , From your #6981 (comment) :

Our regression area in IT should be fixed to match our pattern in Test folder.
Google and Sun area should atleast start with Input, but their folder structure follows a different pattern.

The input files of Google and sun area already start with word "Input".
The regression area however is too liberal.

Also the first post says this is the first part of this issue, but I am not seeing explanation on what is the other parts.

Approach :

  1. Rename all input files of regression area to match InputXpath{CheckName}Xxxx.java
  2. Organize the input files folder-wise like we did in our test folder (second part of issue as mentioned at comment)
  3. Organize the regression tests folder-wise to match the test folder pattern.
  4. Rename google and sun area files to be more specific of functionality (similar to my Issue 14436)

This can all be done in a single PR but it would complicate debugging and also the review process

I am not seeing why we have this check for SuppressionXpathRegression explicitly, why we have 2 chunks of duplicated code

At present, XpathRegressionTest is designed to fail if input file doesn't follow pattern SuppressionXpathRegressionXxxx.java.
All our files are named that way, so we need to allow them until this issue is fixed. So, I designed the code (suffixed "temp") to surpass if it finds a name containig "SuppressionXpathRegression"

From your discussion at #6207 (comment) and #6207 (comment) :

If we are talking about in the IT tier, I ask that we use a different pattern then Test.

I recommend to add such pattern in validation and allow two patterns (with input prefix and existing ) while work in progress.

The duplicate code I have designed to allow the new pattern InputXpath{CheckName}Xxxx.java while I work on fixing all the files. Once this is done, we can remove the previous chunk which is extra and update #6207 description intimating new contributors to follow new naming pattern for regression files.

and how this somehow only applies to ExecutableStatementCheck when there are still other checks to do.

The pattern applies to all of the regression area..
ExecutableStatementCheck was just my way of showing proof that my design works for new pattern.
The test was actually supposed to fail for the changes that I have made to executablestatementcount inputs, but because of the new chunk of code, it passes as I expected.

Also, I needed your and @romani 's approval for the new pattern InputXpath{CheckName}Xxxx.java
Once you are okay with this, I will send further PRs with all other checks

Copy link
Member

@rnveach rnveach Mar 9, 2024

Choose a reason for hiding this comment

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

I needed your ... approval for the new pattern InputXpath{CheckName}Xxxx.java

I have no issue here.

@romani gave his approval, so I don't think the pattern has any approval, but I am going to reassign him because of my next post.

Approach
Rename all input files of regression area to match InputXpath{CheckName}Xxxx.java

Tied into the next post, but this more an overall approach, including multiple issues and future goals. I am looking at only this issue, which is only file naming convention, and more importantly this PR to understand how this will fit into the overall issue. This PR is only a small part of your first bullet and it wasn't helping me see your goal for this.

The duplicate code I have designed to allow the new pattern InputXpath{CheckName}Xxxx.java while I work on fixing all the files.
ExecutableStatementCheck was just my way of showing proof that my design works for new pattern.

Now I understand what I was missing.

This PR doesn't enforce one pattern or another. It allows both the new and old pattern and users can "choose" what they want. The problem with this is that this goes against how we have done other similar issues. Normally we create suppressions or a list of things to do. That is how we know what is and isn't done, when an issue is fully complete, and people can pick from the list on what to work on a small part. We can't tell this with how you have it now. Is this 1 of 10, or 1 of a million? New contributors can accidentally copy the old pattern which will increase the list. There are so many files to do and limited time before GSoC, I doubt this can be completed quickly. I don't know your past work, so I am not basing this on any judgement of you but we take time to review and agree.

Unless someone interjects, we need to change this to be a enforcement with a list of to be completed. I wouldn't make this a exact file match but a parent folder match, which is the check name. So completing a folder completes a check. Anything in that folder can be whatever it wants if it is part of that list, but anything outside the list must be InputXpath.... We are then good to completely swap old enforcement with new as it will be fixed as your list is worked on. The list must reference the issue to work on (until https://....) and complete it. I recommend to make this a new issue, we can mark it as easy and maybe others will join you.

For this PR, I expect 2 commits. 1 commit of a full list, and the other with your example of ExecutableStatementCheck. This is a small enough subset as an example on how to do future PRs.

====

As a completely separate thought to improve your code, you probably could do away with all your changes and change:

final Pattern pattern = Pattern.compile("^SuppressionXpathRegression(.+)\\.java$");

to the following instead:

final Pattern pattern = Pattern.compile("^(?:SuppressionXpathRegression|InputXpath)(.+)\\.java$");

But I am thinking of a different path now so we can't use it.

Copy link
Member

Choose a reason for hiding this comment

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

The easiest way to handle this is to have some file with all the "bad" file names in it. We could create a hacked version of this method to generate this file, then read it in when this validation runs and filter out failures by the contents of the file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@nrmancuso , do you mean something like a temporary regex check/test?
Could you please elaborate on why we would need this? I see that the issue is going to be very short-lived. Then we can simply revert back to our original method with changed pattern?
Or please correct me if am I going in the wrong direction.. :)

Copy link
Member

@nrmancuso nrmancuso Mar 9, 2024

Choose a reason for hiding this comment

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

We need to make sure that other maintainers are on board, but my proposal is this:

  1. Hack this method locally to dump full filenames of the "bad" input files (with path) to a file
  2. Update this method to read the file in as a collection of files to ignore
  3. Update this method to only check for the new pattern, and filter failures by the suppression file

Then, as we rename input files, we can remove them from the generated list. This will prevent anyone from adding new files with bad naming.

@MANISH-K-07

This comment was marked as outdated.

@rnveach
Copy link
Member

rnveach commented Mar 9, 2024

Unrelated : I just found out that checkstyle doesn't allow collapsible nested ifs

Unless we are not talking about the same thing, it should, but you will run into issues with complexity if you put too many conditions in that one if.

Example:


and
if (storedVariable != null && isSameVariables(storedVariable, ast)) {

final String check = ALLOWED_DIRECTORY_AND_CHECKS.get(checkDir.toFile().getName());

try (DirectoryStream<Path> inputPaths = Files.newDirectoryStream(checkDir)) {
for (Path inputPath : inputPaths) {
final String filename = inputPath.toFile().getName();
if (filename.endsWith("java")) {
final Matcher matcher = pattern.matcher(filename);
if (filename.contains("SuppressionXpathRegression") && filename.endsWith("java")) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unless we are not talking about the same thing, it should, but you will run into issues with complexity if you put too many conditions in that one if.

Yes, I believe we are talking about the same thing :)
Each if only had one condition as shown below. The following wasn't allowed though. I had failing build on local

It was actually observed here..
At first, I roughly used :

if (filename.endsWith("java") {
    if (filename.contains("SuppressionXpathRegression")) {
       // code block
    }
}

An error was reported saying the ifs could be combined, which is obvious

Copy link
Member

Choose a reason for hiding this comment

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

The line you are commenting on is a collapsed nested if, which you said in the first post wasn't acceptable. :)
https://jsparrow.github.io/rules/collapse-if-statements.html#simple-collapse

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, it is good that we check where ifs can be combined. ;)
However, I remember that day vigorously browsing through the codebase for the class/method which checks this.
Still am infact, but I somehow don't seem to find it....

@MANISH-K-07 MANISH-K-07 force-pushed the renameIT branch 3 times, most recently from 59e489f to 5db2585 Compare March 11, 2024 10:28
@MANISH-K-07
Copy link
Contributor Author

MANISH-K-07 commented Mar 11, 2024

To all the maintainers,
Firstly, I am extremely sorry, I don't intend to surpass any of your suggestions.

We need to make sure that other maintainers are on board, but my proposal is this

We still didn't agree on one proposal to tackle this and in this gap, I did my best to help....

From #14595 (comment) :

I am looking at only this issue, which is only file naming convention, and more importantly this PR to understand how this will fit into the overall issue. This PR is only a small part of your first bullet and it wasn't helping me see your goal for this.

@romani , @nrmancuso
@rnveach ,
If I had an approval of the pattern and my goal, I would have made all required changes to close this issue before itself.
We could leave an ongoing issue like you said, but that would cause timely PRs and frequent reviews for you guys. I know that reviewing my current commit won't be easy, but will be a one time thing So please bear with me :)

One more drawback of leaving this as an open issue is that few old and few new pattern named files would be confusing during GSoC period. I wanted to avoid this.

There are so many files to do and limited time before GSoC, I doubt this can be completed quickly. I don't know your past work, so I am not basing this on any judgement of you but we take time to review and agree.

I agree there were a lot of files to modify ( 997 Files changed !! 3 more and I would have hit 1K 馃槀 ). It took me a lot of time to debug too. However I Managed to complete everything with a successful build in a day and two sleepless nights 馃槄
The thing is I am competitive by nature and actually love challenges. I jump right in when I see one.
Coming to my past work part :

Hope I have grabbed all your good attention now and plan on doing the same going further too ;)
Also, really hope this PR gets merged and solves our issue bcoz it took a lot of sweat and blood 馃槄
I can ensure that my changes have been tested multiple times and are 99.99 % 馃悰 free

@MANISH-K-07
Copy link
Contributor Author

MANISH-K-07 commented Mar 11, 2024

This PR is only a small part of your first bullet and it wasn't helping me see your goal for this.

I have completed the first step in plan of action..
If this is all good, I would like to launch the next 2 bullets mentioned in my approach by creating two new issues

Approach :

  1. Rename all input files of regression area to match InputXpath{CheckName}Xxxx.java
  2. Organize the input files folder-wise like we did in our test folder (second part of issue as mentioned at comment)
  3. Organize the regression tests folder-wise to match the test folder pattern.
  4. Rename google and sun area files to be more specific of functionality (similar to my Issue 14436)

Also, with your approval, I would like to create a two new Issues :

  1. To tackle step-4 (can be ongoing issue similar to my other Issue #14436)
  2. Similar issue for our regression area inputs. While working on this PR, I found a lot of files that were left '....One' or '....1'

As a footnote, I now pretty much have gone through about 80-90 % of our codebase :)

@MANISH-K-07 MANISH-K-07 changed the title Issue #6981: Added new Pattern check for It Regression input file naming convention Issue #6981: Renamed Complete IT Regression codebase & Added new Pattern check for input file naming convention Mar 11, 2024
@rnveach
Copy link
Member

rnveach commented Mar 11, 2024

@MANISH-K-07 I asked for a suppression list at #14595 (comment) and only 1 check to be done , not for all the files to be done in 1 go. Another admin was the one who pinged me what happened here and. I don't believe we can accept this as this PR is too big to review in one go. We prefer smaller PRs as they are easier to review by us.

@romani
Copy link
Member

romani commented Mar 12, 2024

I do not know how to review this PR, github is not able to render it.
can you split it two commits ? one commit is for functional changes of validation and second commit is just massive renaming of all.

I am supporting comment above.

@MANISH-K-07 , please never create massive PRs it is always a problem for both sides, and it almost always problematic with merge and leakage of side effects.

Copy link
Contributor Author

@MANISH-K-07 MANISH-K-07 left a comment

Choose a reason for hiding this comment

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

We prefer smaller PRs as they are easier to review by us.

@MANISH-K-07 , please never create massive PRs it is always a problem for both sides

Sorry, I'll make sure to keep these in mind 馃毇

can you split it two commits ? one commit is for functional changes of validation and second commit is just massive renaming of all.

Sure, 993 out of 997 files changed are it regression inputs and tests.
Only 4 following files were changed during debug and I will split these into minor commit

@@ -85,7 +85,7 @@
<suppress checks="OuterTypeFilename"
files="[\\/]package-info\.java"/>
<suppress checks="OuterTypeFilename"
files="src[\\/]it[\\/]resources[\\/].*[\\/]SuppressionXpathRegressionOuterTypeFilename.*\.java"/>
files="src[\\/]it[\\/]resources[\\/].*[\\/]InputXpathOuterTypeFilename.*\.java"/>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. checkstyle-resource-suppressions where SuppressionXpathRegressionOuterTypeFilename was being suppressed for OuterTypeFilename check. Had to change the suppression here to new naming.

@@ -8,7 +8,7 @@

package com.puppycrawl.tools.checkstyle.checks.blocks.avoidnestedblocks;

import static org.checkstyle.suppressionxpathfilter.interfaceistype.SuppressionXpathRegressionInterfaceIsType1.a;
import static org.checkstyle.suppressionxpathfilter.interfaceistype.InputXpathInterfaceIsType1.a;

// xdoc section -- start
public class Example1 {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. avoidnestedblocks/Example1.java was importing a file from it folder. Had to change import with new name.

@@ -10,7 +10,7 @@

package com.puppycrawl.tools.checkstyle.checks.blocks.avoidnestedblocks;

import static org.checkstyle.suppressionxpathfilter.interfaceistype.SuppressionXpathRegressionInterfaceIsType1.a;
import static org.checkstyle.suppressionxpathfilter.interfaceistype.InputXpathInterfaceIsType1.a;

// xdoc section -- start
public class Example2 {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. Same as above. Had to change import with new name in avoidnestedblocks/Example2.java

@@ -264,7 +264,7 @@ public void validateInputFiles() throws Exception {
}

private static void validateInputDirectory(Path checkDir) throws IOException {
final Pattern pattern = Pattern.compile("^SuppressionXpathRegression(.+)\\.java$");
final Pattern pattern = Pattern.compile("^InputXpath(.+)\\.java$");
final String check = ALLOWED_DIRECTORY_AND_CHECKS.get(checkDir.toFile().getName());

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. New pattern has been updated here to be validated

@rnveach
Copy link
Member

rnveach commented Mar 12, 2024

I am not sure why @romani wants 2 commits if he intends all 1k files to stay here (which is what my impression is). I cannot review a 1k file change in any timely matter. I stand by my original statement that we just need the test, suppression, and the 1 example in this PR (2 commits). I would think this would ultimately need to be split among 50 PRs (20 files each) at the minimum. I originally felt that @MANISH-K-07 had better issues to work on then spending so much time on this one.

@rnveach rnveach removed their assignment Mar 12, 2024
@MANISH-K-07 MANISH-K-07 force-pushed the renameIT branch 2 times, most recently from 8840b96 to 690fe2e Compare March 12, 2024 15:58
@MANISH-K-07
Copy link
Contributor Author

I am not sure why @romani wants 2 commits if he intends all 1k files to stay here (which is what my impression is). I cannot review a 1k file change in any timely matter. I stand by my original statement that we just need the test, suppression, and the 1 example in this PR (2 commits). I would think this would ultimately need to be split among 50 PRs (20 files each) at the minimum.

@rnveach , I understand this is not possible to review and have made a mistake. If there isn't any option and this PR is a hard block, then I will revert and proceed with suppression list just like you suggested.

I originally felt that @MANISH-K-07 had better issues to work on then spending so much time on this one.

I actually maintain multiple clones of the project in different directories (atleast 3-4 running on multiple powershells). This way, the time that goes by during mvn validations (usually about an hour and a half or more for all validations), I utilize this time to work parallely on a different issue. Also, this is actually how I manage to spend max time on the project despite university exams and research publications.

@romani
Copy link
Member

romani commented Mar 15, 2024

@rnveach , please review first commit. Let's agree on it. Second commit I can try to review on my next keyboard time, not sure when, but weekend is close.

Can we can merge just renaming before validation (first commit)?

@MANISH-K-07
Copy link
Contributor Author

A new Xpath regression test has been introduced as a result of merging #14639 .
In case this is okay, I will have to fetch--change--push 4 more files to here.

@MANISH-K-07
Copy link
Contributor Author

MANISH-K-07 commented Mar 23, 2024

@MANISH-K-07 , please fix inspection failure https://app.circleci.com/pipelines/github/checkstyle/checkstyle/24586/workflows/183f467a-5b07-4230-bf3e-ac1bfc0511df/jobs/548478/artifacts

<description>Redundant character escape <code>\\}</code> in RegExp</description>

This is not because of changes in this PR. It was a leak in master and fixed by my commit #14658 .
Rebasing should make inspections green.

However, #14639 needs to be applied here, Proof that new pattern is being validated
Let me fix this one

@romani
Copy link
Member

romani commented Mar 23, 2024

Maintainers are ok to continue this PR

@romani romani closed this Mar 23, 2024
@MANISH-K-07
Copy link
Contributor Author

MANISH-K-07 commented Mar 23, 2024

Maintainers are ok to continue this PR

@romani , I didn't understand. Why close the PR then?
I can make all required changes to this PR itself.

@rnveach
Copy link
Member

rnveach commented Mar 23, 2024

@MANISH-K-07 The word "not" was missing from his text.

Like I mentioned at #14595 (comment) and #14595 (comment) , no one can review a 1k change PR.

We are not saying you should abandon your work. We just need it split up like I mentioned previously.

we just need the test, suppression, and the 1 example in this PR (2 commits). I would think this would ultimately need to be split among 50 PRs (20 files each) at the minimum.

@MANISH-K-07
Copy link
Contributor Author

Ohh Okay..
So @rnveach as you suggested, modified test, required suppressions and 1 example as proof is fine by all?
If yes, I'll get it done :)

@MANISH-K-07 MANISH-K-07 deleted the renameIT branch March 23, 2024 16:19
@rnveach
Copy link
Member

rnveach commented Mar 23, 2024

Yes, but be sure it is 2 commits. We expect full suppression list in 1 commit, and then 1 item removed from suppression list in another commit with the test fixes.

@MANISH-K-07

This comment was marked as off-topic.

@MANISH-K-07
Copy link
Contributor Author

@rnveach , from what I see, we will have to validate using RegexpOnFilename if we want to add suppressions ?
The way we are testing pattern right now via XpathRegressionTest#validateInputDirectory, I'm not sure if this can be extended to checkstyle suppressions ? Or am I missing something here?

@rnveach
Copy link
Member

rnveach commented Mar 24, 2024

It is sort of similar to ALLOWED_DIRECTORY_AND_CHECKS but I don't remember why that was specifically created. The value passed to it (checkDir.toFile().getName()) is the check name. We are just skipping over the pattern check completely if the check should be suppressed. We just need a Set of check names that should be suppressed.

@MANISH-K-07
Copy link
Contributor Author

@rnveach @rnveach , PR created at #14713.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants