Chris@0: getTokens(); Chris@0: Chris@0: // Do not check nested style definitions as, for example, in @media style rules. Chris@0: $nested = $phpcsFile->findNext(T_OPEN_CURLY_BRACKET, ($stackPtr + 1), $tokens[$stackPtr]['bracket_closer']); Chris@0: if ($nested !== false) { Chris@0: return; Chris@0: } Chris@0: Chris@0: // Find the first blank line before this opening brace, unless we get Chris@0: // to another style definition, comment or the start of the file. Chris@0: $endTokens = array( Chris@0: T_OPEN_CURLY_BRACKET => T_OPEN_CURLY_BRACKET, Chris@0: T_CLOSE_CURLY_BRACKET => T_CLOSE_CURLY_BRACKET, Chris@0: T_OPEN_TAG => T_OPEN_TAG, Chris@0: ); Chris@17: $endTokens += Tokens::$commentTokens; Chris@0: Chris@0: $foundContent = false; Chris@0: $currentLine = $tokens[$stackPtr]['line']; Chris@0: for ($i = ($stackPtr - 1); $i >= 0; $i--) { Chris@0: if (isset($endTokens[$tokens[$i]['code']]) === true) { Chris@0: break; Chris@0: } Chris@0: Chris@0: // A comma must be followed by a new line character. Chris@0: if ($tokens[$i]['code'] === T_COMMA Chris@0: && strpos($tokens[($i + 1)]['content'], $phpcsFile->eolChar) === false Chris@0: ) { Chris@0: $error = 'Multiple selectors should each be on a single line'; Chris@0: $fix = $phpcsFile->addFixableError($error, ($i + 1), 'MultipleSelectors'); Chris@0: if ($fix === true) { Chris@0: $phpcsFile->fixer->addNewline($i); Chris@0: } Chris@0: } Chris@0: Chris@0: // Selectors must be on the same line. Chris@0: if ($tokens[$i]['code'] === T_WHITESPACE Chris@0: && strpos($tokens[$i]['content'], $phpcsFile->eolChar) !== false Chris@0: && isset($endTokens[$tokens[($i - 1)]['code']]) === false Chris@0: && in_array($tokens[($i - 1)]['code'], array(T_WHITESPACE, T_COMMA)) === false Chris@0: ) { Chris@0: $error = 'Selectors must be on a single line'; Chris@0: $fix = $phpcsFile->addFixableError($error, $i, 'SeletorSingleLine'); Chris@0: if ($fix === true) { Chris@0: $phpcsFile->fixer->replaceToken($i, str_replace($phpcsFile->eolChar, ' ', $tokens[$i]['content'])); Chris@0: } Chris@0: } Chris@0: Chris@0: if ($tokens[$i]['line'] === $currentLine) { Chris@0: if ($tokens[$i]['code'] !== T_WHITESPACE) { Chris@0: $foundContent = true; Chris@0: } Chris@0: Chris@0: continue; Chris@0: } Chris@0: Chris@0: // We changed lines. Chris@0: if ($foundContent === false) { Chris@0: // Before we throw an error, make sure we are not looking Chris@0: // at a gap before the style definition. Chris@0: $prev = $phpcsFile->findPrevious(T_WHITESPACE, $i, null, true); Chris@0: if ($prev !== false Chris@0: && isset($endTokens[$tokens[$prev]['code']]) === false Chris@0: ) { Chris@0: $error = 'Blank lines are not allowed between class names'; Chris@0: $fix = $phpcsFile->addFixableError($error, ($i + 1), 'BlankLinesFound'); Chris@0: if ($fix === true) { Chris@0: $phpcsFile->fixer->replaceToken(($i + 1), ''); Chris@0: } Chris@0: } Chris@0: Chris@0: break; Chris@0: } Chris@0: Chris@0: $foundContent = false; Chris@0: $currentLine = $tokens[$i]['line']; Chris@0: }//end for Chris@0: Chris@0: }//end process() Chris@0: Chris@0: Chris@0: }//end class