Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7787343

Browse filesBrowse files
committed
feature #23332 [Yaml] fix the displayed line number (fabpot, xabbuh)
This PR was merged into the 3.4 branch. Discussion ---------- [Yaml] fix the displayed line number | Q | A | ------------- | --- | Branch? | 3.4 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #23294 | License | MIT | Doc PR | First, this PR backports #23294 to the `3.4` branch. Secondly, `getRealCurrentLineNb()` returns line numbers index by 0 (as they serve as array indexes internally). I removed the `getLastLineNumberBeforeDeprecation()` method added in #23294 as we can just expose the already existing `getRealCurrentLineNb()` method. Commits ------- a2ae6bf [Yaml] fix the displayed line number 1baac5a feature #23294 [Yaml][Lint] Add line numbers to JSON output. (WybrenKoelmans)
2 parents e891d55 + a2ae6bf commit 7787343
Copy full SHA for 7787343

File tree

3 files changed

+6
-4
lines changed
Filter options

3 files changed

+6
-4
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Bridge/Twig/Command/LintCommand.php
+1-1Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Yaml/Command/LintCommand.php
+2-2Lines 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()->getRealCurrentLineNb() + 1);
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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Yaml/Parser.php
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,9 +453,11 @@ private function parseBlock($offset, $yaml, $flags)
453453
/**
454454
* Returns the current line number (takes the offset into account).
455455
*
456+
* @internal
457+
*
456458
* @return int The current line number
457459
*/
458-
private function getRealCurrentLineNb()
460+
public function getRealCurrentLineNb()
459461
{
460462
$realCurrentLineNumber = $this->currentLineNb + $this->offset;
461463

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.