8000 feature #39641 [Yaml] Add --exclude and negatable --parse-tags option… · symfony/symfony@a9753d7 · GitHub
[go: up one dir, main page]

Skip to content

Commit a9753d7

Browse files
committed
feature #39641 [Yaml] Add --exclude and negatable --parse-tags option to lint:yaml command (christingruber)
This PR was merged into the 5.4 branch. Discussion ---------- [Yaml] Add --exclude and negatable --parse-tags option to lint:yaml command | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | None | License | MIT | Doc PR | symfony/symfony-docs#14780 Added a new `--exclude` option to exclude one or more specific files from multiple file list: ```lint:yaml dirname --exclude=/dirname/foo.yml --exclude=/dirname/bar.yml``` Allow negatable for the parse tags option with `--no-parse-tags` and increase the `symfony/console` dependency to version 5.3 Commits ------- 55704f3 [Yaml] Add an --exclude option to lint:yaml command
2 parents fccd9ca + 55704f3 commit a9753d7

File tree

4 files changed

+33
-5
lines changed

4 files changed

+33
-5
lines changed

src/Symfony/Component/Yaml/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
CHANGELOG
22
=========
33

4+
5.4
5+
---
6+
7+
* Add new `lint:yaml dirname --exclude=/dirname/foo.yaml --exclude=/dirname/bar.yaml`
8+
option to exclude one or more specific files from multiple file list
9+
* Allow negatable for the parse tags option with `--no-parse-tags`
10+
411
5.3
512
---
613

src/Symfony/Component/Yaml/Command/LintCommand.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,8 @@ protected function configure()
5858
->setDescription(self::$defaultDescription)
5959
->addArgument('filename', InputArgument::IS_ARRAY, 'A file, a directory or "-" for reading from STDIN')
6060
->addOption('format', null, InputOption::VALUE_REQUIRED, 'The output format')
61-
->addOption('parse-tags', null, InputOption::VALUE_NONE, 'Parse custom tags')
61+
->addOption('exclude', 'e', InputOption::VALUE_REQUIRED | InputOption::VALUE_IS_ARRAY, 'Path(s) to exclude')
62+
->addOption('parse-tags', null, InputOption::VALUE_NEGATABLE, 'Parse custom tags', null)
6263
->setHelp(<<<EOF
6364
The <info>%command.name%</info> command lints a YAML file and outputs to STDOUT
6465
the first encountered syntax error.
@@ -76,6 +77,10 @@ protected function configure()
7677
<info>php %command.full_name% dirname</info>
7778
<info>php %command.full_name% dirname --format=json</info>
7879
80+
You can also exclude one or more specific files:
81+
82+
<info>php %command.full_name% dirname --exclude="dirname/foo.yaml" --exclude="dirname/bar.yaml"</info>
83+
7984
EOF
8085
)
8186
;
@@ -85,7 +90,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
8590
{
8691
$io = new SymfonyStyle($input, $output);
8792
$filenames = (array) $input->getArgument('filename');
93+
$excludes = $input->getOption('exclude');
8894
$this->format = $input->getOption('format');
95+
$flags = $input->getOption('parse-tags');
8996

9097
if ('github' === $this->format && !class_exists(GithubActionReporter::class)) {
9198
throw new \InvalidArgumentException('The "github" format is only available since "symfony/console" >= 5.3.');
@@ -96,8 +103,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
96103
$this->format = class_exists(GithubActionReporter::class) && GithubActionReporter::isGithubActionEnvironment() ? 'github' : 'txt';
97104
}
98105

106+
$flags = $flags ? Yaml::PARSE_CUSTOM_TAGS : 0;
107+
99108
$this->displayCorrectFiles = $output->isVerbose();
100-
$flags = $input->getOption('parse-tags') ? Yaml::PARSE_CUSTOM_TAGS : 0;
101109

102110
if (['-'] === $filenames) {
103111
return $this->display($io, [$this->validate(file_get_contents('php://stdin'), $flags)]);
@@ -114,7 +122,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
114122
}
115123

116124
foreach ($this->getFiles($filename) as $file) {
117-
$filesInfo[] = $this->validate(file_get_contents($file), $flags, $file);
125+
if (!\in_array($file->getPathname(), $excludes, true)) {
126+
$filesInfo[] = $this->validate(file_get_contents($file), $flags, $file);
127+
}
118128
}
119129
}
120130

src/Symfony/Component/Yaml/Tests/Command/LintCommandTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,17 @@ public function testCustomTagsError()
142142
$this->assertSame(1, $ret, 'lint:yaml exits with code 1 in case of error');
143143
}
144144

145+
public function testLintWithExclude()
146+
{
147+
$tester = $this->createCommandTester();
148+
$filename1 = $this->createFile('foo: bar');
149+
$filename2 = $this->createFile('bar: baz');
150+
151+
$ret = $tester->execute(['filename' => [$filename1, $filename2], '--exclude' => [$filename1]], ['verbosity' => OutputInterface::VERBOSITY_VERBOSE, 'decorated' => false]);
152+
$this->assertSame(0, $ret, 'lint:yaml exits with code 0 in case of success');
153+
$this->assertStringContainsString('All 1 YAML files contain valid syntax.', trim($tester->getDisplay()));
154+
}
155+
145156
public function testLintFileNotReadable()
146157
{
147158
$this->expectException(\RuntimeException::class);

src/Symfony/Component/Yaml/composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
"symfony/polyfill-php81": "^1.22"
2424
},
2525
"require-dev": {
26-
"symfony/console": "^4.4|^5.0|^6.0"
26+
"symfony/console": "^5.3|^6.0"
2727
},
2828
"conflict": {
29-
"symfony/console": "<4.4"
29+
"symfony/console": "<5.3"
3030
},
3131
"suggest": {
3232
"symfony/console": "For validating YAML files using the lint command"

0 commit comments

Comments
 (0)
0