Skip to content

Commit 6be24db

Browse files
authored
Merge pull request #27 from magento-commerce/imported-magento-magento-coding-standard-229
[Imported] AC-939: Create unit test for Magento2\Less\AvoidIdSniff check
2 parents dd0f63b + e538e6f commit 6be24db

File tree

5 files changed

+123
-2
lines changed

5 files changed

+123
-2
lines changed

Diff for: Magento2/Sniffs/Less/AvoidIdSniff.php

+1
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ class AvoidIdSniff implements Sniff
5151
T_PLUS,
5252
T_NS_SEPARATOR,
5353
T_LNUMBER,
54+
T_BITWISE_NOT
5455
];
5556

5657
/**
+33
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
/**
3+
* Copyright © Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento2\Tests\Less;
7+
8+
use PHP_CodeSniffer\Config;
9+
use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;
10+
11+
/**
12+
* Implements an abstract base for unit tests that cover less sniffs.
13+
*/
14+
abstract class AbstractLessSniffUnitTestCase extends AbstractSniffUnitTest
15+
{
16+
/**
17+
* @inheritDoc
18+
*/
19+
protected function setUp(): void
20+
{
21+
parent::setUp();
22+
23+
$config = new Config();
24+
$config->extensions = array_merge(
25+
$config->extensions,
26+
[
27+
'less' => 'CSS'
28+
]
29+
);
30+
31+
$GLOBALS['PHP_CODESNIFFER_CONFIG'] = $config;
32+
}
33+
}

Diff for: Magento2/Tests/Less/AvoidIdUnitTest.less

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// /**
2+
// * Copyright © Magento, Inc. All rights reserved.
3+
// * See COPYING.txt for license details.
4+
// */
5+
6+
#foo[bar],
7+
#foo[bar=bash],
8+
#foo[bar~=bash],
9+
#foo[bar$=bash],
10+
#foo[bar*=bash],
11+
#foo[bar|=bash],
12+
#foo[bar='bash'],
13+
#foo:hover,
14+
#foo:nth-last-of-type(n),
15+
#foo::before,
16+
#foo + div,
17+
#foo > div,
18+
#foo ~ div,
19+
#foo\3Abar ~ div,
20+
#foo\:bar ~ div,
21+
#foo.bar .baz,
22+
div#foo {
23+
blah: 'abc';
24+
}
25+
26+
.my #foo,
27+
#foo .blah,
28+
.my #foo .blah {
29+
some: 'stuff';
30+
}
31+
.blah {
32+
#bar .baz();
33+
.foo #bar .baz();
34+
#bar .baz();
35+
36+
#bar .baz;
37+
.foo #bar .baz;
38+
#bar .baz;
39+
}

Diff for: Magento2/Tests/Less/AvoidIdUnitTest.php

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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 AvoidIdUnitTest extends AbstractLessSniffUnitTestCase
9+
{
10+
/**
11+
* @inheritdoc
12+
*/
13+
public function getErrorList()
14+
{
15+
return [
16+
6 => 1,
17+
7 => 1,
18+
8 => 1,
19+
9 => 1,
20+
10 => 1,
21+
11 => 1,
22+
12 => 1,
23+
13 => 1,
24+
14 => 1,
25+
15 => 1,
26+
16 => 1,
27+
17 => 1,
28+
18 => 1,
29+
19 => 1,
30+
20 => 1,
31+
21 => 1,
32+
22 => 1,
33+
26 => 1,
34+
27 => 1,
35+
28 => 1
36+
];
37+
}
38+
39+
/**
40+
* @inheritdoc
41+
*/
42+
public function getWarningList()
43+
{
44+
return [];
45+
}
46+
}

Diff for: Magento2/ruleset.xml

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<description>Magento Coding Standard</description>
44

55
<!-- File extensions to be checked. -->
6-
<arg name="extensions" value="php,phtml,graphqls/GraphQL"/>
6+
<arg name="extensions" value="php,phtml,graphqls/GraphQL,less/CSS,html/PHP"/>
77

88
<!-- Severity 10 errors: Critical code issues. -->
99
<rule ref="Generic.Functions.CallTimePassByReference">
@@ -590,7 +590,9 @@
590590
<exclude-pattern>*Test.php</exclude-pattern>
591591
</rule>
592592
<rule ref="Magento2.Html"/>
593-
<rule ref="Magento2.Less"/>
593+
<rule ref="Magento2.Less">
594+
<include-pattern>*\.less$</include-pattern>
595+
</rule>
594596
<rule ref="Internal.NoCodeFound">
595597
<severity>0</severity>
596598
</rule>

0 commit comments

Comments
 (0)