Skip to content

Commit

Permalink
minor #54326 [Yaml] prefix examples with # (tacman)
Browse files Browse the repository at this point in the history
This PR was squashed before being merged into the 7.0 branch.

Discussion
----------

[Yaml] prefix examples with #

| Q             | A
| ------------- | ---
| Branch?       | 7.0
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Issues        | Fix ##54154
| License       | MIT

As mentioned in the issue, the yaml before wasn't valid, as the examples were dumped as an array in the yaml.  This simply comments the examples.

Commits
-------

fd95a8f [Yaml] prefix examples with #
  • Loading branch information
fabpot committed Mar 22, 2024
2 parents ed617c8 + fd95a8f commit afc47ed
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
Expand Up @@ -170,7 +170,7 @@ private function writeNode(NodeInterface $node, ?NodeInterface $parentNode = nul

$this->writeLine('# '.$message.':', $depth * 4 + 4);

$this->writeArray(array_map(Inline::dump(...), $example), $depth + 1);
$this->writeArray(array_map(Inline::dump(...), $example), $depth + 1, true);
}

if ($children) {
Expand All @@ -191,7 +191,7 @@ private function writeLine(string $text, int $indent = 0): void
$this->reference .= sprintf($format, $text)."\n";
}

private function writeArray(array $array, int $depth): void
private function writeArray(array $array, int $depth, bool $asComment = false): void
{
$isIndexed = array_is_list($array);

Expand All @@ -201,11 +201,12 @@ private function writeArray(array $array, int $depth): void
} else {
$val = $value;
}
$prefix = $asComment ? '# ' : '';

if ($isIndexed) {
$this->writeLine('- '.$val, $depth * 4);
$this->writeLine($prefix.'- '.$val, $depth * 4);
} else {
$this->writeLine(sprintf('%-20s %s', $key.':', $val), $depth * 4);
$this->writeLine($prefix.sprintf('%-20s %s', $key.':', $val), $depth * 4);
}

if (\is_array($value)) {
Expand Down
Expand Up @@ -117,8 +117,8 @@ enum: ~ # One of "this"; "that"; Symfony\Component\Config\Tests\
variable:
# Examples:
- foo
- bar
# - foo
# - bar
parameters:
# Prototype: Parameter name
Expand Down

0 comments on commit afc47ed

Please sign in to comment.