|
5 | 5 | */
|
6 | 6 | namespace Magento\Sniffs\Less;
|
7 | 7 |
|
8 |
| -use PHP_CodeSniffer\Sniffs\Sniff; |
9 | 8 | use PHP_CodeSniffer\Files\File;
|
| 9 | +use PHP_CodeSniffer\Sniffs\Sniff; |
10 | 10 |
|
11 | 11 | /**
|
12 | 12 | * Class CommentLevelsSniff
|
@@ -72,14 +72,7 @@ public function process(File $phpcsFile, $stackPtr)
|
72 | 72 | return;
|
73 | 73 | }
|
74 | 74 |
|
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); |
83 | 76 |
|
84 | 77 | if (!$this->isNthLevelComment($phpcsFile, $stackPtr, $tokens)) {
|
85 | 78 | return;
|
@@ -195,4 +188,27 @@ private function checkNthLevelComment(File $phpcsFile, $stackPtr, array $tokens)
|
195 | 188 |
|
196 | 189 | return $correct;
|
197 | 190 | }
|
| 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 | + } |
198 | 214 | }
|
0 commit comments