Skip to content

Commit 6f2a73b

Browse files
authored
Merge pull request #140 from magento-trigger/AC-99
AC-99: Update Third Party library: jquery.tabs
2 parents 3610044 + b068334 commit 6f2a73b

File tree

4 files changed

+127
-0
lines changed

4 files changed

+127
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
namespace Magento2\Sniffs\Html;
8+
9+
use PHP_CodeSniffer\Sniffs\Sniff;
10+
use PHP_CodeSniffer\Files\File;
11+
12+
/**
13+
* Sniffing improper HTML bindings.
14+
*/
15+
class HtmlCollapsibleAttributeSniff implements Sniff
16+
{
17+
/**
18+
* @inheritDoc
19+
*/
20+
public function register()
21+
{
22+
return [T_INLINE_HTML];
23+
}
24+
25+
/**
26+
* Detect use of data attributes used by older version of bootstrap collapse
27+
*
28+
* Use new attributes in https://getbootstrap.com/docs/5.0/components/collapse/
29+
*
30+
* @param File $phpcsFile
31+
* @param int $stackPtr
32+
* @return int|void
33+
*/
34+
public function process(File $phpcsFile, $stackPtr)
35+
{
36+
if ($stackPtr !== 0) {
37+
return;
38+
}
39+
$html = $phpcsFile->getTokensAsString($stackPtr, count($phpcsFile->getTokens()));
40+
41+
if (empty($html)) {
42+
return;
43+
}
44+
45+
$pattern = '$<\w+.*?\s*(?=.*?\s*data-toggle="collapse")[^>]*?>.*?$';
46+
if (preg_match_all($pattern, $html, $matches, PREG_SET_ORDER)) {
47+
foreach ($matches as $match) {
48+
$phpcsFile->addError(
49+
'Collapsible attributes data-toggle and data-target need to be updated to ' .
50+
'data-bs-toggle and data-bs-target'
51+
. ' - "' . $match[0] . PHP_EOL,
52+
null,
53+
'HtmlCollapsibleAttribute'
54+
);
55+
}
56+
}
57+
}
58+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
<!--
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
-->
7+
8+
<html>
9+
<head>
10+
<base/>
11+
<link/>
12+
</head>
13+
<body>
14+
<div class="action-dropdown">
15+
<button type="button" class="action-toggle" data-mage-init='{"dropdown":{}}' data-toggle="dropdown">
16+
<span>Test</span>
17+
</button>
18+
</div>
19+
<div class="fieldset-wrapper-title">
20+
<strong class="admin__collapsible-title" data-toggle="collapse" data-bind="attr:{'data-target': '#'+id}">
21+
<span data-bind="text: title"></span>
22+
</strong>
23+
</div>
24+
<div class="admin__collapsible-title"
25+
data-toggle="collapse"
26+
data-target="#id-content">
27+
<span>Test</span>
28+
</div>
29+
<strong <?= /* @noEscape */ $isCollapsable ?
30+
'class="admin__collapsible-title" data-toggle="collapse" data-target="#' . $id . '-content"' :
31+
'class="title"'; ?>>
32+
<span><?= $block->escapeHtml($element->getLegend()) ?></span>
33+
</strong>
34+
</body>
35+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?php
2+
/**
3+
* Copyright © Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
namespace Magento2\Tests\Html;
7+
8+
use PHP_CodeSniffer\Tests\Standards\AbstractSniffUnitTest;
9+
10+
class HtmlCollapsibleAttributeUnitTest extends AbstractSniffUnitTest
11+
{
12+
/**
13+
* @inheritdoc
14+
*/
15+
public function getErrorList()
16+
{
17+
return [1 => 3];
18+
}
19+
20+
/**
21+
* @inheritdoc
22+
*/
23+
public function getWarningList()
24+
{
25+
return [];
26+
}
27+
}

Magento2/ruleset.xml

+7
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,13 @@
143143
<type>error</type>
144144
<exclude-pattern>*\.xml$</exclude-pattern>
145145
</rule>
146+
<rule ref="Magento2.Html.HtmlCollapsibleAttribute">
147+
<include-pattern>*\.html$</include-pattern>
148+
<include-pattern>*\.phtml$</include-pattern>
149+
<severity>10</severity>
150+
<type>error</type>
151+
<exclude-pattern>*\.xml$</exclude-pattern>
152+
</rule>
146153
<rule ref="Magento2.Legacy.Layout">
147154
<severity>10</severity>
148155
<type>error</type>

0 commit comments

Comments
 (0)