Commented out code false positive for markdown in comment blocks for PHP

We’re using php-swagger for OpenAPI annotations, but sonarcloud/sonarlint detects comment blocks as a code-smell under rule php:S125 if using the description+markdown from comments extraction support.

This example triggers the code smell and the entire comment block gets marked as commented out code under rule php:S125. After further investigation it seems that the ## Header is what is triggering the code-smell.

use OpenApi\Annotations as OA;

class ExampleController {

    /**
     * ## The example endpoint.
     *
     * This *demonstrates* issues with OpenAPI documentation while using [SonarLint](https://community.sonarsource.com/).
     *
     * @OA\Get(
     *     path="/api/some/endpoint",
     *     operationId="getSomeEndpoint",
     *     tags={"Example"},
     *     summary="Does something",
     *     description="One-line markdown is not fun"
     *     @OA\Response(
     *         response=201,
     *         description="Successfully succeeded"
     *     )
     * )
     *
     * @return void
     */
    public function getSomething(): void
    {
        //
    }
}

This example does not trigger a code-smell.

use OpenApi\Annotations as OA;

class ExampleController {

    /**
     * *This* is apparently fine with SonarCloud/Lint.
     *
     * @OA\Get(
     *     path="/api/some/endpoint",
     *     operationId="getSomeEndpoint",
     *     tags={"Example"},
     *     summary="Does something",
     *     description="One-line markdown is not fun"
     *     @OA\Response(
     *         response=201,
     *         description="Successfully succeeded"
     *     )
     * )
     *
     * @return void
     */
    public function getSomething(): void
    {
        //
    }
}

The library used for annotations:

Edit: I did some further investigation, and it seems that the markdown headers is what triggers the code-smell, and potentially other markdown syntax. Updated the description and title to reflect that.

Hallo @faylite,

thank you for your report and your extensive reproducers.
Indeed, it is not expected to raise an S125 issue in the case you presented.
I created a ticket to address the issue. It will be part of the next release.

Best,
Nils

1 Like

Great, will be looking forward to a fix!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.