[Yaml][Twig][Lint] Added line numbers to JSON output.

This commit is contained in:
Wybren Koelmans 2017-06-29 22:55:41 +02:00
parent 8483564b71
commit c6d19b1976
3 changed files with 13 additions and 3 deletions

View File

@ -145,7 +145,7 @@ EOF
} catch (Error $e) {
$twig->setLoader($realLoader);
return array('template' => $template, 'file' => $file, 'valid' => false, 'exception' => $e);
return array('template' => $template, 'file' => $file, 'line' => $e->getTemplateLine(), 'valid' => false, 'exception' => $e);
}
return array('template' => $template, 'file' => $file, 'valid' => true);

View File

@ -105,7 +105,7 @@ EOF
{
$prevErrorHandler = set_error_handler(function ($level, $message, $file, $line) use (&$prevErrorHandler) {
if (E_USER_DEPRECATED === $level) {
throw new ParseException($message);
throw new ParseException($message, $this->getParser()->getLastLineNumberBeforeDeprecation());
}
return $prevErrorHandler ? $prevErrorHandler($level, $message, $file, $line) : false;
@ -114,7 +114,7 @@ EOF
try {
$this->getParser()->parse($content, Yaml::PARSE_CONSTANT);
} catch (ParseException $e) {
return array('file' => $file, 'valid' => false, 'message' => $e->getMessage());
return array('file' => $file, 'line' => $e->getParsedLine(), 'valid' => false, 'message' => $e->getMessage());
} finally {
restore_error_handler();
}

View File

@ -75,6 +75,16 @@ class Parser
return $data;
}
/**
* @internal
*
* @return int
*/
public function getLastLineNumberBeforeDeprecation()
{
return $this->getRealCurrentLineNb();
}
private function doParse($value, $flags)
{
$this->currentLineNb = -1;