8000 feature #6963 [Yaml] Add lint:yaml command usage (chalasr, javieregui… · symfony/symfony-docs@7a8e74a · GitHub
[go: up one dir, main page]

Skip to content

Commit 7a8e74a

Browse files
committed
feature #6963 [Yaml] Add lint:yaml command usage (chalasr, javiereguiluz)
This PR was submitted for the master branch but it was merged into the 3.2 branch instead (closes #6963). Discussion ---------- [Yaml] Add lint:yaml command usage This documents symfony/symfony#19139 (merged on 3.2) and closes symfony/symfony#19916. Commits ------- ed4cb40 Remove an unneeded code directive 44b4ad0 Use `terminal` instead of `bash` for console code 78075c1 Yaml] Add lint:yaml command usage
2 parents 22ca5b8 + ed4cb40 commit 7a8e74a

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

components/yaml.rst

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,51 @@ flag::
293293
// Line
294294
// String
295295

296+
Syntax Validation
297+
~~~~~~~~~~~~~~~~~
298+
299+
The syntax of YAML contents can be validated through the CLI using the
300+
:class:`Symfony\\Component\\Yaml\\Command\\LintCommand` command.
301+
302+
First, install the Console component:
303+
304+
.. code-block:: terminal
305+
306+
$ composer require symfony/console
307+
308+
Create a console application with ``lint:yaml`` as its only command::
309+
310+
// lint.php
311+
312+
use Symfony\Component\Console\Application;
313+
use Symfony\Component\Yaml\Command\LintCommand;
314+
315+
(new Application('yaml/lint'))
316+
->add(new LintCommand())
317+
->getApplication()
318+
->setDefaultCommand('lint:yaml', true)
319+
->run();
320+
321+
Then, execute the script for validating contents:
322+
323+
.. code-block:: terminal
324+
325+
# validates a single file
326+
$ php lint.php path/to/file.yml
327+
328+
# or all the files in a directory
329+
$ php lint.php path/to/directory
330+
331+
# or contents passed to STDIN
332+
$ cat path/to/file.yml | php lint.php
333+
334+
The result is written to STDOUT and uses a plain text format by default.
335+
Add the ``--format`` option to get the output in JSON format:
336+
337+
.. code-block:: terminal
338+
339+
$ php lint.php path/to/file.yml --format json
340+
296341
Learn More
297342
----------
298343

0 commit comments

Comments
 (0)
0