From c7a06b56b3d37bd877e859bc8877d07553362e4c Mon Sep 17 00:00:00 2001 From: Lena Orobei Date: Wed, 16 Jan 2019 11:23:08 -0600 Subject: [PATCH] Remove "Less" sniffs - removed "Less" sniffs since they are useless without Magento wrapper --- Magento/Sniffs/Less/AvoidIdSniff.php | 100 --------- Magento/Sniffs/Less/BracesFormattingSniff.php | 88 -------- Magento/Sniffs/Less/ClassNamingSniff.php | 65 ------ Magento/Sniffs/Less/ColonSpacingSniff.php | 113 ---------- Magento/Sniffs/Less/ColourDefinitionSniff.php | 65 ------ .../Less/CombinatorIndentationSniff.php | 49 ----- Magento/Sniffs/Less/CommentLevelsSniff.php | 198 ------------------ .../Sniffs/Less/ImportantPropertySniff.php | 51 ----- Magento/Sniffs/Less/IndentationSniff.php | 106 ---------- .../Sniffs/Less/PropertiesLineBreakSniff.php | 52 ----- .../Sniffs/Less/PropertiesSortingSniff.php | 119 ----------- Magento/Sniffs/Less/QuotesSniff.php | 46 ---- .../Sniffs/Less/SelectorDelimiterSniff.php | 90 -------- Magento/Sniffs/Less/SemicolonSpacingSniff.php | 115 ---------- .../Sniffs/Less/TokenizerSymbolsInterface.php | 27 --- .../Less/TypeSelectorConcatenationSniff.php | 56 ----- Magento/Sniffs/Less/TypeSelectorsSniff.php | 97 --------- Magento/Sniffs/Less/VariablesSniff.php | 80 ------- Magento/Sniffs/Less/ZeroUnitsSniff.php | 78 ------- Magento/ruleset.xml | 3 - 20 files changed, 1598 deletions(-) delete mode 100644 Magento/Sniffs/Less/AvoidIdSniff.php delete mode 100644 Magento/Sniffs/Less/BracesFormattingSniff.php delete mode 100644 Magento/Sniffs/Less/ClassNamingSniff.php delete mode 100644 Magento/Sniffs/Less/ColonSpacingSniff.php delete mode 100644 Magento/Sniffs/Less/ColourDefinitionSniff.php delete mode 100644 Magento/Sniffs/Less/CombinatorIndentationSniff.php delete mode 100644 Magento/Sniffs/Less/CommentLevelsSniff.php delete mode 100644 Magento/Sniffs/Less/ImportantPropertySniff.php delete mode 100644 Magento/Sniffs/Less/IndentationSniff.php delete mode 100644 Magento/Sniffs/Less/PropertiesLineBreakSniff.php delete mode 100644 Magento/Sniffs/Less/PropertiesSortingSniff.php delete mode 100644 Magento/Sniffs/Less/QuotesSniff.php delete mode 100644 Magento/Sniffs/Less/SelectorDelimiterSniff.php delete mode 100644 Magento/Sniffs/Less/SemicolonSpacingSniff.php delete mode 100644 Magento/Sniffs/Less/TokenizerSymbolsInterface.php delete mode 100644 Magento/Sniffs/Less/TypeSelectorConcatenationSniff.php delete mode 100644 Magento/Sniffs/Less/TypeSelectorsSniff.php delete mode 100644 Magento/Sniffs/Less/VariablesSniff.php delete mode 100644 Magento/Sniffs/Less/ZeroUnitsSniff.php diff --git a/Magento/Sniffs/Less/AvoidIdSniff.php b/Magento/Sniffs/Less/AvoidIdSniff.php deleted file mode 100644 index ae0c7e23..00000000 --- a/Magento/Sniffs/Less/AvoidIdSniff.php +++ /dev/null @@ -1,100 +0,0 @@ - div, - * #foo ~ div, - * #foo\3Abar ~ div, - * #foo\:bar ~ div, - * #foo.bar .baz, - * div#foo { - * blah: 'abc'; - * } - */ - public function process(File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - // Find the next non-selector token - $nextToken = $phpcsFile->findNext($this->selectorTokens, $stackPtr + 1, null, true); - - // Anything except a { or a , means this is not a selector - if ($nextToken !== false && in_array($tokens[$nextToken]['code'], [T_OPEN_CURLY_BRACKET, T_COMMA])) { - $phpcsFile->addWarning('Id selector is used', $stackPtr, 'IdSelectorUsage'); - } - } -} diff --git a/Magento/Sniffs/Less/BracesFormattingSniff.php b/Magento/Sniffs/Less/BracesFormattingSniff.php deleted file mode 100644 index f56fe3e3..00000000 --- a/Magento/Sniffs/Less/BracesFormattingSniff.php +++ /dev/null @@ -1,88 +0,0 @@ -getTokens(); - - if (T_OPEN_CURLY_BRACKET === $tokens[$stackPtr]['code']) { - if (TokenizerSymbolsInterface::WHITESPACE !== $tokens[$stackPtr - 1]['content']) { - $phpcsFile->addWarning('Space before opening brace is missing', $stackPtr, 'SpacingBeforeOpen'); - } - - return; - } - - $next = $phpcsFile->findNext(T_WHITESPACE, ($stackPtr + 1), null, true); - if ($next === false) { - return; - } - - if (!in_array($tokens[$next]['code'], [T_CLOSE_TAG, T_CLOSE_CURLY_BRACKET])) { - $found = (($tokens[$next]['line'] - $tokens[$stackPtr]['line']) - 1); - if ($found !== 1) { - $error = 'Expected one blank line after closing brace of class definition; %s found'; - $data = [$found]; - // Will be implemented in MAGETWO-49778 - //$phpcsFile->addWarning($error, $stackPtr, 'SpacingAfterClose', $data); - } - } - - // Ignore nested style definitions from here on. The spacing before the closing brace - // (a single blank line) will be enforced by the above check, which ensures there is a - // blank line after the last nested class. - $found = $phpcsFile->findPrevious( - T_CLOSE_CURLY_BRACKET, - ($stackPtr - 1), - $tokens[$stackPtr]['bracket_opener'] - ); - - if ($found !== false) { - return; - } - - $prev = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true); - if ($prev !== false && $tokens[$prev]['line'] !== ($tokens[$stackPtr]['line'] - 1)) { - $num = ($tokens[$stackPtr]['line'] - $tokens[$prev]['line'] - 1); - $error = 'Expected 0 blank lines before closing brace of class definition; %s found'; - $data = [$num]; - $phpcsFile->addWarning($error, $stackPtr, 'SpacingBeforeClose', $data); - } - } -} diff --git a/Magento/Sniffs/Less/ClassNamingSniff.php b/Magento/Sniffs/Less/ClassNamingSniff.php deleted file mode 100644 index 64995712..00000000 --- a/Magento/Sniffs/Less/ClassNamingSniff.php +++ /dev/null @@ -1,65 +0,0 @@ -getTokens(); - - if (T_WHITESPACE !== $tokens[$stackPtr - 1]['code'] - && !in_array($tokens[$stackPtr - 1]['content'], [ - TokenizerSymbolsInterface::INDENT_SPACES, - TokenizerSymbolsInterface::NEW_LINE, - ]) - ) { - return; - } - - $className = $tokens[$stackPtr + 1]['content']; - if (preg_match_all('/[^a-z0-9\-_]/U', $className, $matches)) { - $phpcsFile->addWarning('Class name contains not allowed symbols', $stackPtr, 'NotAllowedSymbol', $matches); - } - } -} diff --git a/Magento/Sniffs/Less/ColonSpacingSniff.php b/Magento/Sniffs/Less/ColonSpacingSniff.php deleted file mode 100644 index 82c8b5ad..00000000 --- a/Magento/Sniffs/Less/ColonSpacingSniff.php +++ /dev/null @@ -1,113 +0,0 @@ -getTokens(); - - if ($this->needValidateSpaces($phpcsFile, $stackPtr, $tokens)) { - $this->validateSpaces($phpcsFile, $stackPtr, $tokens); - } - } - - /** - * Check is it need to check spaces - * - * @param File $phpcsFile - * @param int $stackPtr - * @param array $tokens - * - * @return bool - */ - private function needValidateSpaces(File $phpcsFile, $stackPtr, $tokens) - { - $nextSemicolon = $phpcsFile->findNext(T_SEMICOLON, $stackPtr); - - if (false === $nextSemicolon - || ($tokens[$nextSemicolon]['line'] !== $tokens[$stackPtr]['line']) - || TokenizerSymbolsInterface::BITWISE_AND === $tokens[$stackPtr - 1]['content'] - ) { - return false; - } - - $prev = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true); - if ($tokens[$prev]['code'] !== T_STYLE) { - // The colon is not part of a style definition. - return false; - } - - if ($tokens[$prev]['content'] === 'progid') { - // Special case for IE filters. - return false; - } - - return true; - } - - /** - * Validate Colon Spacing according to requirements - * - * @param File $phpcsFile - * @param int $stackPtr - * @param array $tokens - * - * @return void - */ - private function validateSpaces(File $phpcsFile, $stackPtr, array $tokens) - { - if (T_WHITESPACE === $tokens[($stackPtr - 1)]['code']) { - $phpcsFile->addWarning('There must be no space before a colon in a style definition', $stackPtr, 'Before'); - } - - if (T_WHITESPACE !== $tokens[($stackPtr + 1)]['code']) { - $phpcsFile->addWarning('Expected 1 space after colon in style definition; 0 found', $stackPtr, 'NoneAfter'); - } else { - $content = $tokens[($stackPtr + 1)]['content']; - if (false === strpos($content, $phpcsFile->eolChar)) { - $length = strlen($content); - if ($length !== 1) { - $error = 'Expected 1 space after colon in style definition; %s found'; - $phpcsFile->addWarning($error, $stackPtr, 'After'); - } - } else { - $error = 'Expected 1 space after colon in style definition; newline found'; - $phpcsFile->addWarning($error, $stackPtr, 'AfterNewline'); - } - } - } -} diff --git a/Magento/Sniffs/Less/ColourDefinitionSniff.php b/Magento/Sniffs/Less/ColourDefinitionSniff.php deleted file mode 100644 index 80e4642a..00000000 --- a/Magento/Sniffs/Less/ColourDefinitionSniff.php +++ /dev/null @@ -1,65 +0,0 @@ -getTokens(); - $colour = $tokens[$stackPtr]['content']; - - $variablePtr = $phpcsFile->findPrevious(T_ASPERAND, $stackPtr); - if ((false === $variablePtr) || ($tokens[$stackPtr]['line'] !== $tokens[$variablePtr]['line'])) { - $phpcsFile->addWarning('Hexadecimal value should be used for variable', $stackPtr, 'NotInVariable'); - } - - $expected = strtolower($colour); - if ($colour !== $expected) { - $error = 'CSS colours must be defined in lowercase; expected %s but found %s'; - $phpcsFile->addWarning($error, $stackPtr, 'NotLower', [$expected, $colour]); - } - - // Now check if shorthand can be used. - if (strlen($colour) !== 7) { - return; - } - - if ($colour[1] === $colour[2] && $colour[3] === $colour[4] && $colour[5] === $colour[6]) { - $expected = '#' . $colour[1] . $colour[3] . $colour[5]; - $error = 'CSS colours must use shorthand if available; expected %s but found %s'; - $phpcsFile->addWarning($error, $stackPtr, 'Shorthand', [$expected, $colour]); - } - } -} diff --git a/Magento/Sniffs/Less/CombinatorIndentationSniff.php b/Magento/Sniffs/Less/CombinatorIndentationSniff.php deleted file mode 100644 index e7e87122..00000000 --- a/Magento/Sniffs/Less/CombinatorIndentationSniff.php +++ /dev/null @@ -1,49 +0,0 @@ -getTokens(); - - $prevPtr = $stackPtr - 1; - $nextPtr = $stackPtr + 1; - - if (($tokens[$prevPtr]['code'] !== T_WHITESPACE) || ($tokens[$nextPtr]['code'] !== T_WHITESPACE)) { - $phpcsFile->addWarning('Spaces should be before and after combinators', $stackPtr, 'NoSpaces'); - } - } -} diff --git a/Magento/Sniffs/Less/CommentLevelsSniff.php b/Magento/Sniffs/Less/CommentLevelsSniff.php deleted file mode 100644 index 660acfc7..00000000 --- a/Magento/Sniffs/Less/CommentLevelsSniff.php +++ /dev/null @@ -1,198 +0,0 @@ - T_STRING, - self::SECOND_LEVEL_COMMENT => T_DEC, - ]; - - /** - * A list of tokenizers this sniff supports. - * - * @var array - */ - public $supportedTokenizers = [TokenizerSymbolsInterface::TOKENIZER_CSS]; - - /** - * @inheritdoc - */ - public function register() - { - return [T_STRING]; - } - - /** - * @inheritdoc - */ - public function process(File $phpcsFile, $stackPtr) - { - $tokens = $phpcsFile->getTokens(); - - if ((T_STRING !== $tokens[$stackPtr]['code']) - || (self::COMMENT_STRING !== $tokens[$stackPtr]['content']) - || (1 === $tokens[$stackPtr]['line']) - ) { - return; - } - - $textInSameLine = $phpcsFile->findPrevious([T_STRING, T_STYLE], $stackPtr - 1); - - // is inline comment - if ((false !== $textInSameLine) - && ($tokens[$textInSameLine]['line'] === $tokens[$stackPtr]['line']) - ) { - $this->validateInlineComment($phpcsFile, $stackPtr, $tokens); - return; - } - - // validation of levels comments - if (!in_array($tokens[$stackPtr + 1]['content'], [ - TokenizerSymbolsInterface::DOUBLE_WHITESPACE, - TokenizerSymbolsInterface::NEW_LINE, - ]) - ) { - $phpcsFile->addWarning('Level\'s comment does not have 2 spaces after "//"', $stackPtr, 'SpacesMissed'); - } - - if (!$this->isNthLevelComment($phpcsFile, $stackPtr, $tokens)) { - return; - } - - if (!$this->checkNthLevelComment($phpcsFile, $stackPtr, $tokens)) { - $phpcsFile->addWarning( - 'First and second level comments must be surrounded by empty lines', - $stackPtr, - 'SpaceMissed' - ); - } - } - - /** - * Validate that inline comment responds to given requirements - * - * @param File $phpcsFile - * @param int $stackPtr - * @param array $tokens - * @return bool - */ - private function validateInlineComment(File $phpcsFile, $stackPtr, array $tokens) - { - if ($tokens[$stackPtr + 1]['content'] !== TokenizerSymbolsInterface::WHITESPACE) { - $phpcsFile->addWarning('Inline comment should have 1 space after "//"', $stackPtr, 'SpaceMissedAfter'); - } - if ($tokens[$stackPtr - 1]['content'] !== TokenizerSymbolsInterface::WHITESPACE) { - $phpcsFile->addWarning('Inline comment should have 1 space before "//"', $stackPtr, 'SpaceMissedBefore'); - } - } - - /** - * Check is it n-th level comment was found - * - * @param File $phpcsFile - * @param int $stackPtr - * @param array $tokens - * @return bool - */ - private function isNthLevelComment(File $phpcsFile, $stackPtr, array $tokens) - { - $nthLevelCommentFound = false; - $levelComment = 0; - - foreach ($this->levelComments as $code => $comment) { - $levelComment = $phpcsFile->findNext($comment, $stackPtr, null, false, $code); - if (false !== $levelComment) { - $nthLevelCommentFound = true; - break; - } - } - - if (false === $nthLevelCommentFound) { - return false; - } - - $currentLine = $tokens[$stackPtr]['line']; - $levelCommentLine = $tokens[$levelComment]['line']; - - if ($currentLine !== $levelCommentLine) { - return false; - } - - return true; - } - - /** - * Check is it n-th level comment is correct - * - * @param File $phpcsFile - * @param int $stackPtr - * @param array $tokens - * @return bool - */ - private function checkNthLevelComment(File $phpcsFile, $stackPtr, array $tokens) - { - $correct = false; - - $nextLine = $phpcsFile->findNext( - T_WHITESPACE, - $stackPtr, - null, - false, - TokenizerSymbolsInterface::NEW_LINE - ); - - if (false === $nextLine) { - return $correct; - } - - if (($tokens[$nextLine]['content'] !== TokenizerSymbolsInterface::NEW_LINE) - || ($tokens[$nextLine + 1]['content'] !== TokenizerSymbolsInterface::NEW_LINE) - ) { - return $correct; - } - - $commentLinePtr = $stackPtr; - while ($tokens[$commentLinePtr - 2]['line'] > 1) { - $commentLinePtr = $phpcsFile->findPrevious(T_STRING, $commentLinePtr - 1, null, false, '//'); - - if (false === $commentLinePtr) { - continue; - } - - if (($tokens[$commentLinePtr - 1]['content'] === TokenizerSymbolsInterface::NEW_LINE) - && ($tokens[$commentLinePtr - 2]['content'] === TokenizerSymbolsInterface::NEW_LINE) - ) { - $correct = true; - break; - } - } - - return $correct; - } -} diff --git a/Magento/Sniffs/Less/ImportantPropertySniff.php b/Magento/Sniffs/Less/ImportantPropertySniff.php deleted file mode 100644 index c097bae1..00000000 --- a/Magento/Sniffs/Less/ImportantPropertySniff.php +++ /dev/null @@ -1,51 +0,0 @@ -getTokens(); - - // Will be implemented in MAGETWO-49778 - //$phpcsFile->addWarning('!important is used', $stackPtr, '!ImportantIsUsed'); - - if (($tokens[$stackPtr + 1]['content'] === 'important') - && ($tokens[$stackPtr - 1]['content'] !== TokenizerSymbolsInterface::WHITESPACE) - ) { - $phpcsFile->addWarning('Space before !important is missing', $stackPtr, 'NoSpace'); - } - } -} diff --git a/Magento/Sniffs/Less/IndentationSniff.php b/Magento/Sniffs/Less/IndentationSniff.php deleted file mode 100644 index aeaaf89a..00000000 --- a/Magento/Sniffs/Less/IndentationSniff.php +++ /dev/null @@ -1,106 +0,0 @@ -getTokens(); - - $numTokens = (count($tokens) - 2); - $indentLevel = 0; - for ($i = 1; $i < $numTokens; $i++) { - if ($tokens[$i]['code'] === T_COMMENT) { - // Don't check the indent of comments. - continue; - } - - if ($tokens[$i]['code'] === T_OPEN_CURLY_BRACKET) { - $indentLevel++; - } elseif ($tokens[($i + 1)]['code'] === T_CLOSE_CURLY_BRACKET) { - $indentLevel--; - } - - if ($tokens[$i]['column'] !== 1) { - continue; - } - - // We started a new line, so check indent. - if ($tokens[$i]['code'] === T_WHITESPACE) { - $content = str_replace($phpcsFile->eolChar, '', $tokens[$i]['content']); - $foundIndent = strlen($content); - } else { - $foundIndent = 0; - } - - $expectedIndent = ($indentLevel * $this->indent); - if (!($expectedIndent > 0 && strpos($tokens[$i]['content'], $phpcsFile->eolChar) !== false) - && ($foundIndent !== $expectedIndent) - && (!in_array($tokens[$i + 1]['code'], $this->styleCodesToSkip)) - ) { - $error = 'Line indented incorrectly; expected %s spaces, found %s'; - $phpcsFile->addWarning($error, $i, 'Incorrect', [$expectedIndent, $foundIndent]); - } - - if ($indentLevel > $this->maxIndentLevel) { - // Will be implemented in MAGETWO-49778 - // $phpcsFile->addWarning('Avoid using more than three levels of nesting', $i, 'IncorrectNestingLevel'); - } - } - } -} diff --git a/Magento/Sniffs/Less/PropertiesLineBreakSniff.php b/Magento/Sniffs/Less/PropertiesLineBreakSniff.php deleted file mode 100644 index 23c130b5..00000000 --- a/Magento/Sniffs/Less/PropertiesLineBreakSniff.php +++ /dev/null @@ -1,52 +0,0 @@ -getTokens(); - - $prevPtr = $phpcsFile->findPrevious(T_SEMICOLON, ($stackPtr - 1)); - if (false === $prevPtr) { - return; - } - - if ($tokens[$prevPtr]['line'] === $tokens[$stackPtr]['line']) { - $error = 'Each property must be on a line by itself'; - $phpcsFile->addWarning($error, $stackPtr, 'SameLine'); - } - } -} diff --git a/Magento/Sniffs/Less/PropertiesSortingSniff.php b/Magento/Sniffs/Less/PropertiesSortingSniff.php deleted file mode 100644 index 4ad04444..00000000 --- a/Magento/Sniffs/Less/PropertiesSortingSniff.php +++ /dev/null @@ -1,119 +0,0 @@ -getTokens(); - $currentToken = $tokens[$stackPtr]; - - // if variables, mixins, extends area used - skip - if ((T_ASPERAND === $tokens[$stackPtr - 1]['code']) - || in_array($tokens[$stackPtr]['content'], $this->styleSymbolsToSkip) - ) { - return; - } - - $nextCurlyBracket = $phpcsFile->findNext(T_OPEN_CURLY_BRACKET, $stackPtr + 1); - if (in_array($currentToken['code'], [T_OPEN_CURLY_BRACKET, T_CLOSE_CURLY_BRACKET]) - || ((false !== $nextCurlyBracket) && ($tokens[$nextCurlyBracket]['line'] === $tokens[$stackPtr]['line'])) - ) { - if ($this->properties) { - // validate collected properties before erase them - $this->validatePropertiesSorting($phpcsFile, $stackPtr, $this->properties); - } - - $this->properties = []; - return; - } - - if (T_STYLE === $currentToken['code']) { - $this->properties[] = $currentToken['content']; - } - } - - /** - * Validate sorting of properties of class - * - * @param File $phpcsFile - * @param int $stackPtr - * @param array $properties - * - * @return void - */ - private function validatePropertiesSorting(File $phpcsFile, $stackPtr, array $properties) - { - // Fix needed for cases when incorrect properties passed for validation due to bug in PHP tokens. - $symbolsForSkip = ['(', 'block', 'field']; - $properties = array_filter( - $properties, - function ($var) use ($symbolsForSkip) { - return !in_array($var, $symbolsForSkip); - } - ); - - $originalProperties = $properties; - sort($properties); - - if ($originalProperties !== $properties) { - $delimiter = $phpcsFile->findPrevious(T_SEMICOLON, $stackPtr); - $phpcsFile->addWarning('Properties sorted not alphabetically', $delimiter, 'PropertySorting'); - } - } -} diff --git a/Magento/Sniffs/Less/QuotesSniff.php b/Magento/Sniffs/Less/QuotesSniff.php deleted file mode 100644 index fb5bb1d8..00000000 --- a/Magento/Sniffs/Less/QuotesSniff.php +++ /dev/null @@ -1,46 +0,0 @@ -getTokens(); - - if (false !== strpos($tokens[$stackPtr]['content'], '"')) { - $phpcsFile->addWarning('Use single quotes', $stackPtr, 'DoubleQuotes'); - } - } -} diff --git a/Magento/Sniffs/Less/SelectorDelimiterSniff.php b/Magento/Sniffs/Less/SelectorDelimiterSniff.php deleted file mode 100644 index 838f00d6..00000000 --- a/Magento/Sniffs/Less/SelectorDelimiterSniff.php +++ /dev/null @@ -1,90 +0,0 @@ -getTokens(); - - // Check that there's no spaces before delimiter - if ($tokens[$stackPtr - 1]['code'] === T_WHITESPACE) { - $phpcsFile->addWarning('Spaces should not be before delimiter', $stackPtr - 1, 'SpacesBeforeDelimiter'); - } - - $this->validateParenthesis($phpcsFile, $stackPtr, $tokens); - } - - /** - * Parenthesis validation. - * - * @param File $phpcsFile - * @param int $stackPtr - * @param array $tokens - * @return void - */ - private function validateParenthesis(File $phpcsFile, $stackPtr, array $tokens) - { - $nextPtr = $stackPtr + 1; - - $nextClassPtr = $phpcsFile->findNext(T_STRING_CONCAT, $nextPtr); - $nextOpenBrace = $phpcsFile->findNext(T_OPEN_CURLY_BRACKET, $nextPtr); - - if ($nextClassPtr === false || $nextOpenBrace === false) { - return; - } - - $stackLine = $tokens[$stackPtr]['line']; - $nextClassLine = $tokens[$nextPtr]['line']; - $nextOpenBraceLine = $tokens[$nextOpenBrace]['line']; - - // Check that each class declaration goes from new line - if (($stackLine === $nextClassLine) && ($stackLine === $nextOpenBraceLine)) { - $prevParenthesis = $phpcsFile->findPrevious(T_OPEN_PARENTHESIS, $stackPtr); - $nextParenthesis = $phpcsFile->findNext(T_OPEN_PARENTHESIS, $stackPtr); - - if ((false !== $prevParenthesis) && (false !== $nextParenthesis) - && ($tokens[$prevParenthesis]['line'] === $tokens[$stackPtr]['line']) - && ($tokens[$nextParenthesis]['line'] === $tokens[$stackPtr]['line']) - ) { - return; - } - - $error = 'Add a line break after each selector delimiter'; - $phpcsFile->addWarning($error, $nextOpenBrace, 'LineBreakAfterDelimiter'); - } - } -} diff --git a/Magento/Sniffs/Less/SemicolonSpacingSniff.php b/Magento/Sniffs/Less/SemicolonSpacingSniff.php deleted file mode 100644 index 12bb3e7c..00000000 --- a/Magento/Sniffs/Less/SemicolonSpacingSniff.php +++ /dev/null @@ -1,115 +0,0 @@ -getTokens(); - - if (in_array($tokens[$stackPtr]['content'], $this->styleSymbolsToSkip)) { - return; - } - - $semicolonPtr = $phpcsFile->findNext(T_SEMICOLON, ($stackPtr + 1)); - if ($tokens[$semicolonPtr]['line'] !== $tokens[$stackPtr]['line']) { - $semicolonPtr = $phpcsFile->findNext(T_STYLE, ($stackPtr + 1), null, false, ";"); - } - - $this->validateSemicolon($phpcsFile, $stackPtr, $tokens, $semicolonPtr); - $this->validateSpaces($phpcsFile, $stackPtr, $tokens, $semicolonPtr); - } - - /** - * Semicolon validation. - * - * @param File $phpcsFile - * @param int $stackPtr - * @param array $tokens - * @param int $semicolonPtr - * @return void - */ - private function validateSemicolon(File $phpcsFile, $stackPtr, array $tokens, $semicolonPtr) - { - if ((false === $semicolonPtr || $tokens[$semicolonPtr]['line'] !== $tokens[$stackPtr]['line']) - && (isset($tokens[$stackPtr - 1]) && !in_array($tokens[$stackPtr - 1]['code'], $this->styleCodesToSkip)) - && (T_COLON !== $tokens[$stackPtr + 1]['code']) - ) { - $error = 'Style definitions must end with a semicolon'; - $phpcsFile->addWarning($error, $stackPtr, 'NotAtEnd'); - } - } - - /** - * Spaces validation. - * - * @param File $phpcsFile - * @param int $stackPtr - * @param array $tokens - * @param int $semicolonPtr - * @return void - */ - private function validateSpaces(File $phpcsFile, $stackPtr, array $tokens, $semicolonPtr) - { - if (!isset($tokens[($semicolonPtr - 1)])) { - return; - } - - if ($tokens[($semicolonPtr - 1)]['code'] === T_WHITESPACE) { - $length = strlen($tokens[($semicolonPtr - 1)]['content']); - $error = 'Expected 0 spaces before semicolon in style definition; %s found'; - $data = [$length]; - $phpcsFile->addWarning($error, $stackPtr, 'SpaceFound', $data); - } - } -} diff --git a/Magento/Sniffs/Less/TokenizerSymbolsInterface.php b/Magento/Sniffs/Less/TokenizerSymbolsInterface.php deleted file mode 100644 index db6a2fe1..00000000 --- a/Magento/Sniffs/Less/TokenizerSymbolsInterface.php +++ /dev/null @@ -1,27 +0,0 @@ -getTokens(); - - if (0 === strpos($tokens[$stackPtr + 1]['content'], '-') - && in_array($tokens[$stackPtr - 1]['content'], $this->symbolsBeforeConcat) - ) { - $phpcsFile->addWarning('Concatenation is used', $stackPtr, 'ConcatenationUsage'); - } - } -} diff --git a/Magento/Sniffs/Less/TypeSelectorsSniff.php b/Magento/Sniffs/Less/TypeSelectorsSniff.php deleted file mode 100644 index 5d2823f8..00000000 --- a/Magento/Sniffs/Less/TypeSelectorsSniff.php +++ /dev/null @@ -1,97 +0,0 @@ -getTokens(); - - $bracketPtr = $phpcsFile->findNext(T_OPEN_CURLY_BRACKET, $stackPtr); - - if (false === $bracketPtr) { - return; - } - - $isBracketOnSameLane = (bool)($tokens[$bracketPtr]['line'] === $tokens[$stackPtr]['line']); - - if (!$isBracketOnSameLane) { - return; - } - - if ((T_STRING === $tokens[$stackPtr - 1]['code']) - && in_array($tokens[$stackPtr - 1]['content'], $this->tags) - ) { - // Will be implemented in MAGETWO-49778 - //$phpcsFile->addWarning('Type selector is used', $stackPtr, 'TypeSelector'); - } - - for ($i = $stackPtr; $i < $bracketPtr; $i++) { - if (preg_match('/[A-Z]/', $tokens[$i]['content'])) { - $phpcsFile->addWarning('Selector contains uppercase symbols', $stackPtr, 'UpperCaseSelector'); - } - } - } -} diff --git a/Magento/Sniffs/Less/VariablesSniff.php b/Magento/Sniffs/Less/VariablesSniff.php deleted file mode 100644 index 3663254f..00000000 --- a/Magento/Sniffs/Less/VariablesSniff.php +++ /dev/null @@ -1,80 +0,0 @@ -getTokens(); - $currentToken = $tokens[$stackPtr]; - - $nextColon = $phpcsFile->findNext(T_COLON, $stackPtr); - $nextSemicolon = $phpcsFile->findNext(T_SEMICOLON, $stackPtr); - if ((false === $nextColon) || (false === $nextSemicolon)) { - return; - } - - $isVariableDeclaration = ($currentToken['line'] === $tokens[$nextColon]['line']) - && ($currentToken['line'] === $tokens[$nextSemicolon]['line']) - && (T_STRING === $tokens[$stackPtr + 1]['code']) - && (T_COLON === $tokens[$stackPtr + 2]['code']); - - if (!$isVariableDeclaration) { - return; - } - - $classBefore = $phpcsFile->findPrevious(T_STYLE, $stackPtr); - if (false !== $classBefore) { - $phpcsFile->addWarning( - 'Variable declaration located not in the beginning of general comments', - $stackPtr, - 'VariableLocation' - ); - } - - $variableName = $tokens[$stackPtr + 1]['content']; - if (preg_match('/[A-Z]/', $variableName)) { - $phpcsFile->addWarning( - 'Variable declaration contains uppercase symbols', - $stackPtr, - 'VariableUppercase' - ); - } - } -} diff --git a/Magento/Sniffs/Less/ZeroUnitsSniff.php b/Magento/Sniffs/Less/ZeroUnitsSniff.php deleted file mode 100644 index 6ab2fc6c..00000000 --- a/Magento/Sniffs/Less/ZeroUnitsSniff.php +++ /dev/null @@ -1,78 +0,0 @@ -getTokens(); - $tokenCode = $tokens[$stackPtr]['code']; - $tokenContent = $tokens[$stackPtr]['content']; - - $nextToken = $tokens[$stackPtr + 1]; - - if (T_LNUMBER === $tokenCode - && "0" === $tokenContent - && T_STRING === $nextToken['code'] - && in_array($nextToken['content'], $this->units) - ) { - $phpcsFile->addWarning('Units specified for "0" value', $stackPtr, 'ZeroUnitFound'); - } - - if ((T_DNUMBER === $tokenCode) - && 0 === strpos($tokenContent, "0") - && ((float)$tokenContent < 1) - ) { - $phpcsFile->addWarning('Values starts from "0"', $stackPtr, 'ZeroUnitFound'); - } - } -} diff --git a/Magento/ruleset.xml b/Magento/ruleset.xml index b009a662..3e80c1cb 100644 --- a/Magento/ruleset.xml +++ b/Magento/ruleset.xml @@ -89,9 +89,6 @@ 10 - - 6 - 6