Skip to content

Commit 3195a74

Browse files
xabengrogy
authored andcommitted
Skip shebang sequence if it is the first line
1 parent b5c0080 commit 3195a74

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

bin/skip-linting.php

+6
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@
99
$f = @fopen($file, 'r');
1010
if ($f) {
1111
$firstLine = fgets($f);
12+
13+
// ignore shebang line
14+
if (strpos($firstLine, '#!') === 0) {
15+
$firstLine = fgets($f);
16+
}
17+
1218
@fclose($f);
1319

1420
if (preg_match('~<?php\\s*\\/\\/\s*lint\s*([^\d\s]+)\s*([^\s]+)\s*~i', $firstLine, $m)) {

tests/Unit/ParallelLintLintTest.php

+10
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,16 @@ public function testValidFile()
7878
$this->assertSame(0, count($result->getErrors()));
7979
}
8080

81+
public function testSkipShebang()
82+
{
83+
$parallelLint = new ParallelLint($this->getPhpExecutable());
84+
$result = $parallelLint->lint(array(PL_TESTROOT . '/fixtures/fixture-07/example.php'));
85+
86+
$this->assertSame(0, $result->getCheckedFilesCount());
87+
$this->assertSame(0, $result->getFilesWithSyntaxErrorCount());
88+
$this->assertSame(1, $result->getSkippedFilesCount());
89+
}
90+
8191
public function testInvalidFile()
8292
{
8393
$parallelLint = new ParallelLint($this->getPhpExecutable());

tests/fixtures/fixture-07/example.php

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#!/usr/bin/php
2+
<?php // lint < 5.3
3+
4+
$myString = 'This is always skipped';
5+
echo $myString;

0 commit comments

Comments
 (0)