Skip to content

Commit 1e3a89f

Browse files
authored
Merge pull request #54 from magento-commerce/imported-magento-magento-coding-standard-258
[Imported] AC-1100 Catch badly put newlines in LESS files
2 parents d321823 + e2aa287 commit 1e3a89f

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

Magento2/Sniffs/Less/ColonSpacingSniff.php

+12-11
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,7 @@ public function process(File $phpcsFile, $stackPtr)
5656
*/
5757
private function needValidateSpaces(File $phpcsFile, $stackPtr, $tokens)
5858
{
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-
) {
59+
if (TokenizerSymbolsInterface::BITWISE_AND === $tokens[$stackPtr - 1]['content']) {
6560
return false;
6661
}
6762

@@ -80,7 +75,10 @@ private function needValidateSpaces(File $phpcsFile, $stackPtr, $tokens)
8075
}
8176

8277
/**
83-
* Validate Colon Spacing according to requirements
78+
* Validate Colon Spacing according to requirements:
79+
* - No spaces before colon
80+
* - Exactly 1 space after colon
81+
* - No property definition scattered among several lines
8482
*
8583
* @param File $phpcsFile
8684
* @param int $stackPtr
@@ -94,19 +92,22 @@ private function validateSpaces(File $phpcsFile, $stackPtr, array $tokens)
9492
$phpcsFile->addError('There must be no space before a colon in a style definition', $stackPtr, 'Before');
9593
}
9694

95+
$nextSemicolon = $phpcsFile->findNext(T_SEMICOLON, $stackPtr);
96+
if (false !== $nextSemicolon && ($tokens[$nextSemicolon]['line'] !== $tokens[$stackPtr]['line'])) {
97+
$error = 'Expected 1 space after colon in style definition; newline found';
98+
$phpcsFile->addError($error, $stackPtr, 'AfterNewline');
99+
}
100+
97101
if (T_WHITESPACE !== $tokens[($stackPtr + 1)]['code']) {
98102
$phpcsFile->addError('Expected 1 space after colon in style definition; 0 found', $stackPtr, 'NoneAfter');
99103
} else {
100104
$content = $tokens[($stackPtr + 1)]['content'];
101-
if (false === strpos($content, $phpcsFile->eolChar)) {
105+
if (false !== strpos($content, ' ')) {
102106
$length = strlen($content);
103107
if ($length !== 1) {
104108
$error = sprintf('Expected 1 space after colon in style definition; %s found', $length);
105109
$phpcsFile->addError($error, $stackPtr, 'After');
106110
}
107-
} else {
108-
$error = 'Expected 1 space after colon in style definition; newline found';
109-
$phpcsFile->addError($error, $stackPtr, 'AfterNewline');
110111
}
111112
}
112113
}

Magento2/Tests/Less/ColonSpacingUnitTest.less

+1-1
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

+1
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)