coding-standard icon indicating copy to clipboard operation
coding-standard copied to clipboard

Add Utf8 support for LineLengthFixer

Open avdeev-ms opened this issue 2 years ago • 3 comments

No utf8 support for LineLengthFixer. The length of the strings is not correctly calculated, because of this, an extra line break is set, where it is not necessary.

The solution would be \Symplify\CodingStandard\TokenRunner\Transformer\FixerTransformer\FirstLineLengthResolver class to use the mb_strlen function instead of strlen, or be able to configure this behavior

avdeev-ms avatar Feb 07 '23 09:02 avdeev-ms

Could you share exact code of where current behavior fails?

TomasVotruba avatar Feb 07 '23 10:02 TomasVotruba

Setting LineLengthFixer in ecs config (no inline_short_lines, default line length: 120):

$services->set(LineLengthFixer::class)->call(
    'configure',
    [
        [
            'inline_short_lines' => false,
        ],
    ]
);

Run ecs on code example

class Example
{
    public function decline()
    {
        //a line break will be inserted here
        $this->getDefaultHttpException('Извините, произошла ошибка. Попробуйте позже.');
        //no line break will be inserted here
        $this->getDefaultHttpException('Sorry, an unexpected error occurred. Please try later.');
    }
}

The result will be

         //a line break will be inserted here
-        $this->getDefaultHttpException('Извините, произошла ошибка. Попробуйте позже.');
+        $this->getDefaultHttpException(
+            'Извините, произошла ошибка. Попробуйте позже.',
+        );
         //no line break will be inserted here
         $this->getDefaultHttpException('Sorry, an unexpected error occurred. Please try later.');

avdeev-ms avatar Feb 08 '23 03:02 avdeev-ms

I see, it seems valid. Feel free to add this feature with the test fixture you've provided :+1:

TomasVotruba avatar Feb 08 '23 09:02 TomasVotruba