Skip to content

feat(oxfmt): add arrayWrap option for array literal wrapping control#20114

Open
jgeurts wants to merge 6 commits intooxc-project:mainfrom
jgeurts:array-literal-wrapping
Open

feat(oxfmt): add arrayWrap option for array literal wrapping control#20114
jgeurts wants to merge 6 commits intooxc-project:mainfrom
jgeurts:array-literal-wrapping

Conversation

@jgeurts
Copy link

@jgeurts jgeurts commented Mar 8, 2026

Fix #20007

Add arrayWrap configuration option to oxfmt with three modes:

  • "preserve" (default): use Prettier's auto-expand heuristic
  • "collapse": collapse arrays to single line when they fit within printWidth
  • { "minElementsToWrap": N }: force one-element-per-line when count >= threshold

Applies to array expressions, array destructuring patterns, and array assignment targets.

NOTE: I used Claude to help create these changes. Rust is not my first language, so please let me know if there are any improvements or changes that I can make!

@jgeurts jgeurts requested a review from Dunqing as a code owner March 8, 2026 16:34
@github-actions github-actions bot added A-cli Area - CLI A-formatter Area - Formatter C-enhancement Category - New feature or request labels Mar 8, 2026
Add `arrayWrap` configuration option to oxfmt with three modes:

- `"preserve"` (default): use Prettier's auto-expand heuristic
- `"collapse"`: collapse arrays to single line when they fit within printWidth
- `{ "minElementsToWrap": N }`: force one-element-per-line when count >= threshold

Applies to array expressions, array destructuring patterns, and array
assignment targets.
@jgeurts jgeurts force-pushed the array-literal-wrapping branch from 819b7c0 to 3450a6d Compare March 8, 2026 16:37
@hilja
Copy link

hilja commented Mar 8, 2026

Tangentially realated: I've been dreaming of a "matrix wrap", if key count exceeds a threshold it would wrap them more efficiently.

Is this something oxfmt could have or are we on plugin territory?

export const timezones = {
  // oxfmt-ignore
  Africa: [
    'Abidjan', 'Accra', 'Addis_Ababa', 'Algiers', 'Asmara', 'Bamako',
    'Bangui', 'Banjul', 'Bissau', 'Blantyre', 'Brazzaville', 'Bujumbura',
    'Cairo', 'Casablanca', 'Ceuta', 'Conakry', 'Dakar', 'Djibouti', 'Douala',
    'El_Aaiun', 'Freetown', 'Gaborone', 'Harare', 'Johannesburg', 'Juba',
    'Kampala', 'Khartoum', 'Kigali', 'Kinshasa', 'Lagos', 'Libreville',
    'Lome', 'Luanda', 'Lubumbashi', 'Lusaka', 'Malabo', 'Maputo',
    'Maseru', 'Mbabane', 'Mogadishu', 'Monrovia', 'Nairobi', 'Ndjamena',
    'Niamey', 'Nouakchott', 'Ouagadougou', 'Sao_Tome', 'Tripoli', 'Tunis',
    'Windhoek',
  ],
  // ...
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-cli Area - CLI A-formatter Area - Formatter C-enhancement Category - New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support heuristic wrapping for array literals

2 participants