Skip to content

Commit

Permalink
Merge pull request #188 from magento-commerce/imported-svera-magento-…
Browse files Browse the repository at this point in the history
…coding-standard-405

[Imported] AC-3520: Avoid processing less and CSS pseudo-classes
  • Loading branch information
svera authored Jun 20, 2022
2 parents f5b3d0e + 31335a0 commit 756ca2d
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 8 deletions.
7 changes: 4 additions & 3 deletions Magento2/Sniffs/Less/ColonSpacingSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,13 @@ private function needValidateSpaces(File $phpcsFile, $stackPtr, $tokens)
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.
// Avoid false positives when parsing pseudo-classes
$next = $phpcsFile->findNext([T_SEMICOLON, T_OPEN_CURLY_BRACKET], $stackPtr + 1);
if ($tokens[$next]['code'] === T_OPEN_CURLY_BRACKET) {
return false;
}

$prev = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true);
if ($tokens[$prev]['content'] === 'progid') {
// Special case for IE filters.
return false;
Expand Down
34 changes: 29 additions & 5 deletions Magento2/Tests/Less/ColonSpacingUnitTest.less
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,46 @@


div#foo {
blah:'abc';
blah:'abc';
}

.my #foo .blah {
some: 'stuff';
some: 'stuff';
}

.blah {
foo :'jkl';
foo :'jkl';
}

.foo {
bar:
bar:
'xyz';
}

.right {
way: 'good'
way: 'good';
}

a:active {
color: #000;
}

@abs-action-button-as-link: {
&:not(:focus) {
box-shadow: none;
}
}

.actions-toolbar {
&:not(:first-child) {
&:extend(.abs-add-clearfix all);
> .secondary {
.action {
&.add {
margin-top: @indent__l;
}
}
float: left;
}
}
}

0 comments on commit 756ca2d

Please sign in to comment.