Skip to content

Commit 222c1d0

Browse files
xabengrogy
authored andcommitted
Skip shebang sequence if it is the first line
1 parent 7212796 commit 222c1d0

File tree

3 files changed

+21
-0
lines changed

3 files changed

+21
-0
lines changed

bin/skip-linting.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@
88
$f = @fopen($file, 'r');
99
if ($f) {
1010
$firstLine = fgets($f);
11+
12+
// ignore shebang line
13+
if (strpos($firstLine, '#!') === 0) {
14+
$firstLine = fgets($f);
15+
}
16+
1117
@fclose($f);
1218

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

tests/ParallelLint.lint.phpt

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,16 @@ class ParallelLintLintTest extends Tester\TestCase
8383
Assert::equal(0, count($result->getErrors()));
8484
}
8585

86+
public function testSkipShebang()
87+
{
88+
$parallelLint = new ParallelLint($this->getPhpExecutable());
89+
$result = $parallelLint->lint(array(__DIR__ . '/examples/example-07/example.php'));
90+
91+
Assert::equal(0, $result->getCheckedFilesCount());
92+
Assert::equal(0, $result->getFilesWithSyntaxErrorCount());
93+
Assert::equal(1, $result->getSkippedFilesCount());
94+
}
95+
8696
public function testInvalidFile()
8797
{
8898
$parallelLint = new ParallelLint($this->getPhpExecutable());

tests/examples/example-07/example.php

Lines changed: 5 additions & 0 deletions
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)