Knockout JS logic as HTML comments causing false-positive

We are using SonarQube Enterprise Edition Version 8.9.6 (build 50800)

Using Knockout without a container element is causing SonarQube to flag KnockoutJS html logic with the code smell - Sections of code should not be commented out (Web:AvoidCommentedOutCodeCheck)

The KnockoutJS documentation has this listed under the Using “if” and “ifnot” without a container element Knockout : The "if" and "ifnot" bindings which uses HTML comments as markers that Knockout uses as virtual elements.

This is an issue of a false positive as the commented out code is required for Knockout logic to work correctly without a container element.

Here is an example of a valid exerpt of code that has been flagged multiple times when using the conditional logic of KnockoutJS

<td>
    //This causes SonarQube to flag an error: Remove this commented out code (Web:AvoidCommentedOutCodeCheck)
    <!-- ko if: EditCode() == "A" || EditCode() == "" -->
    <a data-bind="click: $root.Remove" href="#">
        //This causes SonarQube to flag an error: Remove this commented out code (Web:AvoidCommentedOutCodeCheck)
        <!-- ko if: EditCode() == "A" -->
        <em class="fa fa1 fa-times-circle" title="Delete"></em>
        <!-- /ko  -->
        //This causes SonarQube to flag an error: Remove this commented out code (Web:AvoidCommentedOutCodeCheck)
        <!-- ko if: EditCode().EditCode() == "" -->
        <em class="fa fa1 fa-ban" title="Remove"></em>
        <!-- /ko  -->
    </a>
    <!-- /ko  -->
    //This causes SonarQube to flag an error: Remove this commented out code (Web:AvoidCommentedOutCodeCheck)
    <!-- ko ifnot: EditCode() == "A" || EditCode() == "" -->
    <a data-bind="click: $root.ReActivate" href="#" title="Reactivate/Reset"></a>
    <!-- /ko  -->
</td>

Hi,

Your version is past EOL. You should upgrade to either the latest version or the current LTS at your earliest convenience. Your upgrade path is:

8.9.6 → 9.9.4 → 10.4 (last step optional)

You may find these resources helpful:

If you have questions about upgrading, feel free to open a new thread for that here.

If your issue persists after upgrade, please come back to us.