Skip to content

[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

Merged
merged 1 commit into from
Jun 29, 2017

Conversation

WybrenKoelmans
Copy link
Contributor

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 \")."
    }
]

@fabpot
Copy link
Member

fabpot commented Jun 25, 2017

Sounds good to me.

Copy link
Member

@javiereguiluz javiereguiluz left a 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());
Copy link
Member

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?

Copy link
Contributor Author

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().

Copy link
Member

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

Copy link
Contributor Author

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?

@WybrenKoelmans WybrenKoelmans changed the title [YAML][LINT] Add line numbers to JSON output. [Yaml][LintAdd line numbers to JSON output. Jun 27, 2017
@WybrenKoelmans WybrenKoelmans changed the title [Yaml][LintAdd line numbers to JSON output. [Yaml][Lint] Add line numbers to JSON output. Jun 27, 2017
@@ -75,6 +75,14 @@ public function parse($value, $flags = 0)
return $data;
}

/**
* @return int
Copy link
Member

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.

Copy link
Contributor Author

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.

@fabpot
Copy link
Member

fabpot commented Jun 29, 2017

Thank you @WybrenKoelmans.

@fabpot fabpot merged commit c6d19b1 into symfony:master Jun 29, 2017
fabpot added a commit that referenced this pull request Jun 29, 2017
…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.
xabbuh pushed a commit to xabbuh/symfony that referenced this pull request Jun 30, 2017
…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.
fabpot added a commit that referenced this pull request Jun 30, 2017
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)
fabpot added a commit that referenced this pull request Jun 30, 2017
* 3.4:
  [Yaml] fix the displayed line number
  feature #23294 [Yaml][Lint] Add line numbers to JSON output. (WybrenKoelmans)
@fabpot fabpot mentioned this pull request Oct 19, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants