Skip to content

Commit fc21b65

Browse files
committed
Merge branch 'master' into report-memory-improvements
2 parents ec2a3df + 579b05a commit fc21b65

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+380
-54
lines changed

CodeSniffer.conf.dist

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
$phpCodeSnifferConfig = array (
3+
'default_standard' => 'PSR2',
4+
'report_format' => 'summary',
5+
'show_warnings' => '0',
6+
'show_progress' => '1',
7+
'report_wdith' => '120',
8+
)
9+
?>

CodeSniffer/File.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1497,7 +1497,7 @@ private static function _recurseScopeMap(
14971497
echo "=> Found semicolon before scope opener for $stackPtr (T_IF), bailing".PHP_EOL;
14981498
}
14991499

1500-
return $stackPtr;
1500+
return $i;
15011501
}
15021502

15031503
// Is this an opening condition ?
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
<?php
2+
/**
3+
* Generic_Sniffs_Debug_CSSLintSniff.
4+
*
5+
* PHP version 5
6+
*
7+
* @category PHP
8+
* @package PHP_CodeSniffer
9+
* @author Roman Levishchenko <[email protected]>
10+
* @copyright 2013 Roman Levishchenko
11+
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
12+
* @link http://pear.php.net/package/PHP_CodeSniffer
13+
*/
14+
15+
/**
16+
* Generic_Sniffs_Debug_CSSLintSniff.
17+
*
18+
* Runs csslint on the file.
19+
*
20+
* @category PHP
21+
* @package PHP_CodeSniffer
22+
* @author Roman Levishchenko <[email protected]>
23+
* @copyright 2013 Roman Levishchenko
24+
* @license https://github.com/squizlabs/PHP_CodeSniffer/blob/master/licence.txt BSD Licence
25+
* @version Release: @package_version@
26+
* @link http://pear.php.net/package/PHP_CodeSniffer
27+
*/
28+
class Generic_Sniffs_Debug_CSSLintSniff implements PHP_CodeSniffer_Sniff
29+
{
30+
31+
/**
32+
* A list of tokenizers this sniff supports.
33+
*
34+
* @var array
35+
*/
36+
public $supportedTokenizers = array('CSS');
37+
38+
39+
/**
40+
* Returns the token types that this sniff is interested in.
41+
*
42+
* @return array(int)
43+
*/
44+
public function register()
45+
{
46+
return array(T_OPEN_TAG);
47+
48+
}//end register()
49+
50+
51+
/**
52+
* Processes the tokens that this sniff is interested in.
53+
*
54+
* @param PHP_CodeSniffer_File $phpcsFile The file where the token was found.
55+
* @param int $stackPtr The position in the stack where
56+
* the token was found.
57+
*
58+
* @return void
59+
*/
60+
public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
61+
{
62+
$fileName = $phpcsFile->getFilename();
63+
64+
$csslintPath = PHP_CodeSniffer::getConfigData('csslint_path');
65+
if ($csslintPath === null) {
66+
return;
67+
}
68+
69+
$cmd = $csslintPath.' '.escapeshellarg($fileName);
70+
exec($cmd, $output, $retval);
71+
72+
if (is_array($output) === false) {
73+
return;
74+
}
75+
76+
$tokens = $phpcsFile->getTokens();
77+
$count = count($output);
78+
79+
for ($i = 0; $i < $count; $i++) {
80+
$matches = array();
81+
$numMatches = preg_match(
82+
'/(error|warning) at line (\d+)/',
83+
$output[$i],
84+
$matches
85+
);
86+
87+
if ($numMatches === 0) {
88+
continue;
89+
}
90+
91+
$line = (int) $matches[2];
92+
$message = 'csslint says: '.$output[($i + 1)];
93+
// 1-st line is message with error line and error code.
94+
// 2-nd error message.
95+
// 3-d wrong line in file.
96+
// 4-th empty line.
97+
$i += 4;
98+
99+
$lineToken = null;
100+
foreach ($tokens as $ptr => $info) {
101+
if ($info['line'] === $line) {
102+
$lineToken = $ptr;
103+
break;
104+
}
105+
}
106+
107+
if ($lineToken !== null) {
108+
$phpcsFile->addWarning($message, $lineToken, 'ExternalTool');
109+
}
110+
}//end for
111+
112+
}//end process()
113+
114+
115+
}//end class
116+
117+
?>

CodeSniffer/Standards/Generic/Sniffs/Files/EndFileNewlineSniff.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,18 @@
2828
class Generic_Sniffs_Files_EndFileNewlineSniff implements PHP_CodeSniffer_Sniff
2929
{
3030

31+
/**
32+
* A list of tokenizers this sniff supports.
33+
*
34+
* @var array
35+
*/
36+
public $supportedTokenizers = array(
37+
'PHP',
38+
'JS',
39+
'CSS',
40+
);
41+
42+
3143
/**
3244
* Returns an array of tokens this test wants to listen for.
3345
*
@@ -62,10 +74,16 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
6274
$tokens = $phpcsFile->getTokens();
6375
$stackPtr = ($phpcsFile->numTokens - 1);
6476

77+
if ($phpcsFile->tokenizerType === 'JS') {
78+
$stackPtr--;
79+
} else if ($phpcsFile->tokenizerType === 'CSS') {
80+
$stackPtr -= 2;
81+
}
82+
6583
$eolCharLen = strlen($phpcsFile->eolChar);
6684
$lastChars = substr($tokens[$stackPtr]['content'], ($eolCharLen * -1));
6785
if ($lastChars !== $phpcsFile->eolChar) {
68-
$error = 'All PHP files must end with a newline character';
86+
$error = 'File must end with a newline character';
6987
$phpcsFile->addError($error, $stackPtr, 'NotFound');
7088
}
7189

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
#login-container {}
3+
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
alert('hi);
3+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
#login-container {}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
alert('hi);
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
#login-container {}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
alert('hi);

0 commit comments

Comments
 (0)