8000 [Yaml][Lint] Add line numbers to JSON output. · symfony/symfony@684f62e · GitHub
[go: up one dir, main page]

Skip to content

Commit 684f62e

Browse files
[Yaml][Lint] Add line numbers to JSON output.
- added line numbers for deprecations and for JSON output
1 parent a617d4b commit 684f62e

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/Symfony/Component/Yaml/Command/LintCommand.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ private function validate($content, $file = null)
105105
{
106106
$prevErrorHandler = set_error_handler(function ($level, $message, $file, $line) use (&$prevErrorHandler) {
107107
if (E_USER_DEPRECATED === $level) {
108-
throw new ParseException($message);
108+
throw new ParseException($message, $this->getParser()->getLastLineNumberBeforeDeprecation());
109109
}
110110

111111
return $prevErrorHandler ? $prevErrorHandler($level, $message, $file, $line) : false;
@@ -114,7 +114,7 @@ private function validate($content, $file = null)
114114
try {
115115
$this->getParser()->parse($content, Yaml::PARSE_CONSTANT);
116116
} catch (ParseException $e) {
117-
return array('file' => $file, 'valid' => false, 'message' => $e->getMessage());
117+
return array('file' => $file, 'line' => $e->getParsedLine(), 'valid' => false, 'message' => $e->getMessage());
118118
} finally {
119119
restore_error_handler();
120120
}

src/Symfony/Component/Yaml/Parser.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ public function parse($value, $flags = 0)
7575
return $data;
7676
}
7777

78+
/**
79+
* @return int
80+
*/
81+
public function getLastLineNumberBeforeDeprecation()
82+
{
83+
return $this->getRealCurrentLineNb();
84+
}
85+
7886
private function doParse($value, $flags)
7987
{
8088
$this->currentLineNb = -1;

0 commit comments

Comments
 (0)
0