Skip to content

Commit

Permalink
linter: warn on BOM and deprecated stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Oct 27, 2021
1 parent a209777 commit aca81a7
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions bin/latte-lint
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,33 @@ function createLatte(): Latte\Engine

function lintLatte(Latte\Engine $latte, string $file): bool
{
set_error_handler(function (int $severity, string $message) use ($file) {
if ($severity === E_USER_DEPRECATED) {
fwrite(STDERR, "[DEPRECATED] $file $message\n");
return null;
}
return false;
});

$s = file_get_contents($file);
if (substr($s, 0, 3) === "\xEF\xBB\xBF") {
fwrite(STDERR, "[WARNING] $file contains BOM\n");
$contents = substr($s, 3);
}

try {
$code = $latte->compile(file_get_contents($file));
$code = $latte->compile($s);

} catch (Latte\CompileException $e) {
fwrite(STDERR, "[ERROR] $file {$e->getMessage()}\n");
fwrite(STDERR, "[ERROR] $file {$e->getMessage()}\n");
return false;

} finally {
restore_error_handler();
}

if ($error = lintPHP($code)) {
fwrite(STDERR, "[ERROR] $file $error\n");
fwrite(STDERR, "[ERROR] $file $error\n");
return false;
}

Expand Down

0 comments on commit aca81a7

Please sign in to comment.