diff --git a/Magento2/Sniffs/Legacy/EmailTemplateSniff.php b/Magento2/Sniffs/Legacy/EmailTemplateSniff.php new file mode 100644 index 00000000..17ebbf08 --- /dev/null +++ b/Magento2/Sniffs/Legacy/EmailTemplateSniff.php @@ -0,0 +1,50 @@ + 'Directive {{htmlescape}} is obsolete. Use {{var}} instead.', + '/\{\{escapehtml.*?\}\}/i' => 'Directive {{escapehtml}} is obsolete. Use {{var}} instead.', + ]; + + private const ERROR_CODE = 'FoundObsoleteEmailDirective'; + + /** + * @inheritdoc + */ + public function register(): array + { + return [ + T_INLINE_HTML + ]; + } + + /** + * @inheritDoc + */ + public function process(File $phpcsFile, $stackPtr) + { + $content = $phpcsFile->getTokens()[$stackPtr]['content']; + foreach (self::OBSOLETE_EMAIL_DIRECTIVES as $directiveRegex => $errorMessage) { + if (preg_match($directiveRegex, $content)) { + $phpcsFile->addError( + $errorMessage, + $stackPtr, + self::ERROR_CODE + ); + } + } + } +} diff --git a/Magento2/Tests/Legacy/EmailTemplateUnitTest.1.html b/Magento2/Tests/Legacy/EmailTemplateUnitTest.1.html new file mode 100644 index 00000000..9516974b --- /dev/null +++ b/Magento2/Tests/Legacy/EmailTemplateUnitTest.1.html @@ -0,0 +1,4 @@ +

{{var "H1"}}

+

{{var "H2"}}

+

{{var "p"}} {{var "p"}}

+ diff --git a/Magento2/Tests/Legacy/EmailTemplateUnitTest.2.html b/Magento2/Tests/Legacy/EmailTemplateUnitTest.2.html new file mode 100644 index 00000000..422cea21 --- /dev/null +++ b/Magento2/Tests/Legacy/EmailTemplateUnitTest.2.html @@ -0,0 +1,4 @@ +

{{htmlescape "H1"}}

+

{{escapehtml "H2"}}

+

{{escapehtml "p"}} {{htmlescape "p"}}

+

{{trans "Translateme"}}

diff --git a/Magento2/Tests/Legacy/EmailTemplateUnitTest.php b/Magento2/Tests/Legacy/EmailTemplateUnitTest.php new file mode 100644 index 00000000..c0b42189 --- /dev/null +++ b/Magento2/Tests/Legacy/EmailTemplateUnitTest.php @@ -0,0 +1,39 @@ + 1, + 2 => 1, + 3 => 2, + ]; + } + + return []; + } + + /** + * @inheritdoc + */ + public function getWarningList($testFile = '') + { + return []; + } +} diff --git a/Magento2/ruleset.xml b/Magento2/ruleset.xml index f31b105d..e1b0f521 100644 --- a/Magento2/ruleset.xml +++ b/Magento2/ruleset.xml @@ -109,6 +109,12 @@ 10 error + + view/email/*.html + view/*/email/*.html + 10 + error +