Commit 36e51a5
committed
fix: break container instead of expanding one of many object siblings (#641)
Previously `const a = [{...}, {...}, {...}, {...}];` could format as
const a = [{...}, {...}, {...}, {
longest,
}];
— a single sibling was promoted to inline multi-line while the others
stayed inline. dprint's resolver does this whenever every value passes
`allows_inline_multi_line` (issue #641).
Adjust `gen_separated_values_with_result`: precompute the
inline-multi-line flags, then count siblings that would actually
compete for the slot — ignoring arrow/function-expression candidates,
which are the canonical prettier-style hugging shape
(`Array.from(x, () => { … })`, `foo(arg, () => {})`). If two or more
non-arrow siblings remain, none get inline-multi-line, so the resolver
breaks the container.
This aligns the array-of-objects layout with prettier:
const a = [
{ name: "FPN" },
{ name: "FPN Class" },
…
];
The change also applies to function-call arguments and tuple types,
keeping behavior consistent across all `gen_separated_values`
consumers.
Spec updates (existing snaps that pinned the old hugging shape):
- specs/expressions/ArrayExpression/ArrayExpression_PreferSingleLine_True.txt
- specs/issues/issue0520.txt (large nested-JSON snapshot)
- specs/issues/old_repo/issue067.txt
- specs/types/TupleType/TupleType_PreferSingleLine_True.txt
Last-arg arrow hugging (issue0312) is preserved by the new
`is_function_hugging_candidate` helper that drops arrow/fn siblings
from the count.
New spec: specs/issues/issue0641.txt covering the regression, the
preserved arrow-hugging behavior, the single-object-hugging behavior,
and tuple-of-types / array-of-arrays variants. Patterns
cross-referenced against prettier's tests/format/js/arrays fixtures.1 parent f7dd1f3 commit 36e51a5
6 files changed
Lines changed: 506 additions & 337 deletions
File tree
- src/generation
- tests/specs
- expressions/ArrayExpression
- issues
- old_repo
- types/TupleType
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7912 | 7912 | | |
7913 | 7913 | | |
7914 | 7914 | | |
| 7915 | + | |
| 7916 | + | |
| 7917 | + | |
| 7918 | + | |
| 7919 | + | |
| 7920 | + | |
| 7921 | + | |
| 7922 | + | |
| 7923 | + | |
| 7924 | + | |
| 7925 | + | |
| 7926 | + | |
| 7927 | + | |
| 7928 | + | |
| 7929 | + | |
| 7930 | + | |
| 7931 | + | |
| 7932 | + | |
| 7933 | + | |
| 7934 | + | |
7915 | 7935 | | |
7916 | 7936 | | |
7917 | 7937 | | |
| |||
7931 | 7951 | | |
7932 | 7952 | | |
7933 | 7953 | | |
| 7954 | + | |
| 7955 | + | |
| 7956 | + | |
| 7957 | + | |
| 7958 | + | |
| 7959 | + | |
| 7960 | + | |
| 7961 | + | |
| 7962 | + | |
| 7963 | + | |
| 7964 | + | |
| 7965 | + | |
| 7966 | + | |
| 7967 | + | |
| 7968 | + | |
| 7969 | + | |
| 7970 | + | |
| 7971 | + | |
| 7972 | + | |
7934 | 7973 | | |
7935 | 7974 | | |
7936 | 7975 | | |
7937 | 7976 | | |
7938 | 7977 | | |
7939 | 7978 | | |
7940 | | - | |
7941 | | - | |
7942 | | - | |
| 7979 | + | |
| 7980 | + | |
| 7981 | + | |
7943 | 7982 | | |
7944 | 7983 | | |
7945 | 7984 | | |
| |||
Lines changed: 9 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
33 | 33 | | |
34 | 34 | | |
35 | 35 | | |
36 | | - | |
| 36 | + | |
37 | 37 | | |
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | | - | |
45 | | - | |
46 | | - | |
47 | | - | |
48 | | - | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
49 | 52 | | |
50 | 53 | | |
51 | 54 | | |
| |||
0 commit comments