Skip to content

Commit 0759da9

Browse files
[Imported] AC-941: Create unit test for Magento2\Less\ClassNamingSniff check (#38)
https://jira.corp.magento.com/browse/AC-941
1 parent 4b2ca82 commit 0759da9

File tree

3 files changed

+76
-5
lines changed

3 files changed

+76
-5
lines changed

Magento2/Sniffs/Less/ClassNamingSniff.php

+14-5
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,7 @@
2121
*/
2222
class ClassNamingSniff implements Sniff
2323
{
24-
25-
const STRING_HELPER_CLASSES_PREFIX = '_';
26-
27-
const STRING_ALLOWED_UNDERSCORES = '__';
24+
private const STRING_HELPER_CLASSES_PREFIX = '_';
2825

2926
/**
3027
* A list of tokenizers this sniff supports.
@@ -62,7 +59,19 @@ public function process(File $phpcsFile, $stackPtr)
6259

6360
$className = $tokens[$stackPtr + 1]['content'];
6461
if (preg_match_all('/[^a-z0-9\-_]/U', $className, $matches)) {
65-
$phpcsFile->addError('Class name contains not allowed symbols', $stackPtr, 'NotAllowedSymbol', $matches);
62+
$phpcsFile->addError(
63+
'CSS class name does not follow class naming requirements: %s',
64+
$stackPtr,
65+
'NotAllowedSymbol',
66+
[implode("", $matches[0])]
67+
);
68+
}
69+
if (strpos($className, self::STRING_HELPER_CLASSES_PREFIX, 2) !== false) {
70+
$phpcsFile->addError(
71+
'CSS class names should be separated with "-" (dash) instead of "_" (underscore)',
72+
$stackPtr,
73+
'NotAllowedSymbol'
74+
);
6675
}
6776
}
6877
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// /**
2+
// * Copyright © Magento, Inc. All rights reserved.
3+
// * See COPYING.txt for license details.
4+
// */
5+
6+
.UPPERCASE {
7+
background: red;
8+
}
9+
10+
.Capital {
11+
background: red;
12+
}
13+
14+
.camelCase {
15+
background: red;
16+
}
17+
18+
.snake_case {
19+
background: red;
20+
}
21+
22+
._helper {
23+
background: green;
24+
}
25+
26+
.__another-helper {
27+
background: green;
28+
}
29+
30+
.category-title {
31+
background: green;
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
/**
3+
* Copyright © Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento2\Tests\Less;
7+
8+
class ClassNamingUnitTest extends AbstractLessSniffUnitTestCase
9+
{
10+
/**
11+
* @inheritdoc
12+
*/
13+
public function getErrorList()
14+
{
15+
return [
16+
6 => 1,
17+
10 => 1,
18+
14 => 1,
19+
18 => 1
20+
];
21+
}
22+
23+
/**
24+
* @inheritdoc
25+
*/
26+
public function getWarningList()
27+
{
28+
return [];
29+
}
30+
}

0 commit comments

Comments
 (0)