Fix #5599, long yaml keys trigger explicit mapping (#10874)

Fix #5599, long yaml keys trigger explicit mapping
This commit is contained in:
Philip Davies authored and GitHub committed 2021-05-15 14:03:06 +03:00
1 parent 1005b4bca3
commit bcd62546c2
6 files changed
+142 -13

No files matched your search

+66
View File
@@ -0,0 +1,66 @@
#### Don't switch to explicit mappings needlessly (#10874 by @pdavies)
Previously, Prettier printed long YAML keys using explicit mapping syntax. The intent was to use that syntax to accommodate multiline keys, but it had the unintended effect of using it even for long keys that couldn’t be made multiline – for example, because `--prose-wrap` was set to `preserve` or the key didn’t contain whitespace. This is bad because:
- Doing so has the effect of further increasing the line length.
- Explicit mappings are obscure and most people have never seen them. It causes confusion to introduce them needlessly.
<!-- prettier-ignore -->
```yaml
# Input
- stage: Process
jobs:
- template: Process.yml
parameters:
${{ if in(parameters.BuildType, 'a') }}:
BuildArtifacts:
- input: Build.Release.x86
output: Processed.Release.x86
${{ if in(parameters.BuildType, 'b ') }}:
BuildArtifacts:
- input: Build.Release
output: Processed.Release
# Prettier stable
- stage: Process
jobs:
- template: Process.yml
parameters:
${{ if in(parameters.BuildType, 'a') }}:
BuildArtifacts:
- input: Build.Release.x86
output: Processed.Release.x86
? ${{ if in(parameters.BuildType, 'b ') }}
: BuildArtifacts:
- input: Build.Release
output: Processed.Release
# Prettier main
- stage: Process
jobs:
- template: Process.yml
parameters:
${{ if in(parameters.BuildType, 'a') }}:
BuildArtifacts:
- input: Build.Release.x86
output: Processed.Release.x86
${{ if in(parameters.BuildType, 'b ') }}:
BuildArtifacts:
- input: Build.Release
output: Processed.Release
# Prettier main (with --prose-wrap always)
- stage: Process
jobs:
- template: Process.yml
parameters:
${{ if in(parameters.BuildType, 'a') }}:
BuildArtifacts:
- input: Build.Release.x86
output: Processed.Release.x86
? ${{ if in(parameters.BuildType, 'b ')
}}
: BuildArtifacts:
- input: Build.Release
output: Processed.Release
```