prettier-plugin-multiline-arrays-2
v5.1.2
Published
Prettier plugin to force array elements to wrap onto new lines.
Maintainers
Readme
prettier-plugin-multiline-arrays-2
Prettier plugin to force array elements to wrap onto new lines, even when there is only one element. It supports TypeScript, JavaScript, JSON, and JSON5, with options for array wrap thresholds, per-line element patterns, and opt-in TypeScript union wrapping.
[!NOTE] This is a maintained fork of electrovir/prettier-plugin-multiline-arrays. Credit to the original plugin for the core idea and implementation.
Install
npm install --save-dev prettier-plugin-multiline-arrays-2Add the plugin to your Prettier config:
export default {
plugins: ["prettier-plugin-multiline-arrays-2"],
};When combining this plugin with parser/preprocessor plugins such as prettier-plugin-organize-imports, put prettier-plugin-multiline-arrays-2 last. Prettier 3.9 selects the last plugin-provided parser for a parser name, and this plugin needs its parser wrapper to run so it can delegate to companion preprocessors and then apply multiline array printing.
Options
multilineArraysWrapThreshold: number. Arrays with more elements than this value are forced to wrap. The default is-1, which disables automatic threshold wrapping.multilineArraysLinePattern: string. Space- or comma-separated list of numbers controlling the element count per line. The pattern repeats for longer arrays. The default is"1".multilineTypeUnionsWrapThreshold: number. TypeScript union types with more members than this value are forced to wrap with one member per line. The default is-1, which disables union wrapping.
Example:
{
"multilineArraysWrapThreshold": 3,
"multilineArraysLinePattern": "2 1",
"multilineTypeUnionsWrapThreshold": 2
}Comment Overrides
Use comments to override the next array:
// prettier-multiline-arrays-next-threshold: 4
const thresholdArray = ["a", "b", "c", "d", "e"];
// prettier-multiline-arrays-next-line-pattern: 2 1
const patternedArray = ["a", "b", "c", "d", "e"];Use set comments to affect later arrays in a file:
// prettier-multiline-arrays-set-threshold: 5
// prettier-multiline-arrays-set-line-pattern: 2 1 3Use prettier-multiline-arrays-reset to return to the configured defaults.
Comment overrides only apply to array formatting. TypeScript union wrapping is
controlled by multilineTypeUnionsWrapThreshold.
Precedence
- Comment overrides.
- Manual wrapping from leading new lines or trailing commas.
- Prettier options.
- Default behavior.
Development
npm ci
npm run build
npm test
npm run release:checkThe test suite runs with Vitest coverage and includes a test:prettier-latest check to verify compatibility with the current npm latest Prettier release.
