Permalink
Browse files

A bunch of new rules to deal with nested class definitions. It boils …

…down to: 1 blank line required after open brace of a nesting definition and 1 blank line before the closing brace. Inside a nesting area, all other rules apply as normal.
  • Loading branch information...
1 parent 440d99d commit f09151959e8d0bdb93b50b8f104f1945a303213f @gsherwood gsherwood committed Feb 13, 2012
@@ -75,6 +75,18 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
}
}
+ // Ignore nested style definitions from here on. The spacing before the closing brace
+ // (a single blank line) will be enforced by the above check, which ensures there is a
+ // blank line after the last nested class.
+ $found = $phpcsFile->findPrevious(
+ T_CLOSE_CURLY_BRACKET,
+ ($stackPtr - 1),
+ $tokens[$stackPtr]['bracket_opener']
+ );
+ if ($found !== false) {
+ return;
+ }
+
$prev = $phpcsFile->findPrevious(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr - 1), null, true);
if ($prev !== false && $tokens[$prev]['line'] !== ($tokens[$stackPtr]['line'] - 1)) {
$num = ($tokens[$stackPtr]['line'] - $tokens[$prev]['line'] - 1);
@@ -61,9 +61,16 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
{
$tokens = $phpcsFile->getTokens();
+ // Do not check nested style definitions as, for example, in @media style rules.
+ $nested = $phpcsFile->findNext(T_OPEN_CURLY_BRACKET, ($stackPtr + 1), $tokens[$stackPtr]['bracket_closer']);
+ if ($nested !== false) {
+ return;
+ }
+
// Find the first blank line before this openning brace, unless we get
// to another style definition, comment or the start of the file.
$endTokens = array(
+ T_OPEN_CURLY_BRACKET,
T_CLOSE_CURLY_BRACKET,
T_COMMENT,
T_DOC_COMMENT,
@@ -80,11 +80,34 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
}//end if
$next = $phpcsFile->findNext(PHP_CodeSniffer_Tokens::$emptyTokens, ($stackPtr + 1), null, true);
- if ($next !== false && $tokens[$next]['line'] !== ($tokens[$stackPtr]['line'] + 1)) {
- $num = ($tokens[$next]['line'] - $tokens[$stackPtr]['line'] - 1);
- $error = 'Expected 0 blank lines after opening brace of class definition; %s found';
- $data = array($num);
- $phpcsFile->addError($error, $stackPtr, 'After', $data);
+ if ($next === false) {
+ return;
+ }
+
+ // Check for nested class definitions.
+ $nested = false;
+ $found = $phpcsFile->findNext(
+ T_OPEN_CURLY_BRACKET,
+ ($stackPtr + 1),
+ $tokens[$stackPtr]['bracket_closer']
+ );
+ if ($found !== false) {
+ $nested = true;
+ }
+
+ $foundLines = ($tokens[$next]['line'] - $tokens[$stackPtr]['line'] - 1);
+ if ($nested === true) {
+ if ($foundLines !== 1) {
+ $error = 'Expected 1 blank line after opening brace of nesting class definition; %s found';
+ $data = array($foundLines);
+ $phpcsFile->addError($error, $stackPtr, 'AfterNesting', $data);
+ }
+ } else {
+ if ($foundLines !== 0) {
+ $error = 'Expected 0 blank lines after opening brace of class definition; %s found';
+ $data = array($foundLines);
+ $phpcsFile->addError($error, $stackPtr, 'After', $data);
+ }
}
}//end process()
@@ -64,6 +64,7 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
$numTokens = (count($tokens) - 2);
$currentLine = 0;
$indentLevel = 0;
+ $nested = false;
for ($i = 1; $i < $numTokens; $i++) {
if ($tokens[$i]['code'] === T_COMMENT) {
// Dont check the indent of comments.
@@ -72,6 +73,14 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
if ($tokens[$i]['code'] === T_OPEN_CURLY_BRACKET) {
$indentLevel++;
+
+ // Check for nested style definitions as, for example, in @media style rules.
+ $found = $phpcsFile->findNext(T_OPEN_CURLY_BRACKET, ($i + 1), $tokens[$i]['bracket_closer']);
+ if ($found === false) {
+ $nested = false;
+ } else {
+ $nested = true;
+ }
} else if ($tokens[($i + 1)]['code'] === T_CLOSE_CURLY_BRACKET) {
$indentLevel--;
}
@@ -90,8 +99,10 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
$expectedIndent = ($indentLevel * 4);
if ($expectedIndent > 0 && strpos($tokens[$i]['content'], $phpcsFile->eolChar) !== false) {
- $error = 'Blank lines are not allowed in class definitions';
- $phpcsFile->addError($error, $i, 'BlankLine');
+ if ($nested === false) {
+ $error = 'Blank lines are not allowed in class definitions';
+ $phpcsFile->addError($error, $i, 'BlankLine');
+ }
} else if ($foundIndent !== $expectedIndent) {
$error = 'Line indented incorrectly; expected %s spaces, found %s';
$data = array(
@@ -28,3 +28,18 @@
.AssetLineageWidgetType-item.selected {
}
+
+@media screen and (max-device-width: 769px) {
+
+ header #logo img {
+ max-width: 100%;
+ }
+
+}
+
+@media screen and (max-device-width: 769px) {
+
+ header #logo img {
+ max-width: 100%;
+ }
+}
@@ -44,6 +44,7 @@ public function getErrorList()
2 => 1,
11 => 1,
19 => 1,
+ 44 => 1,
);
}//end getErrorList()
@@ -46,3 +46,12 @@ td.TableWidgetType-header.TableWidgetType-header-userName {
padding-left: 12px;
width: 150px;
}
+
+@media screen and (max-device-width: 769px) {
+
+ header #logo img {
+ max-width: 100%;
+ padding: 20px;
+ margin: 40px;
+ }
+}
@@ -14,3 +14,18 @@
float: left;
}
+
+@media screen and (max-device-width: 769px) {
+
+ header #logo img {
+ max-width: 100%;
+ }
+
+}
+
+@media screen and (max-device-width: 769px) {
+ header #logo img {
+ max-width: 100%;
+ }
+
+}
@@ -45,6 +45,7 @@ public function getErrorList()
7 => 1,
10 => 1,
13 => 1,
+ 26 => 1,
);
}//end getErrorList()
@@ -23,6 +23,7 @@ td {
*/
@media screen and (max-device-width: 769px) {
+
header #logo img {
max-width: 100%;
padding: 20px;
@@ -46,8 +46,8 @@ public function getErrorList()
6 => 1,
7 => 1,
12 => 1,
- 27 => 1,
- 29 => 1,
+ 28 => 1,
+ 30 => 1,
);
}//end getErrorList()

0 comments on commit f091519

Please sign in to comment.