Skip to content

Commit

Permalink
feature #22274 [Yaml] report deprecations when linting YAML files (xa…
Browse files Browse the repository at this point in the history
…bbuh)

This PR was merged into the 3.3-dev branch.

Discussion
----------

[Yaml] report deprecations when linting YAML files

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

In a project I frequently discovered usages of deprecated YAML formats. I first wanted to set up a build step that would lint all YAML files found in that project to be able to report it inside the CI. While doing so I noticed that the lint command was ignoring all deprecations after all. I suggest that catch all deprecations triggered by the YAML components and turn them into reported errors here. If we think that this could be seen as misbehaviour as the Symfony YAML parser is still able to handle these files properly, we could think about adding an additional option to the command that would turn on the deprecation handling.

Commits
-------

9b4206f report deprecations when linting YAML files
  • Loading branch information
fabpot committed Apr 5, 2017
2 parents d45d40d + 9b4206f commit 937045c
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Symfony/Component/Yaml/Command/LintCommand.php
Expand Up @@ -102,10 +102,20 @@ protected function execute(InputInterface $input, OutputInterface $output)

private function validate($content, $file = null)
{
$prevErrorHandler = set_error_handler(function ($level, $message, $file, $line) use (&$prevErrorHandler) {
if (E_USER_DEPRECATED === $level) {
throw new ParseException($message);
}

return $prevErrorHandler ? $prevErrorHandler($level, $message, $file, $line) : false;
});

try {
$this->getParser()->parse($content);
} catch (ParseException $e) {
return array('file' => $file, 'valid' => false, 'message' => $e->getMessage());
} finally {
restore_error_handler();
}

return array('file' => $file, 'valid' => true);
Expand Down

0 comments on commit 937045c

Please sign in to comment.