Conversation
|
|
This PR is stale because it has been open 7 days with no activity. If there is no activity in the next 7 days it will be closed automatically |
GabrielFleischer
left a comment
There was a problem hiding this comment.
I think your method is a bit too broad and trim too many TPs.
I provided you with a moretest cases.
sonar-xml-plugin/src/main/java/org/sonar/plugins/xml/checks/IndentationCheck.java
Outdated
Show resolved
Hide resolved
sonar-xml-plugin/src/test/resources/checks/IndentationCheck/LineContinuation.xml
Show resolved
Hide resolved
sonar-xml-plugin/src/main/java/org/sonar/plugins/xml/checks/IndentationCheck.java
Outdated
Show resolved
Hide resolved
|
I spent way too much time on it and it looks fixing it would be more complicated than initially expected. |
GabrielFleischer
left a comment
There was a problem hiding this comment.
As discussed, I join you on the fact that the lost FPs provide more value than the lost TPs.
So, LGTM
I still thing the comment explaining the exception would be better by using whitespaces rather than -, but this is nitpicky.
good catch, I applied the suggestion |
|
dorian-burihabwa-sonarsource
left a comment
There was a problem hiding this comment.
Blocking to keep out of release 2.15
|
This PR is stale because it has been open 7 days with no activity. If there is no activity in the next 7 days it will be closed automatically |
dorian-burihabwa-sonarsource
left a comment
There was a problem hiding this comment.
The solution looks pretty good but I have left a couple of style suggestions that I think could help with readability and coverage
sonar-xml-plugin/src/test/java/org/sonar/plugins/xml/checks/IndentationCheckTest.java
Outdated
Show resolved
Hide resolved
sonar-xml-plugin/src/main/java/org/sonar/plugins/xml/checks/IndentationCheck.java
Show resolved
Hide resolved
sonar-xml-plugin/src/main/java/org/sonar/plugins/xml/checks/IndentationCheck.java
Outdated
Show resolved
Hide resolved
sonar-xml-plugin/src/main/java/org/sonar/plugins/xml/checks/IndentationCheck.java
Outdated
Show resolved
Hide resolved
- refactoring needed
Revert "Draft of full solution not trimming too many FP" This reverts commit b604297. Revert "Refactoring : split test into MultilineString.xml and LineContinuation.xml" This reverts commit 0c9cc3e. Revert "Refactoring tests - use parametrized tests" This reverts commit e10bfa4. Revert "Refactoring - clean IndentationCheck.java" This reverts commit 43af5f0. Revert "Refactoring & behavior fix, add non-trivial tests" This reverts commit 300ab87. Revert "Fix qg" This reverts commit 653a104. Revert "Fix plugin test" This reverts commit 4194663. Revert "Continue small fixes and edge case tests" This reverts commit 712666c.
Co-authored-by: Gabriel Fleischer <gabriel.fleischer@sonarsource.com>
e8016e3 to
486bf40
Compare
dorian-burihabwa-sonarsource
left a comment
There was a problem hiding this comment.
LGTM 👍🏿 I just left a nitpicking comment on returning earlier. Feel free to address the issue with the trim vs strip
| boolean isTextContent = element.getChildNodes().getLength() == 1 && element.getFirstChild() instanceof Text; | ||
| boolean isTextContinuingOnClosingTagLine = false; | ||
| if (isTextContent) { | ||
| String text = element.getFirstChild().getNodeValue(); | ||
| String lastLine = text.lines().reduce((first, second) -> second).orElse(""); | ||
| isTextContinuingOnClosingTagLine = !lastLine.trim().isEmpty(); | ||
| } |
There was a problem hiding this comment.
Nitpick: To keep with the early return theme, we can probably return earlier if we know that the node does not contain only text content.
| boolean isTextContent = element.getChildNodes().getLength() == 1 && element.getFirstChild() instanceof Text; | |
| boolean isTextContinuingOnClosingTagLine = false; | |
| if (isTextContent) { | |
| String text = element.getFirstChild().getNodeValue(); | |
| String lastLine = text.lines().reduce((first, second) -> second).orElse(""); | |
| isTextContinuingOnClosingTagLine = !lastLine.trim().isEmpty(); | |
| } | |
| boolean isTextContent = element.getChildNodes().getLength() == 1 && element.getFirstChild() instanceof Text; | |
| if (!isTextContent) { | |
| return; | |
| } | |
| String text = element.getFirstChild().getNodeValue(); | |
| String lastLine = text.lines().reduce((ignored, second) -> second).orElse(""); | |
| boolean isTextContinuingOnClosingTagLine = !lastLine.trim().isEmpty(); |
There was a problem hiding this comment.
This solution is not equivalent, when isTextContent is false, the function returns immediatly, while it is supposed to raise at line 199 (for any non-text content closing tag indentation is no longer checked)
There was a problem hiding this comment.
proposed another refactoring of this
|




Important notes
As noted in Gabriel's review, this PR will trim a few True Positives (TPs) in specific scenarios like the one below:
Current Context & Rationale
Currently, an issue is reported on the closing tag (
</string>) for the wrong reason.Why I chose not to implement the "Proper Check"
While Gabriel proposed checking string content indentation properly, I have decided to keep string content ignored in
IndentationCheck. I believe this remains the best option for the following reasons:Line ContinuationsandMultiline Strings), XML is frequently used to wrap raw data or code snippets (like the example below). In these cases, standard indentation rules are often not relevant.By maintaining the exclusion of string content from the check, and keeping the trivial check, we avoid reporting "accidental" issues on closing tags while preventing a high volume of False Positives in files containing embedded scripts or formatted text.