From 18700227ea0d2b17d9c40fdc8a077ddfa695452f Mon Sep 17 00:00:00 2001 From: Dan Wallis Date: Tue, 28 Mar 2023 22:20:48 +0100 Subject: [PATCH] Allow use of LESS variables in "class name" --- Magento2/Sniffs/Less/ClassNamingSniff.php | 7 +++++++ Magento2/Tests/Less/ClassNamingUnitTest.less | 8 ++++++++ 2 files changed, 15 insertions(+) diff --git a/Magento2/Sniffs/Less/ClassNamingSniff.php b/Magento2/Sniffs/Less/ClassNamingSniff.php index 3c3d1a86..a1b96725 100644 --- a/Magento2/Sniffs/Less/ClassNamingSniff.php +++ b/Magento2/Sniffs/Less/ClassNamingSniff.php @@ -58,6 +58,13 @@ public function process(File $phpcsFile, $stackPtr) } $className = $tokens[$stackPtr + 1]['content']; + + if (str_contains($className, '@')) { + // "class name" is actually a variable. + // @see https://lesscss.org/features/#variables-feature-variable-interpolation + return; + } + if (preg_match_all('/[^a-z0-9\-_]/U', $className, $matches)) { $phpcsFile->addError( 'CSS class name does not follow class naming requirements: %s', diff --git a/Magento2/Tests/Less/ClassNamingUnitTest.less b/Magento2/Tests/Less/ClassNamingUnitTest.less index b7860bc4..89ff3730 100644 --- a/Magento2/Tests/Less/ClassNamingUnitTest.less +++ b/Magento2/Tests/Less/ClassNamingUnitTest.less @@ -40,3 +40,11 @@ .admin__allowed { background: green; } + +// @see https://github.com/magento/magento-coding-standard/issues/434 +.mixin-example(@my-selector) { + .@{my-selector} { + background: #fff + } +} +.mixin-example(input-box)