Open gwharton opened 2 months ago
Hi @gwharton. 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
Join Magento Community Engineering Slack and ask your questions in #github channel.
FYI, the full set of sniffs I tested for regex match was
vendor/bin/phpcs --sniffs=Magento2.Legacy.ObsoleteConfigNodes --standard=Magento2 etc/config.xml
vendor/bin/phpcs --sniffs=Magento2.Legacy.ObsoleteConfigNodes --standard=Magento2 etc/config.anything.xml
vendor/bin/phpcs --sniffs=Magento2.Legacy.ObsoleteConfigNodes --standard=Magento2 etc/anything/config.xml
vendor/bin/phpcs --sniffs=Magento2.PHP.AutogeneratedClassNotInConstructor --standard=Magento2 test.php
vendor/bin/phpcs --sniffs=Magento2.Html.HtmlCollapsibleAttribute --standard=Magento2 test.html
vendor/bin/phpcs --sniffs=Magento2.Html.HtmlCollapsibleAttribute --standard=Magento2 test.phtml
vendor/bin/phpcs --sniffs=Magento2.Legacy.Layout --standard=Magento2 anything/view/adminhtml/anything/test.xml
vendor/bin/phpcs --sniffs=Magento2.Legacy.ClassReferencesInConfigurationFiles --standard=Magento2 anything/etc/test.xml
vendor/bin/phpcs --sniffs=Magento2.Security.XssTemplate --standard=Magento2 test.phtml
vendor/bin/phpcs --sniffs=Magento2.Html.HtmlBinding --standard=Magento2 test.phtml
vendor/bin/phpcs --sniffs=Magento2.Templates.ThisInTemplate --standard=Magento2 test.phtml
vendor/bin/phpcs --sniffs=Magento2.Legacy.ModuleXML --standard=Magento2 anything/module.xml
vendor/bin/phpcs --sniffs=Magento2.Legacy.DiConfig --standard=Magento2 anything/di.xml
vendor/bin/phpcs --sniffs=Magento2.Legacy.WidgetXML --standard=Magento2 anything/widget.xml
vendor/bin/phpcs --sniffs=Magento2.Legacy.ObsoleteAcl --standard=Magento2 etc/config.xml
vendor/bin/phpcs --sniffs=Magento2.Legacy.ObsoleteAcl --standard=Magento2 etc/config.anything.xml
vendor/bin/phpcs --sniffs=Magento2.Legacy.ObsoleteAcl --standard=Magento2 etc/anything/config.xml
vendor/bin/phpcs --sniffs=Magento2.Legacy.ObsoleteMenu --standard=Magento2 etc/config.xml
vendor/bin/phpcs --sniffs=Magento2.Legacy.ObsoleteMenu --standard=Magento2 etc/config.anything.xml
vendor/bin/phpcs --sniffs=Magento2.Legacy.ObsoleteMenu --standard=Magento2 etc/anything/config.xml
vendor/bin/phpcs --sniffs=Magento2.Legacy.ObsoleteSystemConfiguration --standard=Magento2 etc/adminhtml/system.xml
vendor/bin/phpcs --sniffs=Magento2.Legacy.PhtmlTemplate --standard=Magento2 test.phtml
vendor/bin/phpcs --sniffs=Magento2.Less.Indentation --standard=Magento2 test.less
vendor/bin/phpcs --sniffs=Magento2.Less.TypeSelectors --standard=Magento2 test.less
vendor/bin/phpcs --sniffs=Magento2.Less.ClassNaming --standard=Magento2 test.less
vendor/bin/phpcs --sniffs=Magento2.Less.CommentLevels --standard=Magento2 test.less
vendor/bin/phpcs --sniffs=Magento2.Less.PropertiesSorting --standard=Magento2 test.less
vendor/bin/phpcs --sniffs=Magento2.Less.BracesFormatting --standard=Magento2 test.less
vendor/bin/phpcs --sniffs=Magento2.Less.SemicolonSpacing --standard=Magento2 test.less
vendor/bin/phpcs --sniffs=Magento2.Less.ColonSpacing --standard=Magento2 test.less
vendor/bin/phpcs --sniffs=Magento2.Less.ZeroUnits --standard=Magento2 test.less
vendor/bin/phpcs --sniffs=Magento2.Less.PropertiesLineBreak --standard=Magento2 test.less
You can also see evidence of the \m being present on windows in the regex where phpcs fails and bugs out because of the Magento2.Legacy.ModuleXML include regex being wrong on windows.
graham@DESKTOP-IAGIISG ~/testproject
$ vendor/bin/phpcs --standard=Magento2 test.xml
FILE: C:\Users\GrahamWharton\testproject\test.xml
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
FOUND 1 ERROR AFFECTING 1 LINE
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
1 | ERROR | An error occurred during processing; checking has been aborted. The error message was: preg_match(): Compilation failed: unrecognized character follows \ at offset 5 in C:\Users\GrahamWharton\testproject\vendor\squizlabs\php_codesniffer\src\Files\File.php
| | on line 496
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Time: 239ms; Memory: 14MB
graham@DESKTOP-IAGIISG ~/testproject
$
If you'd like me to package this test environment up onto packagist to make it easier for you to reproduce, just let me know. More than happy to help.
@magento I am working on this
Preconditions
Steps to reproduce
The following creates a blank project, installs the necessary composer packages, creates some test files, and then patches phpcs to provide additional debugging output on the console for regex matching of include paths.
I went through all of the Magento sniffs that have an include-path regex specified in the ruleset.xml file and verified that matches were being made where expected. I did this both on Ubuntu 24.04 and on Windows 11/Cygwin. Here is a summary of the tests that dd not produce the expected matching behaviour and some notes.
Ubuntu 24.04 - Magento2.Html.HtmlBinding PHPCS Magento Ruleset Include Pattern :
*\/.phtml$
NO MATCH I am assuming that this test is intended to run on all files with a
.phtml
extension. As written, the expression will match onpath/.phtml
but notpath/file.phtml
.Ubuntu 24.04 - Magento2.Legacy.Layout PHPCS Magento Ruleset Include Pattern :
*/view/(adminhtml|frontend|base)/*\/.xml
NO MATCH Looking at the pattern, I would assume that this is intended to match files with filenames such as
anything/view/adminhtml/anything/test.xml
, but thats not what the expression is looking for. Is it really looking for an xml file with no name and just extension.Windows 11/Cygwin - Magento2.Legacy.ClassReferencesInConfigurationFiles PHPCS Magento Ruleset Include Pattern :
*\/etc/*.xml$
NO MATCH The pattern is wrong here. It is matching
\\
(Backslash) and then\e
(ASCII 8) followed by tc\something.xml.Windows 11/Cygwin - Magento2.Html.HtmlBinding PHPCS Magento Ruleset Include Pattern :
*\/.phtml$
NO MATCH The pattern is wrong here. It is matching
\\
(Backslash) and then\.
(.
) and thenphtml
. i.e filename ends in\.phtml
Windows 11/Cygwin - Magento2.Legacy.ModuleXML PHPCS Magento Ruleset Include Pattern :
*\/module.xml$
NO MATCH The pattern is wrong here. It is matching
\\
(Backslash) and then\m
(undefined, preg_match should throw an error here) and thenodule.xml
.Windows 11/Cygwin - Magento2.Legacy.DiConfig PHPCS Magento Ruleset Include Pattern :
*\/di.xml$
NO MATCH The pattern is wrong here. It is matching
\\
(Backslash) and then\d
(a digit from[0-9]
) and theni.xml
.Windows 11/Cygwin - Magento2.Legacy.WidgetXML PHPCS Magento Ruleset Include Pattern :
*\/widget.xml$
MATCHED but....... Well ok, the regex matches on this one, but not by design, but by accident. The pattern as written will match anything followed by
\\
(Backslash) followed by\w
(and word character[a-zA-Z0-9_]
) followed byidget.xml
.