Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Also lint HTML when not at start of file #443

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: develop
Choose a base branch
Loading
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions 15 Magento2/Sniffs/Html/HtmlClosingVoidTagsSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,16 @@ public function register(): array
*
* @param File $phpcsFile
* @param int $stackPtr
* @return void
*
* @return int
*/
public function process(File $phpcsFile, $stackPtr): void
public function process(File $phpcsFile, $stackPtr): int
{
if ($stackPtr !== 0) {
return;
}
$html = $phpcsFile->getTokensAsString($stackPtr, count($phpcsFile->getTokens()));
$tokenCount = count($phpcsFile->getTokens());
$html = $phpcsFile->getTokensAsString($stackPtr, $tokenCount - $stackPtr);

if (empty($html)) {
return;
return $tokenCount + 1;
}

if (preg_match_all('$<(\w{2,})\s?[^<]*\/>$', $html, $matches, PREG_SET_ORDER)) {
Expand All @@ -92,5 +91,7 @@ public function process(File $phpcsFile, $stackPtr): void
}
}
}

return $tokenCount + 1;
}
}
15 changes: 8 additions & 7 deletions 15 Magento2/Sniffs/Html/HtmlCollapsibleAttributeSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,16 @@ public function register()
*
* @param File $phpcsFile
* @param int $stackPtr
* @return int|void
*
* @return int
*/
public function process(File $phpcsFile, $stackPtr)
public function process(File $phpcsFile, $stackPtr): int
{
if ($stackPtr !== 0) {
return;
}
$html = $phpcsFile->getTokensAsString($stackPtr, count($phpcsFile->getTokens()));
$tokenCount = count($phpcsFile->getTokens());
$html = $phpcsFile->getTokensAsString($stackPtr, $tokenCount - $stackPtr);

if (empty($html)) {
return;
return $tokenCount + 1;
}

$pattern = '$<\w+.*?\s*(?=.*?\s*data-toggle="collapse")[^>]*?>.*?$';
Expand All @@ -54,5 +53,7 @@ public function process(File $phpcsFile, $stackPtr)
);
}
}

return $tokenCount + 1;
}
}
15 changes: 8 additions & 7 deletions 15 Magento2/Sniffs/Html/HtmlDirectiveSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,19 @@ public function register()
*
* @param File $phpcsFile
* @param int $stackPtr
* @return int|void
*
* @return int
*/
public function process(File $phpcsFile, $stackPtr)
public function process(File $phpcsFile, $stackPtr): int
{
$this->usedVariables = [];
$this->unfilteredVariables = [];
if ($stackPtr !== 0) {
return;
}

$html = $phpcsFile->getTokensAsString($stackPtr, count($phpcsFile->getTokens()));
$tokenCount = count($phpcsFile->getTokens());
$html = $phpcsFile->getTokensAsString($stackPtr, $tokenCount - $stackPtr);

if (empty($html)) {
return;
return $tokenCount + 1;
}

$html = $this->processIfDirectives($html, $phpcsFile);
Expand All @@ -66,6 +65,8 @@ public function process(File $phpcsFile, $stackPtr)
$html = $this->processVarDirectivesAndParams($html, $phpcsFile);

$this->validateDefinedVariables($phpcsFile, $html);

return $tokenCount + 1;
}

/**
Expand Down
15 changes: 8 additions & 7 deletions 15 Magento2/Sniffs/Html/HtmlSelfClosingTagsSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,17 +55,16 @@ public function register()
*
* @param File $phpcsFile
* @param int $stackPtr
* @return int|void
*
* @return int
*/
public function process(File $phpcsFile, $stackPtr)
public function process(File $phpcsFile, $stackPtr): int
{
if ($stackPtr !== 0) {
return;
}
$html = $phpcsFile->getTokensAsString($stackPtr, count($phpcsFile->getTokens()));
$tokenCount = count($phpcsFile->getTokens());
$html = $phpcsFile->getTokensAsString($stackPtr, $tokenCount - $stackPtr);

if (empty($html)) {
return;
return $tokenCount + 1;
}

if (preg_match_all('$<(\w{2,})\s?[^<]*\/>$', $html, $matches, PREG_SET_ORDER)) {
Expand All @@ -80,5 +79,7 @@ public function process(File $phpcsFile, $stackPtr)
}
}
}

return $tokenCount + 1;
}
}
35 changes: 35 additions & 0 deletions 35 Magento2/Tests/Html/HtmlClosingVoidTagsUnitTest.2.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
?>

<html>
<head>
<base/>
<link/>
</head>
<body>
<area alt=""/>
<br/>
<table>
<colgroup>
<col/>
</colgroup>
</table>
<embed/>
<hr/>
<img src="" alt=""/>
<input type="text" id="test_input"/>
<keygen/>
<link/>
<meta/>
<param name="" value=""/>
<video>
<source/>
<track src=""/>
</video>
<wbr/>
</body>
</html>
35 changes: 35 additions & 0 deletions 35 Magento2/Tests/Html/HtmlCollapsibleAttributeUnitTest.2.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
?>

<html>
<head>
<base/>
<link/>
</head>
<body>
<div class="action-dropdown">
<button type="button" class="action-toggle" data-mage-init='{"dropdown":{}}' data-toggle="dropdown">
<span>Test</span>
</button>
</div>
<div class="fieldset-wrapper-title">
<strong class="admin__collapsible-title" data-toggle="collapse" data-bind="attr:{'data-target': '#'+id}">
<span data-bind="text: title"></span>
</strong>
</div>
<div class="admin__collapsible-title"
data-toggle="collapse"
data-target="#id-content">
<span>Test</span>
</div>
<strong <?= /* @noEscape */ $isCollapsable ?
'class="admin__collapsible-title" data-toggle="collapse" data-target="#' . $id . '-content"' :
'class="title"'; ?>>
<span><?= $block->escapeHtml($element->getLegend()) ?></span>
</strong>
</body>
</html>
45 changes: 45 additions & 0 deletions 45 Magento2/Tests/Html/HtmlSelfClosingTagsUnitTest.2.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
?>

<html>
<head>
<base/>
<link/>
</head>
<body>
<area alt=""/>
<br/>
<table>
<colgroup>
<col/>
</colgroup>
</table>
<embed/>
<hr/>
<img src="" alt=""/>
<input type="text" id="test_input"/>
<keygen/>
<link/>
<meta/>
<param name="" value=""/>
<video>
<source/>
<track src=""/>
</video>
<wbr/>

<label for="test_input"/>
<style type="text/css"/>
<div/>
<span/>
<text/>
<render/>
<each/>
<translate/>
<scope/>
</body>
</html>
Morty Proxy This is a proxified and sanitized view of the page, visit original site.