Skip to content

Commit 49a3b10

Browse files
ENGCOM-5470: #23789: CommentLevelsSniff works incorrect with @magento_import statement. #23790
- Merge Pull Request #23790 from p-bystritsky/magento2:ISSUE-23789 - Merged commits: 1. a99014e
2 parents a102409 + a99014e commit 49a3b10

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

dev/tests/static/framework/Magento/Sniffs/Less/CommentLevelsSniff.php

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
*/
66
namespace Magento\Sniffs\Less;
77

8-
use PHP_CodeSniffer\Sniffs\Sniff;
98
use PHP_CodeSniffer\Files\File;
9+
use PHP_CodeSniffer\Sniffs\Sniff;
1010

1111
/**
1212
* Class CommentLevelsSniff
@@ -72,14 +72,7 @@ public function process(File $phpcsFile, $stackPtr)
7272
return;
7373
}
7474

75-
// validation of levels comments
76-
if (!in_array($tokens[$stackPtr + 1]['content'], [
77-
TokenizerSymbolsInterface::DOUBLE_WHITESPACE,
78-
TokenizerSymbolsInterface::NEW_LINE,
79-
])
80-
) {
81-
$phpcsFile->addError('Level\'s comment does not have 2 spaces after "//"', $stackPtr, 'SpacesMissed');
82-
}
75+
$this->validateCommentLevel($phpcsFile, $stackPtr, $tokens);
8376

8477
if (!$this->isNthLevelComment($phpcsFile, $stackPtr, $tokens)) {
8578
return;
@@ -195,4 +188,27 @@ private function checkNthLevelComment(File $phpcsFile, $stackPtr, array $tokens)
195188

196189
return $correct;
197190
}
191+
192+
/**
193+
* Validation of comment level.
194+
*
195+
* @param File $phpcsFile
196+
* @param int $stackPtr
197+
* @param array $tokens
198+
*/
199+
private function validateCommentLevel(File $phpcsFile, int $stackPtr, array $tokens): void
200+
{
201+
if ($tokens[$stackPtr + 2]['content'] !== 'magento_import' &&
202+
!in_array(
203+
$tokens[$stackPtr + 1]['content'],
204+
[
205+
TokenizerSymbolsInterface::DOUBLE_WHITESPACE,
206+
TokenizerSymbolsInterface::NEW_LINE,
207+
],
208+
true
209+
)
210+
) {
211+
$phpcsFile->addError('Level\'s comment does not have 2 spaces after "//"', $stackPtr, 'SpacesMissed');
212+
}
213+
}
198214
}

0 commit comments

Comments
 (0)