-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Yaml][Lint] Add line numbers to JSON output. #23294
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Sounds good to me. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 I like this! thanks @WybrenKoelmans.
@@ -114,7 +114,7 @@ private function validate($content, $file = null) | |||
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()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
getParsedLine()
can return -1
. Should we add special handling for that case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes I've noticed that while working with this. I want to research it a little more because the message will have a line number sometimes, so I will try to find out why it is not returning for getParsedLine()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO, displaying the line number here all the time is fine. For cases having -1, the right handling would be to give them the right line number if we can
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've added getLastLineNumberBeforeDeprecation
to get the last line read before the deprecation was triggered. Do you think this is the way to go? The only other way I see to get line numbers from these trigger_error
is by adding them into the $error_msg
and parse them out.. But this seems clearer even though not perfect (it's a very specific method). Maybe you think we should make getRealCurrentLineNb
public?
@@ -75,6 +75,14 @@ public function parse($value, $flags = 0) | |||
return $data; | |||
} | |||
|
|||
/** | |||
* @return int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would tag this with @internal
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 fixed. I've also added the line number to the Twig Lint output.
Thank you @WybrenKoelmans. |
…oelmans) 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.
…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.
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)
* 3.4: [Yaml] fix the displayed line number feature #23294 [Yaml][Lint] Add line numbers to JSON output. (WybrenKoelmans)
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:
Before: