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

Skip to content

Commit 937045c

Browse files
committed
feature #22274 [Yaml] report deprecations when linting YAML files (xabbuh)
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
2 parents d45d40d + 9b4206f commit 937045c

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/Symfony/Component/Yaml/Command/LintCommand.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,20 @@ protected function execute(InputInterface $input, OutputInterface $output)
102102

103103
private function validate($content, $file = null)
104104
{
105+
$prevErrorHandler = set_error_handler(function ($level, $message, $file, $line) use (&$prevErrorHandler) {
106+
if (E_USER_DEPRECATED === $level) {
107+
throw new ParseException($message);
108+
}
109+
110+
return $prevErrorHandler ? $prevErrorHandler($level, $message, $file, $line) : false;
111+
});
112+
105113
try {
106114
$this->getParser()->parse($content);
107115
} catch (ParseException $e) {
108116
return array('file' => $file, 'valid' => false, 'message' => $e->getMessage());
117+
} finally {
118+
restore_error_handler();
109119
}
110120

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

0 commit comments

Comments
 (0)