Skip to content

[Yaml] Add lint:yaml command usage #6963

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

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Yaml] Add lint:yaml command usage
  • Loading branch information
chalasr committed Oct 4, 2016
commit c4172ab0731f95cfedae838b7ddcfc0e43a53111
47 changes: 47 additions & 0 deletions components/yaml.rst
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,53 @@ flag::
// Line
// String

Syntax Validation
~~~~~~~~~~~~~~~~~

The syntax of YAML contents can be validated through the CLI using the
:class:`Symfony\\Component\\Yaml\\Command\\LintCommand` command.

First, install the Console component:

.. code-block:: bash

$ composer require symfony/console

Create a console application with ``lint:yaml`` as its only command::

.. code-block:: php

// lint.php

use Symfony\Component\Console\Application;
use Symfony\Component\Yaml\Command\LintCommand;

(new Application('yaml/lint'))
->add(new LintCommand())
->getApplication()
->setDefaultCommand('lint:yaml', true)
->run();

Then, execute the script for validating contents:

.. code-block:: bash

# validates a single file
$ php lint.php path/to/file.yml

# or all the files in a directory
$ php lint.php path/to/directory

# or contents passed to STDIN
$ cat path/to/file.yml | php lint.php

The result is written to STDOUT and uses a plain text format by default.
Add the ``--format`` option to get the output in JSON format:

.. code-block:: bash

$ php lint.php path/to/file.yml --format json

Learn More
----------

Expand Down