PropertiesLineBreakSniff.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Sniffs\Less;
  7. use PHP_CodeSniffer\Sniffs\Sniff;
  8. use PHP_CodeSniffer\Files\File;
  9. /**
  10. * Class PropertiesLineBreakSniff
  11. *
  12. * Start each property declaration in a new line
  13. *
  14. * @link https://devdocs.magento.com/guides/v2.0/coding-standards/code-standard-less.html#properties-line-break
  15. */
  16. class PropertiesLineBreakSniff implements Sniff
  17. {
  18. /**
  19. * A list of tokenizers this sniff supports.
  20. *
  21. * @var array
  22. */
  23. public $supportedTokenizers = [TokenizerSymbolsInterface::TOKENIZER_CSS];
  24. /**
  25. * @inheritdoc
  26. */
  27. public function register()
  28. {
  29. return [T_SEMICOLON];
  30. }
  31. /**
  32. * @inheritdoc
  33. */
  34. public function process(File $phpcsFile, $stackPtr)
  35. {
  36. $tokens = $phpcsFile->getTokens();
  37. $prevPtr = $phpcsFile->findPrevious(T_SEMICOLON, ($stackPtr - 1));
  38. if (false === $prevPtr) {
  39. return;
  40. }
  41. if ($tokens[$prevPtr]['line'] === $tokens[$stackPtr]['line']) {
  42. $error = 'Each property must be on a line by itself';
  43. $phpcsFile->addError($error, $stackPtr, 'SameLine');
  44. }
  45. }
  46. }