-
Notifications
You must be signed in to change notification settings - Fork 2
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
base: main
Are you sure you want to change the base?
Conversation
final String headerFilePath = config.getProperty(HEADER_FILE_PROPERTY); | ||
header = Files.readString(Path.of(headerFilePath), charsetToUse); | ||
} | ||
} | ||
catch (CheckstyleException | IOException exception) { | ||
catch (IOException exception) { |
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.
Thsi try-catch wraps too much code that doesn't throw exceptions, please include only those code lines that requre this block
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.
else if (config.getParent().hasProperty(CHARSET_PROPERTY)) { | ||
charsetToUse = Charset.forName(config | ||
.getParent().getProperty(CHARSET_PROPERTY)); | ||
} |
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 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.
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.
else { | ||
charsetToUse = charset; | ||
charsetToUse = Charset.defaultCharset(); |
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.
Does it make sense to add getPropertyOrDefault
into config class to handle such cases?
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. simplified the logic.
.map(Integer::parseInt) | ||
.collect(Collectors.toList()); | ||
} | ||
if (!config.hasProperty(IGNORE_LINES_PROPERTY)) { |
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.
Swap this condition with else
. E.g., what's easier to read: if (config.hasProperty(...))
or if (!config.hasProperty(...))
?
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.
|
||
final List<CheckstyleViolation> violations = | ||
CheckstyleReportParser.parse(Path.of(reportPath)); | ||
|
||
return new Header(violations, | ||
extractCheckConfiguration(config, "Header"), getCharset(config)); | ||
final CheckConfiguration checkConfig = config.getChild("Header"); |
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.
- Could you rename
getChild
togetChildConfig
- 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
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're already planning to shift to using CheckstyleAutoFix
directly, so I don't think we'll end up using CheckEnum
.
4d2ba76
to
e6b7f95
Compare
e6b7f95
to
37b3032
Compare
Part of: #50
simplified the implementation by using checkConfiguration in header.