slevomat / coding-standard

Slevomat Coding Standard for PHP_CodeSniffer provides many useful sniffs
MIT License
1.37k stars 170 forks source link

SlevomatCodingStandard.Commenting.DocCommentSpacing crashes when using annotation groups and double quotes in text before annotations #1643

Open kkmuffme opened 7 months ago

kkmuffme commented 7 months ago

composer show | grep -E "(parser|slevomat)" nikic/php-parser v4.17.1 A PHP parser written in PHP phpstan/phpdoc-parser 1.24.4 PHPDoc parser with support for nullable, intersection and generic types slevomat/coding-standard 8.14.1 Slevomat Coding Standard for PHP_CodeSniffer compl

PHP_CodeSniffer version 3.7.2 (stable)

Running phpcbf with config:

<?xml version="1.0"?>
<ruleset name="debug">
    <description>debugging</description>
    <rule ref="SlevomatCodingStandard.Commenting.DocCommentSpacing">
        <properties>
            <property name="annotationsGroups" type="array">
                <element value="@param"/>
            </property>
        </properties>
    </rule>
</ruleset>

For file: (this seems weird, but this is the minimal reproducer, in reality the code comment makes more sense, but I removed everything that isn't strictly necessary to reproduce the issue)

<?php
/**
 * x - y"
 * z - m"
 *
 * @param string $a
 * @param string $b
 */
function foo($a, $b) {}

It seems similar to https://github.com/slevomat/coding-standard/issues/1608 that the issue happens with the double quotes " (but no backtick in this case, additionally the config is slightly different)

Afaik this issue didn't happen at the time I reported the other issue, so it might be a bug introduced since parse 4.16.0 und 4.17.1 or something in slevomat between 8.13.4 and 8.14.1, but I'm not 100% sure.