-
-
Notifications
You must be signed in to change notification settings - Fork 24
[checkstyle] OnlyTabIndentationCheck, OhInfXmlValidationCheck to report filename #506
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
[checkstyle] OnlyTabIndentationCheck, OhInfXmlValidationCheck to report filename #506
Conversation
Signed-off-by: Holger Friedrich <mail@holger-friedrich.de>
Signed-off-by: Holger Friedrich <mail@holger-friedrich.de>
e5057da to
949a54b
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.
Pull request overview
This PR fixes issue #504 and #507 by ensuring that OnlyTabIndentationCheck and OhInfXmlValidationCheck properly report filenames in test results. The checks now explicitly register files with the message dispatcher before logging violations, and the XSLT report preparation has been enhanced to handle XML files (beyond just feature.xml) with improved path extraction logic that correctly identifies the last occurrence of /src/ in file paths.
- Added
MessageDispatcherlifecycle management to checkstyle checks to ensure filenames are properly reported - Enhanced XSLT path extraction to handle all XML files and correctly extract parent directory names
- Fixed path construction to find the last occurrence of
/src/instead of the first, avoiding issues with checkout paths namedsrc
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| sat-plugin/src/main/resources/report/prepare_checkstyle.xslt | Enhanced path extraction logic to process all XML files (not just feature.xml) and correctly find the last /src/ occurrence for proper path reporting |
| custom-checks/checkstyle/src/main/java/org/openhab/tools/analysis/checkstyle/api/AbstractOhInfXmlCheck.java | Added MessageDispatcher lifecycle calls to ensure empty XML files are properly reported with filenames |
| custom-checks/checkstyle/src/main/java/org/openhab/tools/analysis/checkstyle/OnlyTabIndentationCheck.java | Added MessageDispatcher lifecycle calls to ensure tab indentation violations include proper filenames in reports |
| custom-checks/checkstyle/src/main/java/org/openhab/tools/analysis/checkstyle/OhInfXmlValidationCheck.java | Added MessageDispatcher lifecycle calls to ensure XML validation errors include proper filenames in reports |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| <xsl:variable name="before_last_src" select="substring-before($temp_name, concat('/src/', $after_last_src))" /> | ||
| <xsl:variable name="parent"> | ||
| <xsl:choose> | ||
| <xsl:when test="string-length($before_last_src) > 0"> | ||
| <xsl:call-template name="substring-after-last"> | ||
| <xsl:with-param name="input" select="$before_last_src" /> | ||
| <xsl:with-param name="marker" select="'/'" /> | ||
| </xsl:call-template> | ||
| </xsl:when> | ||
| <xsl:otherwise /> | ||
| </xsl:choose> | ||
| </xsl:variable> | ||
| <xsl:choose> | ||
| <xsl:when test="string-length($parent) > 0"> | ||
| <xsl:value-of select="concat($parent, '/src/', $after_last_src)" /> | ||
| </xsl:when> | ||
| <xsl:otherwise> | ||
| <xsl:value-of select="concat('src/', $after_last_src)" /> |
Copilot
AI
Dec 4, 2025
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.
The substring-before operation on line 48 could fail if $after_last_src is empty or if the path doesn't contain /src/ at all. When substring-before doesn't find the search string, it returns an empty string, which could lead to incorrect path construction.
Consider adding a check to verify that $after_last_src is not empty before using it in the substring-before operation, or handle the case where /src/ is not found in the path.
| <xsl:variable name="before_last_src" select="substring-before($temp_name, concat('/src/', $after_last_src))" /> | |
| <xsl:variable name="parent"> | |
| <xsl:choose> | |
| <xsl:when test="string-length($before_last_src) > 0"> | |
| <xsl:call-template name="substring-after-last"> | |
| <xsl:with-param name="input" select="$before_last_src" /> | |
| <xsl:with-param name="marker" select="'/'" /> | |
| </xsl:call-template> | |
| </xsl:when> | |
| <xsl:otherwise /> | |
| </xsl:choose> | |
| </xsl:variable> | |
| <xsl:choose> | |
| <xsl:when test="string-length($parent) > 0"> | |
| <xsl:value-of select="concat($parent, '/src/', $after_last_src)" /> | |
| </xsl:when> | |
| <xsl:otherwise> | |
| <xsl:value-of select="concat('src/', $after_last_src)" /> | |
| <xsl:choose> | |
| <xsl:when test="string-length($after_last_src) > 0"> | |
| <xsl:variable name="before_last_src" select="substring-before($temp_name, concat('/src/', $after_last_src))" /> | |
| <xsl:variable name="parent"> | |
| <xsl:choose> | |
| <xsl:when test="string-length($before_last_src) > 0"> | |
| <xsl:call-template name="substring-after-last"> | |
| <xsl:with-param name="input" select="$before_last_src" /> | |
| <xsl:with-param name="marker" select="'/'" /> | |
| </xsl:call-template> | |
| </xsl:when> | |
| <xsl:otherwise /> | |
| </xsl:choose> | |
| </xsl:variable> | |
| <xsl:choose> | |
| <xsl:when test="string-length($parent) > 0"> | |
| <xsl:value-of select="concat($parent, '/src/', $after_last_src)" /> | |
| </xsl:when> | |
| <xsl:otherwise> | |
| <xsl:value-of select="concat('src/', $after_last_src)" /> | |
| </xsl:otherwise> | |
| </xsl:choose> | |
| </xsl:when> | |
| <xsl:otherwise> | |
| <!-- /src/ not found, fallback to original name or handle as needed --> | |
| <xsl:value-of select="@name" /> |
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 would not expect the tool to run outside if the src folder.
.../checkstyle/src/main/java/org/openhab/tools/analysis/checkstyle/OhInfXmlValidationCheck.java
Outdated
Show resolved
Hide resolved
...heckstyle/src/main/java/org/openhab/tools/analysis/checkstyle/api/AbstractOhInfXmlCheck.java
Outdated
Show resolved
Hide resolved
.../checkstyle/src/main/java/org/openhab/tools/analysis/checkstyle/OnlyTabIndentationCheck.java
Outdated
Show resolved
Hide resolved
Signed-off-by: Holger Friedrich <mail@holger-friedrich.de>
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.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
wborn
left a comment
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.
Is there a reason AbstractStaticCheck.logMessage cannot be used instead?
Signed-off-by: Holger Friedrich <mail@holger-friedrich.de>
@wborn, good catch, now it is much cleaner and the dispatcher is only called in one method of the base class. I am not sure where if I should use getAbsolutePath or getPath, but now use getAbsoultePath after some previous comments from copilot. |
wborn
left a comment
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 the fix!
Fixes #504. Fixes #507.
Obsoletes #505.
OnlyTabIndentationCheckreported findings, but did not add a proper file name to the test result, as it did not call the methods to register the current file under test.Fixing this did not help much to identify the affected binding (filename was added to the report, but without path - you still could not determine the binding with the violation).
It turned out that merge configuration for creating the report removed the path completely.
I have now included *.xml - not only feature.xml to be processed by the following step.
Taking the full file name with path, the last occurrence of
srcis searched (previously the first one matched, bad luck if your checkout path is calledsrc). The reported filename starts with the parent path, found beforesrc.Testing this fix is only possible if you change the checkstyle rule in
src/main/resources/rulesets/checkstyle/rule.xmlfrom error to warning. Otherwise the build will fail (it previously did not, as the file name was not reported).If you do, the report will look like this: