Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0932183

Browse files
committed
feature #23294 [Yaml][Lint] Add line numbers to JSON output. (WybrenKoelmans)
This PR was merged into the 4.0-dev branch. Discussion ---------- [Yaml][Lint] Add line numbers to JSON output. | Q | A | ------------- | --- | Branch? | 2.7? | Bug fix? | no? | New feature? | yes? | BC breaks? | no? | Deprecations? | no? | Tests pass? | Hopefully | Fixed tickets | n/a | License | MIT | Doc PR | TODO? - [ ] Run tests? - [ ] Check if it will break BC? - [ ] Update changelog? The JSON output is not very useful for me without the line number. I don't want to have to parse it from the message. Is this the right way of doing it? With PR: ``` [ { "file": "", "line": 13, "valid": false, "message": "Unable to parse at line 13 (near \"sdf \")." } ] ``` Before: ``` [ { "file": "", "valid": false, "message": "Unable to parse at line 13 (near \"sdf \")." } ] ``` Commits ------- c6d19b1 [Yaml][Twig][Lint] Added line numbers to JSON output.
2 parents 8483564 + c6d19b1 commit 0932183

File tree

3 files changed

+13
-3
lines changed

3 files changed

+13
-3
lines changed

src/Symfony/Bridge/Twig/Command/LintCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ private function validate(Environment $twig, $template, $file)
145145
} catch (Error $e) {
146146
$twig->setLoader($realLoader);
147147

148-
return array('template' => $template, 'file' => $file, 'valid' => false, 'exception' => $e);
148+
return array('template' => $template, 'file' => $file, 'line' => $e->getTemplateLine(), 'valid' => false, 'exception' => $e);
149149
}
150150

151151
return array('template' => $template, 'file' => $file, 'valid' => true);

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: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,16 @@ public function parse($value, $flags = 0)
7575
return $data;
7676
}
7777

78+
/**
79+
* @internal
80+
*
81+
* @return int
82+
*/
83+
public function getLastLineNumberBeforeDeprecation()
84+
{
85+
return $this->getRealCurrentLineNb();
86+
}
87+
7888
private function doParse($value, $flags)
7989
{
8090
$this->currentLineNb = -1;

0 commit comments

Comments
 (0)