Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
TypeSelectorsSniff.php
Go to the documentation of this file.
1 <?php
6 namespace Magento\Sniffs\Less;
7 
8 use PHP_CodeSniffer\Sniffs\Sniff;
9 use PHP_CodeSniffer\Files\File;
10 
24 class TypeSelectorsSniff implements Sniff
25 {
31  private $tags = [
32  'a', 'abbr', 'acronym', 'address', 'area', 'b', 'base', 'bdo',
33  'big', 'blockquote', 'body', 'br', 'button', 'caption', 'cite',
34  'code', 'col', 'colgroup', 'dd', 'del', 'div', 'dfn', 'dl',
35  'dt', 'em', 'fieldset', 'form', 'frame', 'frameset', 'h1', 'h2',
36  'h3', 'h4', 'h5', 'h6', 'head', 'hr', 'html', 'i', 'iframe',
37  'img', 'input', 'ins', 'kbd', 'label', 'legend', 'li', 'link',
38  'map', 'meta', 'noframes', 'noscript', 'object', 'ol', 'optgroup',
39  'option', 'p', 'param', 'pre', 'q', 'samp', 'script', 'select',
40  'small', 'span', 'strong', 'style', 'sub', 'sup', 'table',
41  'tbody', 'td', 'textarea', 'tfoot', 'th', 'thead', 'title',
42  'tr', 'tt', 'ul', 'var',
43  // HTML5
44  'article', 'aside', 'audio', 'bdi', 'canvas', 'command',
45  'datalist', 'details', 'dialog', 'embed', 'figure', 'figcaption',
46  'footer', 'header', 'hgroup', 'keygen', 'mark', 'meter', 'nav',
47  'output', 'progress', 'ruby', 'rt', 'rp', 'track', 'section',
48  'source', 'summary', 'time', 'video', 'wbr'
49  ];
50 
57 
61  public function register()
62  {
63  return [T_STRING_CONCAT];
64  }
65 
69  public function process(File $phpcsFile, $stackPtr)
70  {
71  $tokens = $phpcsFile->getTokens();
72 
73  $bracketPtr = $phpcsFile->findNext(T_OPEN_CURLY_BRACKET, $stackPtr);
74 
75  if (false === $bracketPtr) {
76  return;
77  }
78 
79  $isBracketOnSameLane = (bool)($tokens[$bracketPtr]['line'] === $tokens[$stackPtr]['line']);
80 
81  if (!$isBracketOnSameLane) {
82  return;
83  }
84 
85  if ((T_STRING === $tokens[$stackPtr - 1]['code'])
86  && in_array($tokens[$stackPtr - 1]['content'], $this->tags)
87  ) {
88  // Will be implemented in MAGETWO-49778
89  //$phpcsFile->addWarning('Type selector is used', $stackPtr, 'TypeSelector');
90  }
91 
92  for ($i = $stackPtr; $i < $bracketPtr; $i++) {
93  if (preg_match('/[A-Z]/', $tokens[$i]['content'])) {
94  $phpcsFile->addError('Selector contains uppercase symbols', $stackPtr, 'UpperCaseSelector');
95  }
96  }
97  }
98 }
$i
Definition: gallery.phtml:31
$tokens
Definition: cards_list.phtml:9