Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc4376f1

Browse files
committed
[Yaml] Add lint:yaml command usage
1 parentf78d06b commitc4376f1

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

‎components/yaml.rst‎

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,65 @@ representation of the object.
250250
parsers will likely not recognize the ``php/object`` tag and non-PHP
251251
implementations certainly won't - use with discretion!
252252

253+
Syntax Validation
254+
~~~~~~~~~~~~~~~~~
255+
256+
The syntax of YAML contents can be validated through the CLI using the
257+
:class:`Symfony\\Component\\Yaml\\Command\\LintCommand` command.
258+
259+
First, install the Console component:
260+
261+
..code-block::bash
262+
263+
$ composer require symfony/console
264+
265+
Create a script containing a console application:
266+
267+
..code-block::php
268+
269+
// lint.php
270+
271+
use Symfony\Component\Console\Application;
272+
use Symfony\Component\Yaml\Command\LintCommand;
273+
274+
(new Application('yaml/lint'))
275+
->add(new LintCommand())
276+
->getApplication()
277+
->setDefaultCommand('lint:yaml', true)
278+
->run();
279+
280+
Then, execute the script for validating contents:
281+
282+
..code-block::bash
283+
284+
# validates a single file
285+
$ php lint.php path/to/file.yml
286+
287+
# or all the files in a directory
288+
$ php lint.php path/to/directory
289+
290+
# or contents passed to STDIN
291+
$ cat path/to/file.yml| php lint.php
292+
293+
The result will be written on STDOUT, default in TXT format:
294+
295+
..code-block::bash
296+
297+
[OK] All 1 YAML files contain valid syntax.
298+
299+
For a JSON output, use the ``format`` option:
300+
301+
..code-block::bash
302+
303+
$ php lint.php path/to/file.yml --format json
304+
305+
[
306+
{
307+
"file":"path/to/file.yml",
308+
"valid":true
309+
}
310+
]
311+
253312
Learn More
254313
----------
255314

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp