Skip to content

Commit 138e931

Browse files
committed
Don't take in account the ignored (using codingStandardsIgnore) warnings and errors when using summary report
1 parent e62fb7b commit 138e931

File tree

1 file changed

+51
-22
lines changed

1 file changed

+51
-22
lines changed

CodeSniffer/File.php

Lines changed: 51 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@
111111
* @author Marc McIntyre <[email protected]>
112112
* @copyright 2006-2012 Squiz Pty Ltd (ABN 77 084 670 600)
113113
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
114-
* @version Release: @package_version@
114+
* @version Release: 1.4.2
115115
* @link http://pear.php.net/package/PHP_CodeSniffer
116116
*/
117117
class PHP_CodeSniffer_File
@@ -510,21 +510,34 @@ public function start($contents=null)
510510
// Remove errors and warnings for ignored lines.
511511
foreach ($this->_ignoredLines as $line => $ignore) {
512512
if (isset($this->_errors[$line]) === true) {
513-
foreach ($this->_errors[$line] as $col => $errors) {
514-
$this->_errorCount -= count($errors);
513+
if ($this->_recordErrors === false) {
514+
$this->_errorCount -= $this->_errors[$line];
515+
} else {
516+
foreach ($this->_errors[$line] as $col => $errors) {
517+
$this->_errorCount -= count($errors);
518+
}
515519
}
516520

517521
unset($this->_errors[$line]);
518522
}
519523

520524
if (isset($this->_warnings[$line]) === true) {
521-
foreach ($this->_warnings[$line] as $col => $warnings) {
522-
$this->_warningCount -= count($warnings);
525+
if ($this->_recordErrors === false) {
526+
$this->_errorCount -= $this->_warnings[$line];
527+
} else {
528+
foreach ($this->_warnings[$line] as $col => $warnings) {
529+
$this->_warningCount -= count($warnings);
530+
}
523531
}
524532

525533
unset($this->_warnings[$line]);
526534
}
527535
}
536+
537+
if ($this->_recordErrors === false) {
538+
$this->_errors = array();
539+
$this->_warnings = array();
540+
}
528541

529542
// If short open tags are off but the file being checked uses
530543
// short open tags, the whole content will be inline HTML
@@ -768,8 +781,20 @@ public function addError($error, $stackPtr, $code='', $data=array(), $severity=0
768781
}
769782
}
770783

784+
if ($stackPtr === null) {
785+
$lineNum = 1;
786+
$column = 1;
787+
} else {
788+
$lineNum = $this->_tokens[$stackPtr]['line'];
789+
$column = $this->_tokens[$stackPtr]['column'];
790+
}
791+
771792
$this->_errorCount++;
772793
if ($this->_recordErrors === false) {
794+
if (isset($this->_errors[$lineNum]) === false) {
795+
$this->_errors[$lineNum] = 0;
796+
}
797+
$this->_errors[$lineNum]++;
773798
return;
774799
}
775800

@@ -784,14 +809,6 @@ public function addError($error, $stackPtr, $code='', $data=array(), $severity=0
784809
$message = vsprintf($error, $data);
785810
}
786811

787-
if ($stackPtr === null) {
788-
$lineNum = 1;
789-
$column = 1;
790-
} else {
791-
$lineNum = $this->_tokens[$stackPtr]['line'];
792-
$column = $this->_tokens[$stackPtr]['column'];
793-
}
794-
795812
if (isset($this->_errors[$lineNum]) === false) {
796813
$this->_errors[$lineNum] = array();
797814
}
@@ -885,8 +902,20 @@ public function addWarning($warning, $stackPtr, $code='', $data=array(), $severi
885902
}
886903
}
887904

905+
if ($stackPtr === null) {
906+
$lineNum = 1;
907+
$column = 1;
908+
} else {
909+
$lineNum = $this->_tokens[$stackPtr]['line'];
910+
$column = $this->_tokens[$stackPtr]['column'];
911+
}
912+
888913
$this->_warningCount++;
889914
if ($this->_recordErrors === false) {
915+
if (isset($this->_warnings[$lineNum]) === false) {
916+
$this->_warnings[$lineNum] = 0;
917+
}
918+
$this->_warnings[$lineNum]++;
890919
return;
891920
}
892921

@@ -901,14 +930,6 @@ public function addWarning($warning, $stackPtr, $code='', $data=array(), $severi
901930
$message = vsprintf($warning, $data);
902931
}
903932

904-
if ($stackPtr === null) {
905-
$lineNum = 1;
906-
$column = 1;
907-
} else {
908-
$lineNum = $this->_tokens[$stackPtr]['line'];
909-
$column = $this->_tokens[$stackPtr]['column'];
910-
}
911-
912933
if (isset($this->_warnings[$lineNum]) === false) {
913934
$this->_warnings[$lineNum] = array();
914935
}
@@ -1086,7 +1107,7 @@ private static function _convertTabs(&$tokens, $tokenizer, $eolChar)
10861107

10871108
if (strpos($tokenContent, "\t") === false) {
10881109
// There are no tabs in this content.
1089-
$currColumn += strlen($tokenContent);
1110+
$currColumn += (strlen($tokenContent) - 1);
10901111
} else {
10911112
// We need to determine the length of each tab.
10921113
$tabs = preg_split(
@@ -1097,6 +1118,7 @@ private static function _convertTabs(&$tokens, $tokenizer, $eolChar)
10971118
);
10981119

10991120
$tabNum = 0;
1121+
$adjustedTab = false;
11001122
$tabsToSpaces = array();
11011123
$newContent = '';
11021124

@@ -1118,6 +1140,7 @@ private static function _convertTabs(&$tokens, $tokenizer, $eolChar)
11181140
// This is the first tab, and we are already at a
11191141
// tab stop, so this tab counts as a single space.
11201142
$currColumn++;
1143+
$adjustedTab = true;
11211144
} else {
11221145
$currColumn++;
11231146
while (($currColumn % PHP_CODESNIFFER_TAB_WIDTH) != 0) {
@@ -1132,13 +1155,19 @@ private static function _convertTabs(&$tokens, $tokenizer, $eolChar)
11321155
}//end if
11331156
}//end foreach
11341157

1158+
if ($tabNum === 1 && $adjustedTab === true) {
1159+
$currColumn--;
1160+
}
1161+
11351162
$tokens[$i]['content'] = $newContent;
11361163
}//end if
11371164

11381165
if (isset($tokens[($i + 1)]['line']) === true
11391166
&& $tokens[($i + 1)]['line'] !== $tokens[$i]['line']
11401167
) {
11411168
$currColumn = 1;
1169+
} else {
1170+
$currColumn++;
11421171
}
11431172
}//end for
11441173

0 commit comments

Comments
 (0)