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 grogy committed Mar 27, 2024
1 parent b5c0080 commit 3195a74
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 @@ -9,6 +9,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/Unit/ParallelLintLintTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,16 @@ public function testValidFile()
$this->assertSame(0, count($result->getErrors()));
}

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

$this->assertSame(0, $result->getCheckedFilesCount());
$this->assertSame(0, $result->getFilesWithSyntaxErrorCount());
$this->assertSame(1, $result->getSkippedFilesCount());
}

public function testInvalidFile()
{
$parallelLint = new ParallelLint($this->getPhpExecutable());
Expand Down
5 changes: 5 additions & 0 deletions tests/fixtures/fixture-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 3195a74

Please sign in to comment.