Skip to content

Commit 142ef3b

Browse files
committed
AC-1100: Catch badly put newlines in LESS files
1 parent d753278 commit 142ef3b

File tree

3 files changed

+10
-11
lines changed

3 files changed

+10
-11
lines changed

Magento2/Sniffs/Less/ColonSpacingSniff.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ public function process(File $phpcsFile, $stackPtr)
4040
{
4141
$tokens = $phpcsFile->getTokens();
4242

43+
$nextSemicolon = $phpcsFile->findNext(T_SEMICOLON, $stackPtr);
44+
if (false !== $nextSemicolon && ($tokens[$nextSemicolon]['line'] !== $tokens[$stackPtr]['line'])) {
45+
$error = 'Expected 1 space after colon in style definition; newline found';
46+
$phpcsFile->addError($error, $stackPtr, 'AfterNewline');
47+
}
48+
4349
if ($this->needValidateSpaces($phpcsFile, $stackPtr, $tokens)) {
4450
$this->validateSpaces($phpcsFile, $stackPtr, $tokens);
4551
}
@@ -56,12 +62,7 @@ public function process(File $phpcsFile, $stackPtr)
5662
*/
5763
private function needValidateSpaces(File $phpcsFile, $stackPtr, $tokens)
5864
{
59-
$nextSemicolon = $phpcsFile->findNext(T_SEMICOLON, $stackPtr);
60-
61-
if (false === $nextSemicolon
62-
|| ($tokens[$nextSemicolon]['line'] !== $tokens[$stackPtr]['line'])
63-
|| TokenizerSymbolsInterface::BITWISE_AND === $tokens[$stackPtr - 1]['content']
64-
) {
65+
if (TokenizerSymbolsInterface::BITWISE_AND === $tokens[$stackPtr - 1]['content']) {
6566
return false;
6667
}
6768

@@ -98,15 +99,12 @@ private function validateSpaces(File $phpcsFile, $stackPtr, array $tokens)
9899
$phpcsFile->addError('Expected 1 space after colon in style definition; 0 found', $stackPtr, 'NoneAfter');
99100
} else {
100101
$content = $tokens[($stackPtr + 1)]['content'];
101-
if (false === strpos($content, $phpcsFile->eolChar)) {
102+
if (false !== strpos($content, ' ')) {
102103
$length = strlen($content);
103104
if ($length !== 1) {
104105
$error = sprintf('Expected 1 space after colon in style definition; %s found', $length);
105106
$phpcsFile->addError($error, $stackPtr, 'After');
106107
}
107-
} else {
108-
$error = 'Expected 1 space after colon in style definition; newline found';
109-
$phpcsFile->addError($error, $stackPtr, 'AfterNewline');
110108
}
111109
}
112110
}

Magento2/Tests/Less/ColonSpacingUnitTest.less

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ div#foo {
1313
}
1414

1515
.blah {
16-
foo :'xyz';
16+
foo :'jkl';
1717
}
1818

1919
.foo {

Magento2/Tests/Less/ColonSpacingUnitTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public function getErrorList()
1616
8 => 1,
1717
12 => 1,
1818
16 => 2,
19+
20 => 1,
1920
];
2021
}
2122

0 commit comments

Comments
 (0)