Skip to content

[BUG] LineLengthSniff RegEx misses long lines with Phrase/__ keyword in string #75

Closed
@mzeis

Description

@mzeis

Preconditions

  1. Use fix from #6: Fix line length sniff when using translations #74 (original implementation of the sniff is broken)

Steps to reproduce

  1. in Magento2/Tests/Files/LineLengthUnitTest.inc, add this line:

    $test = "If a string exceeds 120 characters and a part of the string is Phrase('xy'), this would not be caught by the regular expression because it matches any line containing Phrase('xy') or __('xy').";
    
  2. Run vendor/bin/phpunit

Expected result

  1. An error as the line contains no translation but only the keywords "Phrase" and "__" inside a string, e.g.

    PHPUnit 5.7.27 by Sebastian Bergmann and contributors.
    
    ..........F....................                                   31 / 31 (100%)
    
    Time: 441 ms, Memory: 14.00MB
    
    There was 1 failure:
    
    1) Magento2\Tests\Files\LineLengthUnitTest::testSniff
    [LINE 32] Expected 0 error(s) in LineLengthUnitTest.inc but found 1 error(s). The error(s) found were:
     -> Line exceeds maximum limit of 120 characters; contains 202 characters (Magento2.Files.LineLength.MaxExceeded)
    
    /home/matthias/PhpstormProjects/magento-coding-standard/vendor/squizlabs/php_codesniffer/tests/Standards/AbstractSniffUnitTest.php:205
    
    FAILURES!
    Tests: 31, Assertions: 0, Failures: 1.
    

Actual result

  1. The long string is missed:

    PHPUnit 5.7.27 by Sebastian Bergmann and contributors.
    
    ...............................                                   31 / 31 (100%)
    
    Time: 519 ms, Memory: 14.00MB
    
    OK (31 tests, 0 assertions)
    

Metadata

Metadata

Labels

acceptedNew rule is acceptedbugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions