Skip to content

Commit e75544f

Browse files
committed
Added option --ignore-fails to ignore failed checks
1 parent 07940ea commit e75544f

File tree

7 files changed

+98
-40
lines changed

7 files changed

+98
-40
lines changed

parallel-lint.php

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,21 @@ function showOptions()
1313
{
1414
?>
1515
Options:
16-
-p <php> Specify PHP-CGI executable to run (default: 'php').
17-
-s, --short Set short_open_tag to On (default: Off).
18-
-a, -asp Set asp_tags to On (default: Off).
19-
-e <ext> Check only files with selected extensions separated by comma.
20-
(default: php,php3,php4,php5,phtml)
21-
--exclude Exclude directory. If you want exclude multiple directory, use
22-
multiple exclude parameters.
23-
-j <num> Run <num> jobs in parallel (default: 10).
24-
--no-colors Disable colors in console output.
25-
--json Output results as JSON string (require PHP 5.4).
26-
--blame Try to show git blame for row with error.
27-
--git <git> Path to Git executable to show blame message (default: 'git').
28-
--stdin Load files and folder to test from standard input.
29-
-h, --help Print this help.
16+
-p <php> Specify PHP-CGI executable to run (default: 'php').
17+
-s, --short Set short_open_tag to On (default: Off).
18+
-a, -asp Set asp_tags to On (default: Off).
19+
-e <ext> Check only files with selected extensions separated by comma.
20+
(default: php,php3,php4,php5,phtml)
21+
--exclude Exclude directory. If you want exclude multiple directory, use
22+
multiple exclude parameters.
23+
-j <num> Run <num> jobs in parallel (default: 10).
24+
--no-colors Disable colors in console output.
25+
--json Output results as JSON string (require PHP 5.4).
26+
--blame Try to show git blame for row with error.
27+
--git <git> Path to Git executable to show blame message (default: 'git').
28+
--stdin Load files and folder to test from standard input.
29+
--ignore-fails Ignore failed tests.
30+
-h, --help Print this help.
3031
<?php
3132
}
3233

@@ -85,7 +86,12 @@ function showUsage()
8586

8687
$manager = new PhpParallelLint\Manager;
8788
$result = $manager->run($settings);
88-
die($result->hasError() ? WITH_ERRORS : SUCCESS);
89+
90+
if ($settings->ignoreFails) {
91+
die($result->hasSyntaxError() ? WITH_ERRORS : SUCCESS);
92+
} else {
93+
die($result->hasError() ? WITH_ERRORS : SUCCESS);
94+
}
8995

9096
} catch (PhpParallelLint\InvalidArgumentException $e) {
9197
echo "Invalid option {$e->getArgument()}" . PHP_EOL . PHP_EOL;

src/Error.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class Error implements \JsonSerializable
4545
public function __construct($filePath, $message)
4646
{
4747
$this->filePath = $filePath;
48-
$this->message = $message;
48+
$this->message = rtrim($message);
4949
}
5050

5151
/**

src/Manager.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public function run(Settings $settings = null)
8383
$this->gitBlame($result, $settings);
8484
}
8585

86-
$output->writeResult($result, new ErrorFormatter($settings->colors, $translateTokens));
86+
$output->writeResult($result, new ErrorFormatter($settings->colors, $translateTokens), $settings->ignoreFails);
8787

8888
return $result;
8989
}

src/Output.php

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ public function setTotalFileCount($count);
4646

4747
public function writeHeader($phpVersion, $parallelJobs, $hhvmVersion = null);
4848

49-
public function writeResult(Result $result, ErrorFormatter $errorFormatter);
49+
public function writeResult(Result $result, ErrorFormatter $errorFormatter, $ignoreFails);
5050
}
5151

5252
class JsonOutput implements Output
@@ -103,7 +103,7 @@ public function writeHeader($phpVersion, $parallelJobs, $hhvmVersion = null)
103103
$this->hhvmVersion = $hhvmVersion;
104104
}
105105

106-
public function writeResult(Result $result, ErrorFormatter $errorFormatter)
106+
public function writeResult(Result $result, ErrorFormatter $errorFormatter, $ignoreFails)
107107
{
108108
echo json_encode(array(
109109
'phpVersion' => $this->phpVersion,
@@ -223,8 +223,9 @@ public function writeHeader($phpVersion, $parallelJobs, $hhvmVersion = null)
223223
/**
224224
* @param Result $result
225225
* @param ErrorFormatter $errorFormatter
226+
* @param bool $ignoreFails
226227
*/
227-
public function writeResult(Result $result, ErrorFormatter $errorFormatter)
228+
public function writeResult(Result $result, ErrorFormatter $errorFormatter, $ignoreFails)
228229
{
229230
if ($this->checkedFiles % $this->filesPerLine !== 0) {
230231
$rest = $this->filesPerLine - ($this->checkedFiles % $this->filesPerLine);
@@ -236,22 +237,33 @@ public function writeResult(Result $result, ErrorFormatter $errorFormatter)
236237

237238
$testTime = round($result->getTestTime(), 1);
238239
$message = "Checked {$result->getCheckedFilesCount()} files in $testTime ";
239-
$message .= $testTime == 1 ? 'second, ' : 'seconds, ';
240+
$message .= $testTime == 1 ? 'second' : 'seconds';
240241

241242
if ($result->getSkippedFilesCount() > 0) {
242243
$message .= "skipped {$result->getSkippedFilesCount()} ";
243244
$message .= ($result->getSkippedFilesCount() === 1 ? 'file' : 'files');
244-
$message .= ", ";
245245
}
246246

247+
$this->writeLine($message);
248+
247249
if (!$result->hasSyntaxError()) {
248-
$message .= "no syntax error found";
250+
$message = "No syntax error found";
249251
} else {
250-
$message .= "syntax error found in {$result->getFilesWithSyntaxErrorCount()} ";
252+
$message = "Syntax error found in {$result->getFilesWithSyntaxErrorCount()} ";
251253
$message .= ($result->getFilesWithSyntaxErrorCount() === 1 ? 'file' : 'files');
252254
}
253255

254-
$this->writeLine($message, $result->hasSyntaxError() ? self::TYPE_ERROR : self::TYPE_OK);
256+
if ($result->hasFilesWithFail()) {
257+
$message .= ", failed to check {$result->getFilesWithFailCount()} ";
258+
$message .= ($result->getFilesWithFailCount() === 1 ? 'file' : 'files');
259+
260+
if ($ignoreFails) {
261+
$message .= ' (ignored)';
262+
}
263+
}
264+
265+
$hasError = $ignoreFails ? $result->hasSyntaxError() : $result->hasError();
266+
$this->writeLine($message, $hasError ? self::TYPE_ERROR : self::TYPE_OK);
255267

256268
if ($result->hasError()) {
257269
$this->writeNewLine();

src/ParallelLint.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function lint(array $files)
8080
* @var LintProcess[] $waiting
8181
*/
8282
$errors = $running = $waiting = array();
83-
$skippedFiles = $checkedFiles = $filesWithSyntaxError = array();
83+
$skippedFiles = $checkedFiles = array();
8484

8585
while ($files || $running) {
8686
for ($i = count($running); $files && $i < $this->parallelJobs; $i++) {
@@ -121,11 +121,10 @@ public function lint(array $files)
121121
} elseif ($process->hasSyntaxError()) {
122122
$checkedFiles[] = $file;
123123
$errors[] = new SyntaxError($file, $process->getSyntaxError());
124-
$filesWithSyntaxError[] = $file;
125124
$processCallback(self::STATUS_ERROR, $file);
126125

127126
} else {
128-
$errors[] = new Error($file, $process->getErrorOutput());
127+
$errors[] = new Error($file, $process->getOutput());
129128
$processCallback(self::STATUS_FAIL, $file);
130129
}
131130
}
@@ -151,19 +150,18 @@ public function lint(array $files)
151150
} elseif ($process->hasSyntaxError()) {
152151
$checkedFiles[] = $file;
153152
$errors[] = new SyntaxError($file, $process->getSyntaxError());
154-
$filesWithSyntaxError[] = $file;
155153
$processCallback(self::STATUS_ERROR, $file);
156154

157155
} else {
158-
$errors[] = new Error($file, $process->getErrorOutput());
156+
$errors[] = new Error($file, $process->getOutput());
159157
$processCallback(self::STATUS_FAIL, $file);
160158
}
161159
}
162160
}
163161

164162
$testTime = microtime(true) - $startTime;
165163

166-
return new Result($errors, $checkedFiles, $filesWithSyntaxError, $skippedFiles, $testTime);
164+
return new Result($errors, $checkedFiles, $skippedFiles, $testTime);
167165
}
168166

