Skip to content

Issue #50: Refactored the header recipe to use checkConfiguration #51

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

Part of: #50
simplified the implementation by using checkConfiguration in header.

final String headerFilePath = config.getProperty(HEADER_FILE_PROPERTY);
header = Files.readString(Path.of(headerFilePath), charsetToUse);
}
}
catch (CheckstyleException | IOException exception) {
catch (IOException exception) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Thsi try-catch wraps too much code that doesn't throw exceptions, please include only those code lines that requre this block

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.

Comment on lines 84 to 87
else if (config.getParent().hasProperty(CHARSET_PROPERTY)) {
charsetToUse = Charset.forName(config
.getParent().getProperty(CHARSET_PROPERTY));
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we should make getParent() method private and encapsulate this logic in hasProperty and getProperty. E.g., getProperty internally goes via parents and tryes to find requested property and returns it. This will allow to have simpler contract and easier usage of the config class as the complexity will be hidden.

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.

else {
charsetToUse = charset;
charsetToUse = Charset.defaultCharset();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does it make sense to add getPropertyOrDefault into config class to handle such cases?

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. simplified the logic.

.map(Integer::parseInt)
.collect(Collectors.toList());
}
if (!config.hasProperty(IGNORE_LINES_PROPERTY)) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Swap this condition with else. E.g., what's easier to read: if (config.hasProperty(...)) or if (!config.hasProperty(...)) ?

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.


final List<CheckstyleViolation> violations =
CheckstyleReportParser.parse(Path.of(reportPath));

return new Header(violations,
extractCheckConfiguration(config, "Header"), getCharset(config));
final CheckConfiguration checkConfig = config.getChild("Header");
Copy link
Collaborator

Choose a reason for hiding this comment

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

  1. Could you rename getChild to getChildConfig
  2. Using such hardcoded values "Header" may be error prone, any type or multiple places and we are in trouble. Let's handle this separately, as an option we can create an enum and put there all checks the we have recipes for. Please create and issue for this

Copy link
Collaborator Author

@Anmol202005 Anmol202005 Jul 20, 2025

Choose a reason for hiding this comment

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

We're already planning to shift to using CheckstyleAutoFix directly, so I don't think we'll end up using CheckEnum.

@rdiachenko rdiachenko self-assigned this Jul 19, 2025
@Anmol202005 Anmol202005 force-pushed the UpdateHeader branch 4 times, most recently from 4d2ba76 to e6b7f95 Compare July 20, 2025 08:23
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.

2 participants