From 557b1d99dbbdedd3e11587a0fdc8ad7901061126 Mon Sep 17 00:00:00 2001 From: Aad Mathijssen Date: Fri, 4 Mar 2022 19:54:37 +0100 Subject: [PATCH 1/8] Resolve incorrect violation code by resetting the hasDisallowedAnnotation property at then end of processing --- Magento2/Sniffs/Security/XssTemplateSniff.php | 1 + 1 file changed, 1 insertion(+) diff --git a/Magento2/Sniffs/Security/XssTemplateSniff.php b/Magento2/Sniffs/Security/XssTemplateSniff.php index 3b4385e8..2ba8e8c0 100644 --- a/Magento2/Sniffs/Security/XssTemplateSniff.php +++ b/Magento2/Sniffs/Security/XssTemplateSniff.php @@ -135,6 +135,7 @@ public function process(File $phpcsFile, $stackPtr) $statement = array_shift($this->statements); $this->detectUnescapedString($statement); } + $this->hasDisallowedAnnotation = false; } /** From 7c702e0b668036273309fc6cd78f970c452d1999 Mon Sep 17 00:00:00 2001 From: Dan Wallis Date: Tue, 5 Apr 2022 09:48:28 +0100 Subject: [PATCH 2/8] Add @author to forbidden tag list Ref https://devdocs.magento.com/guides/v2.4/coding-standards/docblock-standard-general.html#documentation-space --- .../Commenting/ClassAndInterfacePHPDocFormattingSniff.php | 1 + .../Commenting/ClassAndInterfacePHPDocFormattingUnitTest.1.inc | 2 +- .../Commenting/ClassAndInterfacePHPDocFormattingUnitTest.2.inc | 2 +- .../Commenting/ClassAndInterfacePHPDocFormattingUnitTest.php | 1 + 4 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Magento2/Sniffs/Commenting/ClassAndInterfacePHPDocFormattingSniff.php b/Magento2/Sniffs/Commenting/ClassAndInterfacePHPDocFormattingSniff.php index 2d715c50..20c12851 100644 --- a/Magento2/Sniffs/Commenting/ClassAndInterfacePHPDocFormattingSniff.php +++ b/Magento2/Sniffs/Commenting/ClassAndInterfacePHPDocFormattingSniff.php @@ -24,6 +24,7 @@ class ClassAndInterfacePHPDocFormattingSniff implements Sniff * @var string[] List of tags that can not be used in comments */ public $forbiddenTags = [ + '@author', '@category', '@package', '@subpackage' diff --git a/Magento2/Tests/Commenting/ClassAndInterfacePHPDocFormattingUnitTest.1.inc b/Magento2/Tests/Commenting/ClassAndInterfacePHPDocFormattingUnitTest.1.inc index e5895e32..e2727967 100644 --- a/Magento2/Tests/Commenting/ClassAndInterfacePHPDocFormattingUnitTest.1.inc +++ b/Magento2/Tests/Commenting/ClassAndInterfacePHPDocFormattingUnitTest.1.inc @@ -60,7 +60,7 @@ class EmptyHandler * @api is ok here * @deprecated can be used in this context * @see is ok here - * @author is actually ok + * @author is not ment to be used * @category is irrelevant * @package is not ment to be used * @subpackage does not belong here diff --git a/Magento2/Tests/Commenting/ClassAndInterfacePHPDocFormattingUnitTest.2.inc b/Magento2/Tests/Commenting/ClassAndInterfacePHPDocFormattingUnitTest.2.inc index 96900de2..e45e15ff 100644 --- a/Magento2/Tests/Commenting/ClassAndInterfacePHPDocFormattingUnitTest.2.inc +++ b/Magento2/Tests/Commenting/ClassAndInterfacePHPDocFormattingUnitTest.2.inc @@ -60,7 +60,7 @@ interface EmptyHandler * @api is ok here * @deprecated can be used in this context * @see is ok here - * @author is actually ok + * @author is not ment to be used * @category is irrelevant * @package is not ment to be used * @subpackage does not belong here diff --git a/Magento2/Tests/Commenting/ClassAndInterfacePHPDocFormattingUnitTest.php b/Magento2/Tests/Commenting/ClassAndInterfacePHPDocFormattingUnitTest.php index 9b5b2f85..b6a1c206 100644 --- a/Magento2/Tests/Commenting/ClassAndInterfacePHPDocFormattingUnitTest.php +++ b/Magento2/Tests/Commenting/ClassAndInterfacePHPDocFormattingUnitTest.php @@ -29,6 +29,7 @@ public function getWarningList($testFile = '') 35 => 1, 44 => 1, 52 => 1, + 63 => 1, 64 => 1, 65 => 1, 66 => 1, From 1f76b15da9af73ee88b41ad2ddedaa0f5ab29a8a Mon Sep 17 00:00:00 2001 From: Dan Wallis Date: Wed, 6 Jul 2022 15:51:56 +0100 Subject: [PATCH 3/8] Correct spelling/grammar --- .../ClassAndInterfacePHPDocFormattingUnitTest.1.inc | 4 ++-- .../ClassAndInterfacePHPDocFormattingUnitTest.2.inc | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Magento2/Tests/Commenting/ClassAndInterfacePHPDocFormattingUnitTest.1.inc b/Magento2/Tests/Commenting/ClassAndInterfacePHPDocFormattingUnitTest.1.inc index e2727967..146cded2 100644 --- a/Magento2/Tests/Commenting/ClassAndInterfacePHPDocFormattingUnitTest.1.inc +++ b/Magento2/Tests/Commenting/ClassAndInterfacePHPDocFormattingUnitTest.1.inc @@ -60,9 +60,9 @@ class EmptyHandler * @api is ok here * @deprecated can be used in this context * @see is ok here - * @author is not ment to be used + * @author should not be used * @category is irrelevant - * @package is not ment to be used + * @package should not be used * @subpackage does not belong here */ class ExampleHandler diff --git a/Magento2/Tests/Commenting/ClassAndInterfacePHPDocFormattingUnitTest.2.inc b/Magento2/Tests/Commenting/ClassAndInterfacePHPDocFormattingUnitTest.2.inc index e45e15ff..b6decf6c 100644 --- a/Magento2/Tests/Commenting/ClassAndInterfacePHPDocFormattingUnitTest.2.inc +++ b/Magento2/Tests/Commenting/ClassAndInterfacePHPDocFormattingUnitTest.2.inc @@ -60,9 +60,9 @@ interface EmptyHandler * @api is ok here * @deprecated can be used in this context * @see is ok here - * @author is not ment to be used + * @author should not be used * @category is irrelevant - * @package is not ment to be used + * @package should not be used * @subpackage does not belong here */ interface ExampleHandler From 1798cf49dd752411f373e2fb3e7d028289fc7311 Mon Sep 17 00:00:00 2001 From: Dan Wallis Date: Sat, 15 Oct 2022 12:02:16 +0100 Subject: [PATCH 4/8] Fix PHP error with short class names --- Magento2/Sniffs/Less/ClassNamingSniff.php | 3 ++- Magento2/Tests/Less/ClassNamingUnitTest.less | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/Magento2/Sniffs/Less/ClassNamingSniff.php b/Magento2/Sniffs/Less/ClassNamingSniff.php index e684172b..9a2e1dd0 100644 --- a/Magento2/Sniffs/Less/ClassNamingSniff.php +++ b/Magento2/Sniffs/Less/ClassNamingSniff.php @@ -66,7 +66,8 @@ public function process(File $phpcsFile, $stackPtr) [implode("", $matches[0])] ); } - if (strpos($className, self::STRING_HELPER_CLASSES_PREFIX, 2) !== false) { + + if (strlen($className) > 1 && strpos($className, self::STRING_HELPER_CLASSES_PREFIX, 2) !== false) { $phpcsFile->addError( 'CSS class names should be separated with "-" (dash) instead of "_" (underscore)', $stackPtr, diff --git a/Magento2/Tests/Less/ClassNamingUnitTest.less b/Magento2/Tests/Less/ClassNamingUnitTest.less index ba60c205..f67a938b 100644 --- a/Magento2/Tests/Less/ClassNamingUnitTest.less +++ b/Magento2/Tests/Less/ClassNamingUnitTest.less @@ -30,3 +30,8 @@ .category-title { background: green; } + +// @see https://github.com/magento/magento-coding-standard/issues/425 +.a { + text-decoration: none; +} From 2ea3c393903fcbc1db310d96e0aff4bba540c4a3 Mon Sep 17 00:00:00 2001 From: Dan Wallis Date: Tue, 17 Jan 2023 21:41:29 +1300 Subject: [PATCH 5/8] Allow class names with 'admin__' prefix --- Magento2/Sniffs/Less/ClassNamingSniff.php | 5 +- Magento2/Tests/Less/ClassNamingUnitTest.less | 5 + composer.json | 3 +- composer.lock | 121 ++++++++++++++++++- 4 files changed, 130 insertions(+), 4 deletions(-) diff --git a/Magento2/Sniffs/Less/ClassNamingSniff.php b/Magento2/Sniffs/Less/ClassNamingSniff.php index e684172b..babd0653 100644 --- a/Magento2/Sniffs/Less/ClassNamingSniff.php +++ b/Magento2/Sniffs/Less/ClassNamingSniff.php @@ -66,7 +66,10 @@ public function process(File $phpcsFile, $stackPtr) [implode("", $matches[0])] ); } - if (strpos($className, self::STRING_HELPER_CLASSES_PREFIX, 2) !== false) { + + if (strpos($className, self::STRING_HELPER_CLASSES_PREFIX, 2) !== false + && !str_starts_with($className, 'admin__') + ) { $phpcsFile->addError( 'CSS class names should be separated with "-" (dash) instead of "_" (underscore)', $stackPtr, diff --git a/Magento2/Tests/Less/ClassNamingUnitTest.less b/Magento2/Tests/Less/ClassNamingUnitTest.less index ba60c205..bbb29cde 100644 --- a/Magento2/Tests/Less/ClassNamingUnitTest.less +++ b/Magento2/Tests/Less/ClassNamingUnitTest.less @@ -30,3 +30,8 @@ .category-title { background: green; } + +// @see https://github.com/magento/magento-coding-standard/issues/409 +.admin__allowed { + background: green; +} diff --git a/composer.json b/composer.json index a277cf3a..49b3f7e2 100644 --- a/composer.json +++ b/composer.json @@ -14,7 +14,8 @@ "ext-dom": "*", "phpcompatibility/php-compatibility": "^9.3", "squizlabs/php_codesniffer": "^3.6.1", - "rector/rector": "^0.14.8" + "rector/rector": "^0.14.8", + "symfony/polyfill": "^1.16" }, "require-dev": { "phpunit/phpunit": "^9.5.8" diff --git a/composer.lock b/composer.lock index 11f55459..b4a64057 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "cfdb4177ef4747a5a6b83942ab05d65d", + "content-hash": "0c1e598f16594c56f36b7da4e389d3f9", "packages": [ { "name": "phpcompatibility/php-compatibility", @@ -240,6 +240,123 @@ }, "time": "2022-06-18T07:21:10+00:00" }, + { + "name": "symfony/polyfill", + "version": "v1.27.0", + "source": { + "type": "git", + "url": "https://github.com/symfony/polyfill.git", + "reference": "b78222a273aac3e5bab6358bf499d7f1fb88e48b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/polyfill/zipball/b78222a273aac3e5bab6358bf499d7f1fb88e48b", + "reference": "b78222a273aac3e5bab6358bf499d7f1fb88e48b", + "shasum": "" + }, + "require": { + "php": ">=7.1" + }, + "replace": { + "symfony/polyfill-apcu": "self.version", + "symfony/polyfill-ctype": "self.version", + "symfony/polyfill-iconv": "self.version", + "symfony/polyfill-intl-grapheme": "self.version", + "symfony/polyfill-intl-icu": "self.version", + "symfony/polyfill-intl-idn": "self.version", + "symfony/polyfill-intl-messageformatter": "self.version", + "symfony/polyfill-intl-normalizer": "self.version", + "symfony/polyfill-mbstring": "self.version", + "symfony/polyfill-php72": "self.version", + "symfony/polyfill-php73": "self.version", + "symfony/polyfill-php74": "self.version", + "symfony/polyfill-php80": "self.version", + "symfony/polyfill-php81": "self.version", + "symfony/polyfill-php82": "self.version", + "symfony/polyfill-php83": "self.version", + "symfony/polyfill-util": "self.version", + "symfony/polyfill-uuid": "self.version", + "symfony/polyfill-xml": "self.version" + }, + "require-dev": { + "symfony/intl": "^4.4|^5.0|^6.0", + "symfony/phpunit-bridge": "^5.3|^6.0", + "symfony/var-dumper": "^4.4|^5.1|^6.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-main": "1.27-dev" + } + }, + "autoload": { + "files": [ + "src/bootstrap.php", + "src/Apcu/bootstrap.php", + "src/Ctype/bootstrap.php", + "src/Uuid/bootstrap.php", + "src/Iconv/bootstrap.php", + "src/Intl/Grapheme/bootstrap.php", + "src/Intl/Idn/bootstrap.php", + "src/Intl/Icu/bootstrap.php", + "src/Intl/MessageFormatter/bootstrap.php", + "src/Intl/Normalizer/bootstrap.php", + "src/Mbstring/bootstrap.php" + ], + "psr-4": { + "Symfony\\Polyfill\\": "src/" + }, + "classmap": [ + "src/Intl/Icu/Resources/stubs", + "src/Intl/MessageFormatter/Resources/stubs", + "src/Intl/Normalizer/Resources/stubs", + "src/Php82/Resources/stubs", + "src/Php80/Resources/stubs", + "src/Php73/Resources/stubs" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Nicolas Grekas", + "email": "p@tchwork.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Symfony polyfills backporting features to lower PHP versions", + "homepage": "https://symfony.com", + "keywords": [ + "compat", + "compatibility", + "polyfill", + "shim" + ], + "support": { + "issues": "https://github.com/symfony/polyfill/issues", + "source": "https://github.com/symfony/polyfill/tree/v1.27.0" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2022-11-10T10:11:03+00:00" + }, { "name": "webonyx/graphql-php", "version": "v15.0.0", @@ -2054,5 +2171,5 @@ "ext-dom": "*" }, "platform-dev": [], - "plugin-api-version": "2.2.0" + "plugin-api-version": "2.3.0" } From d16895a56b57e1f12b54e54289a79de1c592097f Mon Sep 17 00:00:00 2001 From: Rajesh Kumar Date: Mon, 30 Jan 2023 13:24:26 +0530 Subject: [PATCH 6/8] AC-7822:Phpstan dependency should not be limited to a specific version, updated rector/rector with latest version --- composer.json | 4 ++-- composer.lock | 29 ++++++++++++++--------------- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/composer.json b/composer.json index a277cf3a..355a66f6 100644 --- a/composer.json +++ b/composer.json @@ -6,7 +6,7 @@ "AFL-3.0" ], "type": "phpcodesniffer-standard", - "version": "30", + "version": "31", "require": { "php": ">=7.4", "webonyx/graphql-php": "^15.0", @@ -14,7 +14,7 @@ "ext-dom": "*", "phpcompatibility/php-compatibility": "^9.3", "squizlabs/php_codesniffer": "^3.6.1", - "rector/rector": "^0.14.8" + "rector/rector": "^0.15.10" }, "require-dev": { "phpunit/phpunit": "^9.5.8" diff --git a/composer.lock b/composer.lock index 11f55459..f2880864 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "cfdb4177ef4747a5a6b83942ab05d65d", + "content-hash": "a1016f46104814a16b090a61a5c2ca2a", "packages": [ { "name": "phpcompatibility/php-compatibility", @@ -70,16 +70,16 @@ }, { "name": "phpstan/phpstan", - "version": "1.9.3", + "version": "1.9.14", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "709999b91448d4f2bb07daffffedc889b33e461c" + "reference": "e5fcc96289cf737304286a9b505fbed091f02e58" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/709999b91448d4f2bb07daffffedc889b33e461c", - "reference": "709999b91448d4f2bb07daffffedc889b33e461c", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/e5fcc96289cf737304286a9b505fbed091f02e58", + "reference": "e5fcc96289cf737304286a9b505fbed091f02e58", "shasum": "" }, "require": { @@ -109,7 +109,7 @@ ], "support": { "issues": "https://github.com/phpstan/phpstan/issues", - "source": "https://github.com/phpstan/phpstan/tree/1.9.3" + "source": "https://github.com/phpstan/phpstan/tree/1.9.14" }, "funding": [ { @@ -125,31 +125,30 @@ "type": "tidelift" } ], - "time": "2022-12-13T10:28:10+00:00" + "time": "2023-01-19T10:47:09+00:00" }, { "name": "rector/rector", - "version": "0.14.8", + "version": "0.15.10", "source": { "type": "git", "url": "https://github.com/rectorphp/rector.git", - "reference": "46ee9a173a2b2645ca92a75ffc17460139fa226e" + "reference": "000bfb6f7974449399f39e1a210458395b75c887" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/rectorphp/rector/zipball/46ee9a173a2b2645ca92a75ffc17460139fa226e", - "reference": "46ee9a173a2b2645ca92a75ffc17460139fa226e", + "url": "https://api.github.com/repos/rectorphp/rector/zipball/000bfb6f7974449399f39e1a210458395b75c887", + "reference": "000bfb6f7974449399f39e1a210458395b75c887", "shasum": "" }, "require": { "php": "^7.2|^8.0", - "phpstan/phpstan": "^1.9.0" + "phpstan/phpstan": "^1.9.7" }, "conflict": { "rector/rector-doctrine": "*", "rector/rector-downgrade-php": "*", "rector/rector-php-parser": "*", - "rector/rector-phpoffice": "*", "rector/rector-phpunit": "*", "rector/rector-symfony": "*" }, @@ -174,7 +173,7 @@ "description": "Instant Upgrade and Automated Refactoring of any PHP code", "support": { "issues": "https://github.com/rectorphp/rector/issues", - "source": "https://github.com/rectorphp/rector/tree/0.14.8" + "source": "https://github.com/rectorphp/rector/tree/0.15.10" }, "funding": [ { @@ -182,7 +181,7 @@ "type": "github" } ], - "time": "2022-11-14T14:09:49+00:00" + "time": "2023-01-21T14:30:16+00:00" }, { "name": "squizlabs/php_codesniffer", From 255e0290f9b50cae5e1efc5973bd1f7df200489f Mon Sep 17 00:00:00 2001 From: Dan Wallis Date: Thu, 16 Feb 2023 12:01:10 +0000 Subject: [PATCH 7/8] Add another test case --- Magento2/Tests/PHP/ShortEchoSyntaxUnitTest.inc | 2 ++ Magento2/Tests/PHP/ShortEchoSyntaxUnitTest.php | 1 + 2 files changed, 3 insertions(+) diff --git a/Magento2/Tests/PHP/ShortEchoSyntaxUnitTest.inc b/Magento2/Tests/PHP/ShortEchoSyntaxUnitTest.inc index b254ebc0..14f7ba1e 100644 --- a/Magento2/Tests/PHP/ShortEchoSyntaxUnitTest.inc +++ b/Magento2/Tests/PHP/ShortEchoSyntaxUnitTest.inc @@ -3,3 +3,5 @@ + + diff --git a/Magento2/Tests/PHP/ShortEchoSyntaxUnitTest.php b/Magento2/Tests/PHP/ShortEchoSyntaxUnitTest.php index 159ddedb..c7a68fe5 100644 --- a/Magento2/Tests/PHP/ShortEchoSyntaxUnitTest.php +++ b/Magento2/Tests/PHP/ShortEchoSyntaxUnitTest.php @@ -24,6 +24,7 @@ public function getWarningList() { return [ 5 => 1, + 7 => 1, ]; } } From 4612aa3600a8bd0b46cf1bacd8fd9ed45c53e8fe Mon Sep 17 00:00:00 2001 From: Dan Wallis Date: Thu, 16 Feb 2023 12:02:29 +0000 Subject: [PATCH 8/8] Auto-fix short echo syntax --- Magento2/Sniffs/PHP/ShortEchoSyntaxSniff.php | 21 ++++++++++++++++++- .../PHP/ShortEchoSyntaxUnitTest.inc.fixed | 7 +++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 Magento2/Tests/PHP/ShortEchoSyntaxUnitTest.inc.fixed diff --git a/Magento2/Sniffs/PHP/ShortEchoSyntaxSniff.php b/Magento2/Sniffs/PHP/ShortEchoSyntaxSniff.php index 946bb273..da1aa279 100644 --- a/Magento2/Sniffs/PHP/ShortEchoSyntaxSniff.php +++ b/Magento2/Sniffs/PHP/ShortEchoSyntaxSniff.php @@ -37,11 +37,30 @@ public function process(File $phpcsFile, $stackPtr) $nextToken = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true); if ($tokens[$nextToken]['code'] == T_ECHO) { - $phpcsFile->addWarning( + $fix = $phpcsFile->addFixableWarning( 'Short echo tag syntax must be used; expected "fixer->beginChangeset(); + + if (($nextToken - $stackPtr) === 1) { + $phpcsFile->fixer->replaceToken($stackPtr, 'fixer->replaceToken($stackPtr, 'fixer->replaceToken($i, ''); + } + } + + $phpcsFile->fixer->replaceToken($nextToken, ''); + $phpcsFile->fixer->endChangeset(); + } } } } diff --git a/Magento2/Tests/PHP/ShortEchoSyntaxUnitTest.inc.fixed b/Magento2/Tests/PHP/ShortEchoSyntaxUnitTest.inc.fixed new file mode 100644 index 00000000..a3073e65 --- /dev/null +++ b/Magento2/Tests/PHP/ShortEchoSyntaxUnitTest.inc.fixed @@ -0,0 +1,7 @@ + + + + + + +