Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Less files: valid Less contruction parsing issue #434

Open
JuiceBlynskyi opened this issue Jan 31, 2023 · 1 comment · May be fixed by #441
Open

Less files: valid Less contruction parsing issue #434

JuiceBlynskyi opened this issue Jan 31, 2023 · 1 comment · May be fixed by #441
Labels
bug Something isn't working Progress: PR created

Comments

@JuiceBlynskyi
Copy link

Preconditions

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

.mixin-example(input-box)
  1. Magento v2.4.5-p1
  2. PHP v8.1
  3. 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
@JuiceBlynskyi JuiceBlynskyi added the bug Something isn't working label Jan 31, 2023
@m2-assistant
Copy link

m2-assistant bot commented Jan 31, 2023

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


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Progress: PR created
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant