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

Commit6e27d51

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

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

‎components/yaml.rst‎

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,59 @@ 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+
Create a script containing a console application:
260+
261+
..code-block::php
262+
263+
// lint.php
264+
265+
use Symfony\Component\Console\Application;
266+
use Symfony\Component\Yaml\Command\LintCommand;
267+
268+
(new Application('yaml/lint'))
269+
->add(new LintCommand())
270+
->getApplication()
271+
->setDefaultCommand('lint:yaml', true)
272+
->run();
273+
274+
Then, execute the script for validating contents:
275+
276+
..code-block::bash
277+
278+
# validates a single file
279+
$ php lint.php path/to/file.yml
280+
281+
# or all the files in a directory
282+
$ php lint.php path/to/directory
283+
284+
# or contents passed to STDIN
285+
$ cat path/to/file.yml| php lint.php
286+
287+
The result will be written on STDOUT, default in TXT format:
288+
289+
..code-block::bash
290+
291+
[OK] All 1 YAML files contain valid syntax.
292+
293+
For a JSON output, use the ``format`` option:
294+
295+
..code-block::bash
296+
297+
$ php lint.php path/to/file.yml --format json
298+
299+
[
300+
{
301+
"file":"path/to/file.yml",
302+
"valid":true
303+
}
304+
]
305+
253306
Learn More
254307
----------
255308

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp