How to stop Prettier from enforcing a new line when using an empty array

Viewed 79

I want to keep the array definition on the same line as the closing bracket of the previous parameter.

Example of what I want:

const ids = models.reduce(
    (prev: number[], curr: Model) => {
        if (this.value === curr.value) prev.push(curr.id);
        return prev;
    }, [] // <-- THIS
);

What happens when I save the file:

const ids = models.reduce(
    (prev: number[], curr: Model) => {
        if (this.value === curr.value) prev.push(curr.id);
        return prev;
    },
    []
);

How can I achieve this? Any help is appreciated!

1 Answers

You can't. Prettier has very few configuration options by design. It offers a small amount of control, but in the end it it designed to take the decision on how to style certain code elements off the developers, as it is stated in the documentation:

By far the biggest reason for adopting Prettier is to stop all the ongoing debates over styles.

If you want a customizable formatter, Prettier is the wrong tool to use.

Related