-
Notifications
You must be signed in to change notification settings - Fork 158
/
Copy pathCombinatorIndentationSniff.php
51 lines (44 loc) · 1.15 KB
/
CombinatorIndentationSniff.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
<?php
/**
* Copyright 2021 Adobe
* All Rights Reserved.
*/
declare(strict_types=1);
namespace Magento2\Sniffs\Less;
use PHP_CodeSniffer\Sniffs\Sniff;
use PHP_CodeSniffer\Files\File;
/**
* Class CombinatorIndentationSniff
*
* Ensure that spaces are used before and after combinators
*
* @link https://devdocs.magento.com/guides/v2.4/coding-standards/code-standard-less.html#combinator-indents
*/
class CombinatorIndentationSniff implements Sniff
{
/**
* A list of tokenizers this sniff supports.
*
* @var array
*/
public $supportedTokenizers = [TokenizerSymbolsInterface::TOKENIZER_CSS];
/**
* @inheritdoc
*/
public function register()
{
return [T_PLUS];
}
/**
* @inheritdoc
*/
public function process(File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
$prevPtr = $stackPtr - 1;
$nextPtr = $stackPtr + 1;
if (($tokens[$prevPtr]['code'] !== T_WHITESPACE) || ($tokens[$nextPtr]['code'] !== T_WHITESPACE)) {
$phpcsFile->addError('Spaces should be before and after combinators', $stackPtr, 'NoSpaces');
}
}
}