有没有办法阻止 prettier / prettier-now 将函数参数分解为新行

Kas*_*sim 9 javascript format visual-studio-code prettier

当使用 prettier / prettier-now 进行保存时格式化时,当一个函数包装另一个函数时,它会中断到一个新行,我想知道是否有办法阻止这种行为?

例如:

期望的输出:

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

更漂亮/现在更漂亮输出:

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

小智 2

您可以使用 Comment // prettier-ignore 告诉 prettier 停止格式化代码块

例如:

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
)
Run Code Online (Sandbox Code Playgroud)