Skip to content

Fix EnumFormatter: last enum label missing due to pre-joined string#11

Merged
boserh merged 1 commit into
mainfrom
fix-enums
Jun 30, 2026
Merged

Fix EnumFormatter: last enum label missing due to pre-joined string#11
boserh merged 1 commit into
mainfrom
fix-enums

Conversation

@boserh

@boserh boserh commented Jun 30, 2026

Copy link
Copy Markdown
Owner

EnumFormatter was returning one pre-joined multi-line string per enum column (via lines.join("\n")). When this string was passed through LineFormatter, flat_map treated it as a single element — so the full string was kept intact. However the comma/no-comma logic used labels.map.with_index with { } block syntax, which in some cases produced an off-by-one in the last-element detection, dropping the final label entirely.

Fix:

  • Return a flat array of individual comment lines (flat_map + each_with_index) consistent with every other formatter in the codebase
  • Add AND t.typtype = 'e' to pg_enum_labels query to prevent joining against a non-enum pg_type with the same name
  • Update specs to assert on the flat line array

EnumFormatter was returning one pre-joined multi-line string per enum
column (via lines.join("\n")). When this string was passed through
LineFormatter, flat_map treated it as a single element — so the full
string was kept intact. However the comma/no-comma logic used
labels.map.with_index with { } block syntax, which in some cases
produced an off-by-one in the last-element detection, dropping the
final label entirely.

Fix:
- Return a flat array of individual comment lines (flat_map + each_with_index)
  consistent with every other formatter in the codebase
- Add AND t.typtype = 'e' to pg_enum_labels query to prevent joining
  against a non-enum pg_type with the same name
- Update specs to assert on the flat line array
@boserh boserh merged commit 6409072 into main Jun 30, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant