Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix lint commands frozen on empty stdin #33523

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions src/Symfony/Bridge/Twig/Command/LintCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ protected function configure()

You can validate the syntax of contents passed from STDIN:

<info>cat filename | php %command.full_name%</info>
<info>cat filename | php %command.full_name% -</info>

Or the syntax of a file:

Expand All @@ -77,13 +77,15 @@ protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
$filenames = $input->getArgument('filename');
$hasStdin = ['-'] === $filenames;

if ($hasStdin || !$filenames) {
if ($hasStdin || 0 === ftell(STDIN)) { // remove 0 === ftell(STDIN) check in 5.0
if (!$hasStdin) {
@trigger_error('Calling to the "lint:twig" command providing pipe file content to STDIN without passing the dash symbol "-" explicitly is deprecated since Symfony 4.4.', E_USER_DEPRECATED);
}
if (['-'] === $filenames) {
return $this->display($input, $output, $io, [$this->validate($this->getStdin(), uniqid('sf_', true))]);
}

if (!$filenames) {
// @deprecated to be removed in 5.0
if (0 === ftell(STDIN)) {
@trigger_error('Piping content from STDIN to the "lint:twig" command without passing the dash symbol "-" as argument is deprecated since Symfony 4.4.', E_USER_DEPRECATED);

return $this->display($input, $output, $io, [$this->validate($this->getStdin(), uniqid('sf_', true))]);
}
Expand All @@ -97,7 +99,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
$filenames = array_merge(...$paths);
}

if (0 === \count($filenames)) {
if (!$filenames) {
throw new RuntimeException('Please provide a filename or pipe template content to STDIN.');
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,29 +35,12 @@ public function testGetHelp()
{
$command = new XliffLintCommand();
$expected = <<<EOF
The <info>%command.name%</info> command lints a XLIFF file and outputs to STDOUT
the first encountered syntax error.

You can validates XLIFF contents passed from STDIN:

<info>cat filename | php %command.full_name%</info>

You can also validate the syntax of a file:

<info>php %command.full_name% filename</info>

Or of a whole directory:

<info>php %command.full_name% dirname</info>
<info>php %command.full_name% dirname --format=json</info>

Or find all files in a bundle:

<info>php %command.full_name% @AcmeDemoBundle</info>

EOF;

$this->assertEquals($expected, $command->getHelp());
$this->assertStringContainsString($expected, $command->getHelp());
}

public function testLintFilesFromBundleDirectory()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,29 +72,12 @@ public function testGetHelp()
{
$command = new YamlLintCommand();
$expected = <<<EOF
The <info>%command.name%</info> command lints a YAML file and outputs to STDOUT
the first encountered syntax error.

You can validates YAML contents passed from STDIN:

<info>cat filename | php %command.full_name%</info>

You can also validate the syntax of a file:

<info>php %command.full_name% filename</info>

Or of a whole directory:

<info>php %command.full_name% dirname</info>
<info>php %command.full_name% dirname --format=json</info>

Or find all files in a bundle:

<info>php %command.full_name% @AcmeDemoBundle</info>

EOF;

$this->assertEquals($expected, $command->getHelp());
$this->assertStringContainsString($expected, $command->getHelp());
}

public function testLintFilesFromBundleDirectory()
Expand Down
16 changes: 9 additions & 7 deletions src/Symfony/Component/Translation/Command/XliffLintCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ protected function configure()

You can validates XLIFF contents passed from STDIN:

<info>cat filename | php %command.full_name%</info>
<info>cat filename | php %command.full_name% -</info>

You can also validate the syntax of a file:

Expand All @@ -83,16 +83,18 @@ protected function execute(InputInterface $input, OutputInterface $output)
$filenames = (array) $input->getArgument('filename');
$this->format = $input->getOption('format');
$this->displayCorrectFiles = $output->isVerbose();
$hasStdin = ['-'] === $filenames;

if ($hasStdin || !$filenames) {
if (!$hasStdin && 0 !== ftell(STDIN)) { // remove 0 !== ftell(STDIN) check in 5.0
if (['-'] === $filenames) {
return $this->display($io, [$this->validate($this->getStdin())]);
}

// @deprecated to be removed in 5.0
if (!$filenames) {
if (0 !== ftell(STDIN)) {
throw new RuntimeException('Please provide a filename or pipe file content to STDIN.');
}

if (!$hasStdin) {
@trigger_error('Calling to the "lint:xliff" command providing pipe file content to STDIN without passing the dash symbol "-" explicitly is deprecated since Symfony 4.4.', E_USER_DEPRECATED);
}
@trigger_error('Piping content from STDIN to the "lint:xliff" command without passing the dash symbol "-" as argument is deprecated since Symfony 4.4.', E_USER_DEPRECATED);

return $this->display($io, [$this->validate($this->getStdin())]);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public function testGetHelp()

You can validates XLIFF contents passed from STDIN:

<info>cat filename | php %command.full_name%</info>
<info>cat filename | php %command.full_name% -</info>

You can also validate the syntax of a file:

Expand Down
20 changes: 11 additions & 9 deletions src/Symfony/Component/Yaml/Command/LintCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected function configure()

You can validates YAML contents passed from STDIN:

<info>cat filename | php %command.full_name%</info>
<info>cat filename | php %command.full_name% -</info>

You can also validate the syntax of a file:

Expand All @@ -86,18 +86,20 @@ protected function execute(InputInterface $input, OutputInterface $output)
$this->format = $input->getOption('format');
$this->displayCorrectFiles = $output->isVerbose();
$flags = $input->getOption('parse-tags') ? Yaml::PARSE_CUSTOM_TAGS : 0;
$hasStdin = ['-'] === $filenames;

if ($hasStdin || !$filenames) {
if (!$hasStdin && 0 !== ftell(STDIN)) { // remove 0 !== ftell(STDIN) check in 5.0
throw new RuntimeException('Please provide a filename or pipe file content to STDIN.');
}
if (['-'] === $filenames) {
return $this->display($io, [$this->validate($this->getStdin(), $flags)]);
}

if (!$hasStdin) {
@trigger_error('Calling to the "lint:yaml" command providing pipe file content to STDIN without passing the dash symbol "-" explicitly is deprecated since Symfony 4.4.', E_USER_DEPRECATED);
// @deprecated to be removed in 5.0
if (!$filenames) {
if (0 === ftell(STDIN)) {
@trigger_error('Piping content from STDIN to the "lint:yaml" command without passing the dash symbol "-" as argument is deprecated since Symfony 4.4.', E_USER_DEPRECATED);

return $this->display($io, [$this->validate($this->getStdin(), $flags)]);
}

return $this->display($io, [$this->validate($this->getStdin(), $flags)]);
throw new RuntimeException('Please provide a filename or pipe file content to STDIN.');
}

$filesInfo = [];
Expand Down