Kassim
Kassim

Reputation: 91

Is there a way to stop prettier / prettier-now from breaking function arguments into new lines

When using prettier / prettier-now to format on save, when a function wraps around another function it breaks to a new line, I was wondering if there was a to stop this behavior?

For example:

Desired output:

app.get('/campgrounds/:id', catchAsync(async (req, res) => {
    const campground = await Campground.findById(req.params.id);
    res.render('campgrounds/show', { campground });
}));

Prettier / Prettier-now output:

app.get(
    '/campgrounds/:id',
    catchAsync(async (req, res) => {
        const campground = await Campground.findById(req.params.id);
        res.render('campgrounds/show', { campground });
    })
);

Upvotes: 9

Views: 2492

Answers (1)

Dpk
Dpk

Reputation: 645

You can tell prettier to stop formatting a block of code by using Comment // prettier-ignore

For example:

A(
  1, 0, 0,
  0, 1, 0,
  0, 0, 1
)

// prettier-ignore
B(
  1, 0, 0,
  0, 1, 0,
  0, 0, 1
)
will be transformed to:

A(1, 0, 0, 0, 1, 0, 0, 0, 1);
    
// prettier-ignore
B(
  1, 0, 0,
  0, 1, 0,
  0, 0, 1
)

Upvotes: 2

Related Questions