Skip to content

Commit 440d99d

Browse files
committed
Fixed bug #19283 : CSS @media rules cause false positives
1 parent 1ee835c commit 440d99d

File tree

7 files changed

+27
-1
lines changed

7 files changed

+27
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
7272

7373
if ($tokens[$i]['code'] === T_OPEN_CURLY_BRACKET) {
7474
$indentLevel++;
75-
} else if ($tokens[$i]['code'] === T_CLOSE_CURLY_BRACKET) {
75+
} else if ($tokens[($i + 1)]['code'] === T_CLOSE_CURLY_BRACKET) {
7676
$indentLevel--;
7777
}
7878

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,12 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
6464
$end = $tokens[$stackPtr]['bracket_closer'];
6565
$endLine = $tokens[$end]['line'];
6666

67+
// Do not check nested style definitions as, for example, in @media style rules.
68+
$nested = $phpcsFile->findNext(T_OPEN_CURLY_BRACKET, ($stackPtr + 1), $end);
69+
if ($nested !== false) {
70+
return;
71+
}
72+
6773
$foundColon = false;
6874
$foundString = false;
6975
for ($i = ($stackPtr + 1); $i <= $end; $i++) {

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,11 @@ td {
2121
background: transparent url(images/ScreenImages/tab_on_right.png) no-repeat;
2222
}
2323
*/
24+
25+
@media screen and (max-device-width: 769px) {
26+
header #logo img {
27+
max-width: 100%;
28+
padding: 20px;
29+
margin: 40px;
30+
}
31+
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ public function getErrorList()
4646
6 => 1,
4747
7 => 1,
4848
12 => 1,
49+
27 => 1,
50+
29 => 1,
4951
);
5052

5153
}//end getErrorList()

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,10 @@
55
margin-top: 15px;
66
margin-bottom 15px;
77
}
8+
9+
@media screen and (max-device-width: 769px) {
10+
header #logo img {
11+
max-width: 100%;
12+
margin-bottom 15px;
13+
}
14+
}

CodeSniffer/Standards/Squiz/Tests/CSS/MissingColonUnitTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public function getErrorList()
4343
2 => 1,
4444
4 => 1,
4545
6 => 1,
46+
12 => 1,
4647
);
4748

4849
}//end getErrorList()

package.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ http://pear.php.net/dtd/package-2.0.xsd">
4747
-- Thanks to Klaus Purer for the patch
4848
- Fixed bug #19264 : Squiz.PHP.NonExecutableCode does not handle RETURN in CASE without BREAK
4949
- Fixed bug #19270 : DuplicateClassName does not handle namespaces correctly
50+
- Fixed bug #19283 : CSS @media rules cause false positives
51+
-- Thanks to Klaus Purer for the patch
5052
</notes>
5153
<contents>
5254
<dir name="/">

0 commit comments

Comments
 (0)