Skip to content

Commit d18cd88

Browse files
committed
Changed the way this was done because it couldnt cope with blank lines between class definitions inside the same nested block (like the ones used for spacing between classes).
1 parent f091519 commit d18cd88

File tree

2 files changed

+27
-12
lines changed

2 files changed

+27
-12
lines changed

CodeSniffer/Standards/Squiz/Sniffs/CSS/IndentationSniff.php

+15-12
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
6161
{
6262
$tokens = $phpcsFile->getTokens();
6363

64-
$numTokens = (count($tokens) - 2);
65-
$currentLine = 0;
66-
$indentLevel = 0;
67-
$nested = false;
64+
$numTokens = (count($tokens) - 2);
65+
$currentLine = 0;
66+
$indentLevel = 0;
67+
$nestingLevel = 0;
6868
for ($i = 1; $i < $numTokens; $i++) {
6969
if ($tokens[$i]['code'] === T_COMMENT) {
7070
// Dont check the indent of comments.
@@ -74,12 +74,14 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
7474
if ($tokens[$i]['code'] === T_OPEN_CURLY_BRACKET) {
7575
$indentLevel++;
7676

77-
// Check for nested style definitions as, for example, in @media style rules.
78-
$found = $phpcsFile->findNext(T_OPEN_CURLY_BRACKET, ($i + 1), $tokens[$i]['bracket_closer']);
79-
if ($found === false) {
80-
$nested = false;
81-
} else {
82-
$nested = true;
77+
// Check for nested class definitions.
78+
$found = $phpcsFile->findNext(
79+
T_OPEN_CURLY_BRACKET,
80+
($i + 1),
81+
$tokens[$i]['bracket_closer']
82+
);
83+
if ($found !== false) {
84+
$nestingLevel = $indentLevel;
8385
}
8486
} else if ($tokens[($i + 1)]['code'] === T_CLOSE_CURLY_BRACKET) {
8587
$indentLevel--;
@@ -98,8 +100,9 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
98100
}
99101

100102
$expectedIndent = ($indentLevel * 4);
101-
if ($expectedIndent > 0 && strpos($tokens[$i]['content'], $phpcsFile->eolChar) !== false) {
102-
if ($nested === false) {
103+
if ($expectedIndent > 0 && strpos($tokens[$i]['content'], $phpcsFile->eolChar) !== false
104+
) {
105+
if ($nestingLevel !== $indentLevel) {
103106
$error = 'Blank lines are not allowed in class definitions';
104107
$phpcsFile->addError($error, $i, 'BlankLine');
105108
}

CodeSniffer/Standards/Squiz/Tests/CSS/IndentationUnitTest.css

+12
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,15 @@ td {
3030
margin: 40px;
3131
}
3232
}
33+
34+
@media screen and (max-device-width: 769px) {
35+
36+
header #logo img {
37+
max-width: 100%;
38+
}
39+
40+
header #logo img {
41+
min-width: 100%;
42+
}
43+
44+
}

0 commit comments

Comments
 (0)