Skip to content

Implemented Report and Config Parsner #16

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Anmol202005
Copy link
Collaborator

Fixes: #15

Implemented Checkstyle Config Parser and violation report parser.

Copy link
Collaborator

@rdiachenko rdiachenko left a comment

Choose a reason for hiding this comment

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

@Anmol202005 please read this comment if you missed it #8 (comment)

We want to reuse parsing logic if it is already present

@Anmol202005
Copy link
Collaborator Author

@Anmol202005 please read this comment if you missed it #8 (comment)

We want to reuse parsing logic if it is already present

@rdiachenko missed it, on it now.

@romani
Copy link
Member

romani commented Jun 15, 2025

checksyle config parser is present in checkstyle jar, just reuse it.

Checkstyle report parser is missed in checkstyle jar, please look around in web, there should some parser already done.

Comment on lines 19 to 22
public class CheckstyleConfigParser {

/** Constant for the module XML tag name. */
private static final String MODULE_TAG = "module";
Copy link
Member

Choose a reason for hiding this comment

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

@Anmol202005
Copy link
Collaborator Author

@romani
Copy link
Member

romani commented Jun 15, 2025

yes

@Anmol202005 Anmol202005 force-pushed the parser branch 2 times, most recently from e9d5836 to 920b16e Compare June 18, 2025 11:24
Copy link
Collaborator

@rdiachenko rdiachenko left a comment

Choose a reason for hiding this comment

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

@Anmol202005 I don't understand why we need all this complex logic? We should go with the smallest working solution and add functionality only when we need it. Please remove everything not relevant to parsing logic.

Additionally, where are the tests?

@Anmol202005
Copy link
Collaborator Author

@rdiachenko done.

@Anmol202005
Copy link
Collaborator Author

Anmol202005 commented Jun 20, 2025

@rdiachenko I have refactored and made the implementation straight forward no more complex logic now.

with tests :)

@rdiachenko rdiachenko self-assigned this Jun 20, 2025
@Anmol202005 Anmol202005 force-pushed the parser branch 2 times, most recently from 44410af to c770823 Compare June 22, 2025 13:43
@Anmol202005 Anmol202005 force-pushed the parser branch 2 times, most recently from 79c939d to ffa27fc Compare June 23, 2025 08:19
@rdiachenko rdiachenko requested a review from timurt June 24, 2025 18:48
Copy link
Collaborator

@timurt timurt left a comment

Choose a reason for hiding this comment

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

Thanks for your work, added comments!


private String fileName;

public CheckstyleRecord(int line, int column,
Copy link
Collaborator

Choose a reason for hiding this comment

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

I see that the default value is -1 and also sometimes a violation contains only a line of information, missing column information

I would prefer to have an explicit nullable type, ex Integer instead of int

What do you think?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done.

public CheckstyleRecord(int line, int column,
String severity, String source, String message, String fileName) {
this.line = line;
this.column = column;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Additionally, I might be wrong again

I recall that the AST line and column don't match one-to-one with the violation message, just because there are tabs

We have this conversion from the AST column to the violation column link

        final int col = 1 + CommonUtil.lengthExpandedTabs(
        fileContext.fileContents.getLine(lineNo - 1), colNo, tabWidth);

Do you reckon we should store tabWidth information?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

IMO we can consider it for another issue while implementing columns calculations in recipes.
additionally how are we going to input tabWidth information.


private final String message;

private String fileName;
Copy link
Collaborator

Choose a reason for hiding this comment

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

final?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

done.

while (attributes.hasNext()) {
final Attribute attribute = attributes.next();
if (FILENAME_ATTR.equals(attribute.getName().toString())) {
fileName = attribute.getValue();
Copy link
Collaborator

Choose a reason for hiding this comment

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

It depends on preferences, but I would early-exit right away here without iterating till the end of the cycle

            if (FILENAME_ATTR.equals(attribute.getName().getLocalPart())) {
                return attribute.getValue();
            }

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We do have a break;
am i missing something.

this.severity = severity;
this.source = source;
this.message = message;
this.fileName = fileName;
Copy link
Collaborator

Choose a reason for hiding this comment

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

By looking at the logic, it is quite possible that fileName is a nullable field

Is it okay? Or is it impossible?
Can we maybe explicitly add @Nullable annotation to nullable fields?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

In a real report it can never be null.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@romani @timurt
We don't expect any field to be null unless there is a misconfiguration in the config.
Am i missing something??

Comment on lines +48 to +54
<!-- Checkstyle dependency for parsing Checkstyle configs -->
<!-- <dependency>-->
<!-- <groupId>com.puppycrawl.tools</groupId>-->
<!-- <artifactId>checkstyle</artifactId>-->
<!-- <version>${checkstyle.version}</version>-->
<!-- </dependency>-->

Copy link
Collaborator

Choose a reason for hiding this comment

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

Please remove it if not needed, we shouldn't have commented out code

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.

Implement Checkstyle violation report parser and config parser.
4 participants