Skip to content

Commit

Permalink
Skip shebang sequence if it is the first line
Browse files Browse the repository at this point in the history
  • Loading branch information
xaben authored and jrfnl committed Mar 27, 2024
1 parent 765fbb4 commit b90851f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
6 changes: 6 additions & 0 deletions bin/skip-linting.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@
$f = @fopen($file, 'r');
if ($f) {
$firstLine = fgets($f);

// ignore shebang line
if (strpos($firstLine, '#!') === 0) {
$firstLine = fgets($f);
}

@fclose($f);

if (preg_match('~<?php\\s*\\/\\/\s*lint\s*([^\d\s]+)\s*([^\s]+)\s*~i', $firstLine, $m)) {
Expand Down
10 changes: 10 additions & 0 deletions tests/ParallelLint.lint.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,16 @@ class ParallelLintLintTest extends Tester\TestCase
Assert::equal(0, count($result->getErrors()));
}

public function testSkipShebang()
{
$parallelLint = new ParallelLint($this->getPhpExecutable());
$result = $parallelLint->lint(array(__DIR__ . '/examples/example-07/example.php'));

Assert::equal(0, $result->getCheckedFilesCount());
Assert::equal(0, $result->getFilesWithSyntaxErrorCount());
Assert::equal(1, $result->getSkippedFilesCount());
}

public function testInvalidFile()
{
$parallelLint = new ParallelLint($this->getPhpExecutable());
Expand Down
5 changes: 5 additions & 0 deletions tests/examples/example-07/example.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/php
<?php // lint < 5.3

$myString = 'This is always skipped';
echo $myString;

0 comments on commit b90851f

Please sign in to comment.