Commit c5b61fb
committed
Assoc uses Identity formatter if any value is nil
The existing assoc formatter has logic to identify the case where a
value is nil (in a Ruby-3.1 style hash) and preserve the existing
formatting. For example: `{ first:, "second" => "value" }` is correctly
left as-is.
However, this logic only worked if the first assoc in the
container had the nil value - if a later assoc had a nil value, the
Identity formatter might not be chosen which could cause the formatter
to generate invalid Ruby code.
As an example, this code: `{ "first" => "value", second: }` would be
turned into `{ "first" => "value", :second => }`.
This patch pulls the nil value check up to the top of
`HashKeyFormatter.for` to ensure it takes precendence over any other
formatting selections. The fixtures have been updated to cover both
cases (nil value in first position, nil value in last position).
Fixes #4461 parent 8dfae19 commit c5b61fb
2 files changed
+16
-8
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1784 | 1784 | | |
1785 | 1785 | | |
1786 | 1786 | | |
| 1787 | + | |
| 1788 | + | |
| 1789 | + | |
| 1790 | + | |
| 1791 | + | |
| 1792 | + | |
| 1793 | + | |
| 1794 | + | |
| 1795 | + | |
| 1796 | + | |
| 1797 | + | |
| 1798 | + | |
1787 | 1799 | | |
1788 | 1800 | | |
1789 | 1801 | | |
1790 | | - | |
1791 | | - | |
1792 | | - | |
1793 | | - | |
1794 | | - | |
1795 | | - | |
1796 | | - | |
1797 | | - | |
1798 | 1802 | | |
1799 | 1803 | | |
1800 | 1804 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
48 | 48 | | |
49 | 49 | | |
50 | 50 | | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
0 commit comments