-
Notifications
You must be signed in to change notification settings - Fork 2
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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
@rdiachenko missed it, on it now. |
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. |
public class CheckstyleConfigParser { | ||
|
||
/** Constant for the module XML tag name. */ | ||
private static final String MODULE_TAG = "module"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and it immeditate points to property handler to be provided.
yes |
e9d5836
to
920b16e
Compare
There was a problem hiding this 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?
@rdiachenko done. |
@rdiachenko I have refactored and made the implementation straight forward no more complex logic now. with tests :) |
src/main/java/org/checkstyle/autofix/data/CheckstyleRecord.java
Outdated
Show resolved
Hide resolved
src/main/java/org/checkstyle/autofix/parser/EmptyXmlEventReader.java
Outdated
Show resolved
Hide resolved
src/main/java/org/checkstyle/autofix/parser/CheckstyleReportsParser.java
Outdated
Show resolved
Hide resolved
44410af
to
c770823
Compare
src/main/java/org/checkstyle/autofix/data/CheckstyleRecord.java
Outdated
Show resolved
Hide resolved
src/main/java/org/checkstyle/autofix/data/CheckstyleRecord.java
Outdated
Show resolved
Hide resolved
src/main/java/org/checkstyle/autofix/parser/CheckstyleReportsParser.java
Outdated
Show resolved
Hide resolved
src/main/java/org/checkstyle/autofix/parser/CheckstyleReportsParser.java
Outdated
Show resolved
Hide resolved
src/main/java/org/checkstyle/autofix/parser/CheckstyleReportsParser.java
Outdated
Show resolved
Hide resolved
src/main/java/org/checkstyle/autofix/parser/CheckstyleReportsParser.java
Outdated
Show resolved
Hide resolved
79c939d
to
ffa27fc
Compare
src/main/java/org/checkstyle/autofix/parser/CheckstyleRecord.java
Outdated
Show resolved
Hide resolved
src/main/java/org/checkstyle/autofix/parser/CheckstyleReportsParser.java
Outdated
Show resolved
Hide resolved
src/main/java/org/checkstyle/autofix/parser/CheckstyleReportsParser.java
Outdated
Show resolved
Hide resolved
src/main/java/org/checkstyle/autofix/parser/CheckstyleReportsParser.java
Outdated
Show resolved
Hide resolved
src/main/java/org/checkstyle/autofix/parser/CheckstyleRecord.java
Outdated
Show resolved
Hide resolved
src/main/java/org/checkstyle/autofix/parser/CheckstyleReportsParser.java
Outdated
Show resolved
Hide resolved
src/main/java/org/checkstyle/autofix/parser/CheckstyleReportsParser.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this 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, |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
final
?
There was a problem hiding this comment.
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(); |
There was a problem hiding this comment.
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();
}
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<!-- Checkstyle dependency for parsing Checkstyle configs --> | ||
<!-- <dependency>--> | ||
<!-- <groupId>com.puppycrawl.tools</groupId>--> | ||
<!-- <artifactId>checkstyle</artifactId>--> | ||
<!-- <version>${checkstyle.version}</version>--> | ||
<!-- </dependency>--> | ||
|
There was a problem hiding this comment.
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
Fixes: #15
Implemented Checkstyle Config Parser and violation report parser.