File tree Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change @@ -292,6 +292,52 @@ flag::
292
292
// Multiple
293
293
// Line
294
294
// String
295
+ Syntax Validation
296
+ ~~~~~~~~~~~~~~~~~
297
+
298
+ The syntax of YAML contents can be validated through the CLI using the
299
+ :class: `Symfony\\ Component\\ Yaml\\ Command\\ LintCommand ` command.
300
+
301
+ First, install the Console component:
302
+
303
+ .. code-block :: bash
304
+
305
+ $ composer require symfony/console
306
+
307
+ Create a script containing a console application:
308
+
309
+ .. code-block :: php
310
+
311
+ // lint.php
312
+
313
+ use Symfony\Component\Console\Application;
314
+ use Symfony\Component\Yaml\Command\LintCommand;
315
+
316
+ (new Application('yaml/lint'))
317
+ ->add(new LintCommand())
318
+ ->getApplication()
319
+ ->setDefaultCommand('lint:yaml', true)
320
+ ->run();
321
+
322
+ Then, execute the script for validating contents:
323
+
324
+ .. code-block :: bash
325
+
326
+ # validates a single file
327
+ $ php lint.php path/to/file.yml
328
+
329
+ # or all the files in a directory
330
+ $ php lint.php path/to/directory
331
+
332
+ # or contents passed to STDIN
333
+ $ cat path/to/file.yml | php lint.php
334
+
335
+ The result will be written on STDOUT, default in TXT format.
336
+ For a JSON output, use the ``format `` option:
337
+
338
+ .. code-block :: bash
339
+
340
+ $ php lint.php path/to/file.yml --format json
295
341
296
342
Learn More
297
343
----------
You can’t perform that action at this time.
0 commit comments