Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Data Fields
AvoidIdSniff Class Reference
Inheritance diagram for AvoidIdSniff:

Public Member Functions

 register ()
 
 process (File $phpcsFile, $stackPtr)
 

Data Fields

 $supportedTokenizers = [TokenizerSymbolsInterface::TOKENIZER_CSS]
 

Detailed Description

Class AvoidIdSniff

Ensure that id selector is not used

http://devdocs.magento.com/guides/v2.0/coding-standards/code-standard-less.html#types

Definition at line 18 of file AvoidIdSniff.php.

Member Function Documentation

◆ process()

process ( File  $phpcsFile,
  $stackPtr 
)

Will flag any selector that looks like the following: #foo[bar], #foo[bar=bash], #foo[bar~=bash], #foo[bar$=bash], #foo[bar*=bash], #foo[bar|=bash], #foo[bar='bash'], #foo:hover, #foo:nth-last-of-type(n), #foo::before, #foo + div, #foo > div, #foo ~ div, #foo\3Abar ~ div, #foo\:bar ~ div, #foo.bar .baz, div::foo { blah: 'abc'; }

Definition at line 88 of file AvoidIdSniff.php.

89  {
90  $tokens = $phpcsFile->getTokens();
91 
92  // Find the next non-selector token
93  $nextToken = $phpcsFile->findNext($this->selectorTokens, $stackPtr + 1, null, true);
94 
95  // Anything except a { or a , means this is not a selector
96  if ($nextToken !== false && in_array($tokens[$nextToken]['code'], [T_OPEN_CURLY_BRACKET, T_COMMA])) {
97  $phpcsFile->addError('Id selector is used', $stackPtr, 'IdSelectorUsage');
98  }
99  }
$tokens
Definition: cards_list.phtml:9

◆ register()

register ( )

Definition at line 59 of file AvoidIdSniff.php.

60  {
61  return [T_HASH];
62  }

Field Documentation

◆ $supportedTokenizers

$supportedTokenizers = [TokenizerSymbolsInterface::TOKENIZER_CSS]

Definition at line 25 of file AvoidIdSniff.php.


The documentation for this class was generated from the following file: