Skip to content

Conversation

@holgerfriedrich
Copy link
Member

@holgerfriedrich holgerfriedrich commented Dec 2, 2025

Fixes #504. Fixes #507.
Obsoletes #505.

OnlyTabIndentationCheck reported 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 src is searched (previously the first one matched, bad luck if your checkout path is called src). The reported filename starts with the parent path, found before src.

Testing this fix is only possible if you change the checkstyle rule in src/main/resources/rulesets/checkstyle/rule.xml from 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:

grafik

@holgerfriedrich holgerfriedrich requested a review from a team as a code owner December 2, 2025 00:17
@holgerfriedrich holgerfriedrich changed the title [checkstyle] OnlyTabIndentationCheck to report filename [checkstyle] OnlyTabIndentationCheck, OhInfXmlValidationCheck to report filename Dec 2, 2025
Signed-off-by: Holger Friedrich <mail@holger-friedrich.de>
Signed-off-by: Holger Friedrich <mail@holger-friedrich.de>
Copy link

Copilot AI left a 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 MessageDispatcher lifecycle 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 named src

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.

Comment on lines +48 to +65
<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) &gt; 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) &gt; 0">
<xsl:value-of select="concat($parent, '/src/', $after_last_src)" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat('src/', $after_last_src)" />
Copy link

Copilot AI Dec 4, 2025

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.

Suggested change
<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) &gt; 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) &gt; 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) &gt; 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) &gt; 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) &gt; 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" />

Copilot uses AI. Check for mistakes.
Copy link
Member Author

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.

Signed-off-by: Holger Friedrich <mail@holger-friedrich.de>
Copy link

Copilot AI left a 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.

@holgerfriedrich holgerfriedrich mentioned this pull request Dec 5, 2025
Copy link
Member

@wborn wborn left a 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>
@holgerfriedrich
Copy link
Member Author

Is there a reason AbstractStaticCheck.logMessage cannot be used instead?

@wborn, good catch, now it is much cleaner and the dispatcher is only called in one method of the base class.
I removed the duplication also in one of the files I did not modify before.

I am not sure where if I should use getAbsolutePath or getPath, but now use getAbsoultePath after some previous comments from copilot.

Copy link
Member

@wborn wborn 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 the fix!

@wborn wborn merged commit 83d608e into openhab:main Dec 12, 2025
2 checks passed
@wborn wborn added the bug An unexpected problem or unintended behavior of the tools label Dec 12, 2025
@wborn wborn added this to the 0.18.0 milestone Dec 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug An unexpected problem or unintended behavior of the tools

Projects

None yet

Development

Successfully merging this pull request may close these issues.

OhInfXmlValidationCheck does not report file name OnlyTabIndentationCheck does not report file name

2 participants