首页 > 解决方案 > 有没有办法阻止 prettier / prettier-now 将函数参数分解为新行

问题描述

当使用 prettier / prettier-now 在保存时格式化时,当一个函数环绕另一个函数时,它会换行,我想知道是否有一个停止这种行为?

例如:

期望的输出:

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

Prettier / Prettier-now 输出:

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

标签: javascriptvisual-studio-codeformatprettier

解决方案


您可以使用 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
)

推荐阅读