magento / magento-coding-standard

Magento Coding Standard
Open Software License 3.0
349 stars 153 forks source link

Less files: valid Less contruction parsing issue #434

Open JuiceBlynskyi opened 1 year ago

JuiceBlynskyi commented 1 year ago

Preconditions

  1. Example of the less file
    
    .mixin-example(@my-selector) {
    .@{my-selector} {
    background: #fff
    }
    }

.mixin-example(input-box)


2. Magento v2.4.5-p1
3. PHP v8.1
4. magento/magento-coding-standart v29

### Steps to reproduce
vendor/bin/phpcs --standart=Magento2 app/code/MyModule

### Expected result
No errors

### Actual result
Fatal PHP error:

PHP Fatal error: Uncaught ValueError: strpos(): Argument #3 ($offset) must be contained in argument #1 ($haystack) in /var/www/html/vendor/magento/magento-coding-standard/Magento2/Sniffs/Less/ClassNamingSniff.php:69 Stack trace:

0 /var/www/html/vendor/magento/magento-coding-standard/Magento2/Sniffs/Less/ClassNamingSniff.php(69): strpos('@', '_', 2)

1 /var/www/html/vendor/squizlabs/php_codesniffer/src/Files/File.php(498): Magento2\Sniffs\Less\ClassNamingSniff->process()

2 /var/www/html/vendor/squizlabs/php_codesniffer/src/Files/LocalFile.php(92): PHP_CodeSniffer\Files\File->process()

3 /var/www/html/vendor/squizlabs/php_codesniffer/src/Runner.php(628): PHP_CodeSniffer\Files\LocalFile->process()

4 /var/www/html/vendor/squizlabs/php_codesniffer/src/Runner.php(434): PHP_CodeSniffer\Runner->processFile()

5 /var/www/html/vendor/squizlabs/php_codesniffer/src/Runner.php(114): PHP_CodeSniffer\Runner->run()

6 /var/www/html/vendor/squizlabs/php_codesniffer/bin/phpcs(18): PHP_CodeSniffer\Runner->runPHPCS()

7 {main}

thrown in /var/www/html/vendor/magento/magento-coding-standard/Magento2/Sniffs/Less/ClassNamingSniff.php on line 69



### Additional description
The similar error was described in the other issue ( #425 ). But in that case, the problem relates directly to the length of the class name in one character (".a" is expected).
However, this report shows that the problem may be more global. In this example, a common construction of the LESS library is used. It allows usage the parameter of the mixin as a selector for the class name (link to the official LESS documentation, which confirms the validity of this construction: https://lesscss.org/features/#variables-feature-variable-interpolation).
**The parser treats the "@" symbol as a class name, when in fact it is not.**
I may be using an outdated version of the module "magento/magento-coding-standart" (v29), though I haven't found a newer one for Magento v2.4.5-p1.
Please, if it's not difficult, fix this bug, if it is.
Please suggest a temporary workaround for this issue.

Also, it may be useful:
- this error was not reproduced in Magento v2.4.3-p1, PHP v7.4, magento/magento-coding-standart v6
m2-assistant[bot] commented 1 year ago

Hi @JuiceBlynskyi. Thank you for your report. To speed up processing of this issue, make sure that you provided sufficient information.

Add a comment to assign the issue: @magento I am working on this