169167
/**

src/Result.php

Lines changed: 41 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,6 @@ class Result implements \JsonSerializable
3838
/** @var array */
3939
private $checkedFiles;
4040

41-
/** @var array */
42-
private $filesWithSyntaxError;
43-
4441
/** @var array */
4542
private $skippedFiles;
4643

@@ -50,15 +47,13 @@ class Result implements \JsonSerializable
5047
/**
5148
* @param Error[] $errors
5249
* @param array $checkedFiles
53-
* @param array $filesWithSyntaxError
5450
* @param array $skippedFiles
5551
* @param float $testTime
5652
*/
57-
public function __construct(array $errors, array $checkedFiles, array $filesWithSyntaxError, array $skippedFiles, $testTime)
53+
public function __construct(array $errors, array $checkedFiles, array $skippedFiles, $testTime)
5854
{
5955
$this->errors = $errors;
6056
$this->checkedFiles = $checkedFiles;
61-
$this->filesWithSyntaxError = $filesWithSyntaxError;
6257
$this->skippedFiles = $skippedFiles;
6358
$this->testTime = $testTime;
6459
}
@@ -79,6 +74,37 @@ public function hasError()
7974
return !empty($this->errors);
8075
}
8176

77+
/**
78+
* @return array
79+
*/
80+
public function getFilesWithFail()
81+
{
82+
$filesWithFail = array();
83+
foreach ($this->errors as $error) {
84+
if (!$error instanceof SyntaxError) {
85+
$filesWithFail[] = $error->getFilePath();
86+
}
87+
}
88+
89+
return $filesWithFail;
90+
}
91+
92+
/**
93+
* @return int
94+
*/
95+
public function getFilesWithFailCount()
96+
{
97+
return count($this->getFilesWithFail());
98+
}
99+
100+
/**
101+
* @return bool
102+
*/
103+
public function hasFilesWithFail()
104+
{
105+
return $this->getFilesWithFailCount() !== 0;
106+
}
107+
82108
/**
83109
* @return array
84110
*/
@@ -116,15 +142,22 @@ public function getSkippedFilesCount()
116142
*/
117143
public function getFilesWithSyntaxError()
118144
{
119-
return $this->filesWithSyntaxError;
145+
$filesWithSyntaxError = array();
146+
foreach ($this->errors as $error) {
147+
if ($error instanceof SyntaxError) {
148+
$filesWithSyntaxError[] = $error->getFilePath();
149+
}
150+
}
151+
152+
return $filesWithSyntaxError;
120153
}
121154

122155
/**
123156
* @return int
124157
*/
125158
public function getFilesWithSyntaxErrorCount()
126159
{
127-
return count($this->filesWithSyntaxError);
160+
return count($this->getFilesWithSyntaxError());
128161
}
129162

130163
/**

src/Settings.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,11 +99,16 @@ class Settings
9999
public $blame = false;
100100

101101
/**
102-
* Path to git executable
102+
* Path to git executable for blame
103103
* @var string
104104
*/
105105
public $gitExecutable = 'git';
106106

107+
/**
108+
* @var bool
109+
*/
110+
public $ignoreFails = false;
111+
107112
/**
108113
* @param array $paths
109114
*/
@@ -173,6 +178,10 @@ public static function parseArguments(array $arguments)
173178
$settings->blame = true;
174179
break;
175180

181+
case '--ignore-fails':
182+
$settings->ignoreFails = true;
183+
break;
184+
176185
default:
177186
throw new InvalidArgumentException($argument);
178187
}

0 commit comments

Comments
 (0)