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

Resolve issues with regex include and exclude patterns in Magento 2 ruleset.xml

Open gwharton opened this issue 5 months ago • 1 comments

See https://github.com/magento/magento-coding-standard/issues/485 for a detailed description of the issue.

These fixes makes the following assumptions and these will need to be verified by someone who knows why the rules were introduced in the first place and has more knowledge about phpcs and Magento than I do.

Magento2.Legacy.Layout The existing rule seems to target files such as

  • anything/view/adminhtml/anything/.xml
  • anything/view/frontend/anything/.xml

I don't think thats right. I believe it should actually be targetting

  • anything/view/adminhtml/anything/anything.xml
  • anything/view/frontend/anything/anything.xml

The updated rule targets any xml file in any subfolder of a view/adminhtml, view/frontend or view/base folder. I think this was the intended target.

Magento2.Html.HtmlBinding I believe the intention with this rule is to target any phtml file anywhere in the tree. The existing rule, as written, will target only files with the following paths

  • .phtml
  • somewhere/.phtml
  • somewhere/somewhere/.phtml

In addition to this, escaping the first forward slash, as in the previous example, breaks things even more under windows. The replacement rule removes the escaping of forward slash so it works under both Linux and Windows, and corrects the rule to target paths such as

  • something.phtml
  • somewhere/something.phtml
  • somewhere/somewhere/something.phtml

Magento2.Legacy.ClassReferencesInConfigurationFiles I believe the intention with this rule is to target any xml file present in any etc folder, anywhere, but exclude wsdl.xml, wsdl2.xml and wsi.xml. There is no need to escape the leading forward slash, and by doing so, it stops the rule working under windows. The replacement rule removes the escaping of the first slash so it works under both Linux and Windows.

Magento2.Legacy.ModuleXML Magento2.Legacy.DiConfig Magento2.Legacy.WidgetXML I believe the intention with these rules is to target any file named module.xml, widget.xml or di.xml, in any subfolder of the tree, but not the root. The existing rules escape the first forward slash, which results in the rule failing when running under windows. The rule is updated to remove the escaping so it works under both Linux and Windows.

QUESTION: Why were all these forward slashes escaped in the rules. Is there something/some system I am overlooking that requires it?

For more detailed analysis see issue #485

Tested under Ubuntu 24.04 and Windows 11/Cygwin

gwharton avatar Aug 29 '24 16:08 gwharton