Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. LintCommand.php

function LintCommand::displayTxt

File

vendor/symfony/yaml/Command/LintCommand.php, line 161

Class

LintCommand
Validates YAML files syntax and outputs encountered errors.

Namespace

Symfony\Component\Yaml\Command

Code

private function displayTxt(SymfonyStyle $io, array $filesInfo, bool $errorAsGithubAnnotations = false) : int {
    $countFiles = \count($filesInfo);
    $erroredFiles = 0;
    $suggestTagOption = false;
    if ($errorAsGithubAnnotations) {
        $githubReporter = new GithubActionReporter($io);
    }
    foreach ($filesInfo as $info) {
        if ($info['valid'] && $this->displayCorrectFiles) {
            $io->comment('<info>OK</info>' . ($info['file'] ? \sprintf(' in %s', $info['file']) : ''));
        }
        elseif (!$info['valid']) {
            ++$erroredFiles;
            $io->text('<error> ERROR </error>' . ($info['file'] ? \sprintf(' in %s', $info['file']) : ''));
            $io->text(\sprintf('<error> >> %s</error>', $info['message']));
            if (str_contains($info['message'], 'PARSE_CUSTOM_TAGS')) {
                $suggestTagOption = true;
            }
            if ($errorAsGithubAnnotations) {
                $githubReporter->error($info['message'], $info['file'] ?? 'php://stdin', $info['line']);
            }
        }
    }
    if (0 === $erroredFiles) {
        $io->success(\sprintf('All %d YAML files contain valid syntax.', $countFiles));
    }
    else {
        $io->warning(\sprintf('%d YAML files have valid syntax and %d contain errors.%s', $countFiles - $erroredFiles, $erroredFiles, $suggestTagOption ? ' Use the --parse-tags option if you want parse custom tags.' : ''));
    }
    return min($erroredFiles, 1);
}
RSS feed
Powered by Drupal