ImportantPropertySniff.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 ImportantPropertySniff
  11. *
  12. * Ensure that single quotes are used
  13. *
  14. * @link https://devdocs.magento.com/guides/v2.0/coding-standards/code-standard-less.html#important-property
  15. */
  16. class ImportantPropertySniff 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_BOOLEAN_NOT];
  30. }
  31. /**
  32. * @inheritdoc
  33. */
  34. public function process(File $phpcsFile, $stackPtr)
  35. {
  36. $tokens = $phpcsFile->getTokens();
  37. // Will be implemented in MAGETWO-49778
  38. //$phpcsFile->addWarning('!important is used', $stackPtr, '!ImportantIsUsed');
  39. if (($tokens[$stackPtr + 1]['content'] === 'important')
  40. && ($tokens[$stackPtr - 1]['content'] !== TokenizerSymbolsInterface::WHITESPACE)
  41. ) {
  42. $phpcsFile->addError('Space before !important is missing', $stackPtr, 'NoSpace');
  43. }
  44. }
  45. }