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

Improve checkstyle performance and readability #53925

Closed
wants to merge 1 commit into from

Conversation

nik9000
Copy link
Member

@nik9000 nik9000 commented Mar 21, 2020

Drop a nasty regex in our checkstyle config that I wrote a long time ago
in favor of a checkstyle extension. This is better because:

  • It is faster. It saves a little more than a minute across the entire
    build.
  • It is easier to read. Who knew 100 lines of Java would be easier to
    read than a regex, but it is.
  • It has tests.

Closes #53921

Drop a nasty regex in our checkstyle config that I wrote a long time ago
in favor of a checkstyle extension. This is better because:
* It is faster. It saves a little more than a minute across the entire
  build.
* It is easier to read. Who knew 100 lines of Java would be easier to
  read than a regex, but it is.
* It has tests.
@@ -0,0 +1,503 @@
GNU LESSER GENERAL PUBLIC LICENSE
Copy link
Member Author

Choose a reason for hiding this comment

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

@tomcallahan could you take a look at this? We depend on checkstyle in the build and this extension is part of the build.

@@ -8,6 +8,7 @@ rootProject.name = dirName
List projects = [
'build-tools',
'build-tools:reaper',
'checkstyle',
Copy link
Member Author

Choose a reason for hiding this comment

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

I did not put this in buildsrc because it looks like the logger usage check to me. I can certainly move it if you'd feel more comfortable with it in the buildSrc but I might need tips on how to reference it in that case.

Copy link
Contributor

Choose a reason for hiding this comment

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

It probably should move as well. It's not production code, but the current configuration is probably just historical.

@rjernst
Copy link
Member

rjernst commented Mar 22, 2020

Please do put the project under buildSrc. We should arrive to have anything build related under there, even in subprojects like reaper.

continue;
}
if (false == line.startsWith(leadingSpaces)) {
log.accept(lines.lastLineNumber, "snippet line should start with [" + leadingSpaces + "]");
Copy link
Contributor

Choose a reason for hiding this comment

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

This log message might be a little confusing as we are just going to print n spaces. Perhaps we should reword this to say that "snippet line should start with n leading spaces" to make it clear that we are talking indent width.

* the page.
*/
public class SnippetLengthCheck extends AbstractFileSetCheck {
private static final Pattern START = Pattern.compile("^( *)//\\s*tag::(.+?)\\s*$", Pattern.MULTILINE);
Copy link
Contributor

Choose a reason for hiding this comment

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

We are we using multiline matchers when we are always matching on individual lines?

Copy link
Member Author

Choose a reason for hiding this comment

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

That makes sense!

@Override
@SuppressForbidden(reason = "Checkstyle's API contain File")
protected void processFiltered(File file, FileText fileText) throws CheckstyleException {
checkFile((line, message) -> log(line, message), max, fileText.toLinesArray());
Copy link
Contributor

Choose a reason for hiding this comment

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

Seems a bit unnecessarily to plum this log function which just maps 1:1 with the log() method of the parent class. Is this just so that these methods can be static? Is there any real benefit to that? Does checkstyle create multiple instances of this?

Copy link
Member Author

Choose a reason for hiding this comment

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

It means I don't have to figure out anything about the way checkstyle works to write the test. I could probably rework it so the test is more checkstyle-native if you'd prefer.

@nik9000
Copy link
Member Author

nik9000 commented Mar 24, 2020

Update for those playing along at home: @mark-vieira is going to see if he can find a nice way to move the new project into buildSrc.

@mark-vieira
Copy link
Contributor

This PR is superseded by #54308.

@mark-vieira mark-vieira added the Team:Delivery Meta label for Delivery team label Nov 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
:Delivery/Build Build or test infrastructure >enhancement Team:Delivery Meta label for Delivery team v7.8.0 v8.0.0-alpha1
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fix Checkstyle SnippetLength Suppressions in HLRC ITs
5 participants