Resolve issues with regex include and exclude patterns in Magento 2 ruleset.xml #486
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
See #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
I don't think thats right. I believe it should actually be targetting
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
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
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