Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/develop' into psr-control-stru…
Browse files Browse the repository at this point in the history
…cture-spacing
  • Loading branch information
fredden committed Mar 30, 2023
2 parents e1621af + bc6b0f6 commit 8e870eb
Show file tree
Hide file tree
Showing 13 changed files with 188 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
7 changes: 6 additions & 1 deletion Magento2/Sniffs/Less/ClassNamingSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@ 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
&& !str_starts_with($className, 'admin__')
) {
$phpcsFile->addError(
'CSS class names should be separated with "-" (dash) instead of "_" (underscore)',
$stackPtr,
Expand Down
21 changes: 20 additions & 1 deletion Magento2/Sniffs/PHP/ShortEchoSyntaxSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 "<?=" but found "<?php echo"',
$stackPtr,
'ShortEchoTag'
);

if ($fix) {
$phpcsFile->fixer->beginChangeset();

if (($nextToken - $stackPtr) === 1) {
$phpcsFile->fixer->replaceToken($stackPtr, '<?=');
} else {
$phpcsFile->fixer->replaceToken($stackPtr, '<?= ');
}

for ($i = $stackPtr + 1; $i < $nextToken; $i++) {
if ($tokens[$i]['code'] === T_WHITESPACE) {
$phpcsFile->fixer->replaceToken($i, '');
}
}

$phpcsFile->fixer->replaceToken($nextToken, '');
$phpcsFile->fixer->endChangeset();
}
}
}
}
1 change: 1 addition & 0 deletions Magento2/Sniffs/Security/XssTemplateSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ public function process(File $phpcsFile, $stackPtr)
$statement = array_shift($this->statements);
$this->detectUnescapedString($statement);
}
$this->hasDisallowedAnnotation = false;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ class EmptyHandler
* @api is ok here
* @deprecated can be used in this context
* @see is ok here
* @author is actually ok
* @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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ interface EmptyHandler
* @api is ok here
* @deprecated can be used in this context
* @see is ok here
* @author is actually ok
* @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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public function getWarningList($testFile = '')
35 => 1,
44 => 1,
52 => 1,
63 => 1,
64 => 1,
65 => 1,
66 => 1,
Expand Down
10 changes: 10 additions & 0 deletions Magento2/Tests/Less/ClassNamingUnitTest.less
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,13 @@
.category-title {
background: green;
}

// @see https://github.com/magento/magento-coding-standard/issues/425
.a {
text-decoration: none;
}

// @see https://github.com/magento/magento-coding-standard/issues/409
.admin__allowed {
background: green;
}
2 changes: 2 additions & 0 deletions Magento2/Tests/PHP/ShortEchoSyntaxUnitTest.inc
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
<?php $foo = bar; ?>

<?php echo "foo" ?>

<?php /* @noEscape */ echo 'baz'; ?>
7 changes: 7 additions & 0 deletions Magento2/Tests/PHP/ShortEchoSyntaxUnitTest.inc.fixed
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?= "foo" ?>

<?php $foo = bar; ?>

<?= "foo" ?>

<?= /* @noEscape */ 'baz'; ?>
1 change: 1 addition & 0 deletions Magento2/Tests/PHP/ShortEchoSyntaxUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public function getWarningList()
{
return [
5 => 1,
7 => 1,
];
}
}
5 changes: 3 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,16 @@
"AFL-3.0"
],
"type": "phpcodesniffer-standard",
"version": "30",
"version": "31",
"require": {
"php": ">=7.4",
"webonyx/graphql-php": "^15.0",
"ext-simplexml": "*",
"ext-dom": "*",
"phpcompatibility/php-compatibility": "^9.3",
"squizlabs/php_codesniffer": "^3.6.1",
"rector/rector": "^0.14.8"
"rector/rector": "^0.15.10",
"symfony/polyfill": "^1.16"
},
"require-dev": {
"phpunit/phpunit": "^9.5.8"
Expand Down
148 changes: 132 additions & 16 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8e870eb

Please sign in to comment.