我一直在开发一个应用程序,最近编写了一个 Mongoose 聚合查询以将一些数据返回到 API。我的工作区是使用 prettier 和 eslint 设置的。
这是我的.eslintrc
{
"extends": ["plugin:prettier/recommended"],
"parserOptions": {
"ecmaVersion": 8,
"ecmaFeatures": {
"experimentalObjectRestSpread": true
},
"sourceType": "module"
},
"rules": {
"prettier/prettier": ["error", {
"singleQuote": true
}],
"max-len": 0
}
}
我将 prettier 设置为忽略 js 文件并让 eslint 处理它们。经过 eslint 格式化后,生成的代码如下所示。
// rehire by employee ID
app.get('/employee/:empID', (req, res) => {
const empID = req.params.empID;
Rehires.aggregate(
[
{ $match: { 'data.EMPLOYEE_ID': empID } },
{
$project: {
data: {
$filter: {
input: '$data',
as: 'data',
cond: { $eq: ['$$data.EMPLOYEE_ID', empID] }
}
}
}
}
],
(err, employees) => {
// check if employees
if (!employees || employees.length === 0) {
return res.status(404).json({
error: `No rehire file(s) exist that contain an Employee ID of ${empID}`
});
}
//employees exist
return res.json(employees);
}
);
});
我不确定要关闭哪些 eslint 规则,所以这不是 30 行代码。什么规则强制执行所有这些换行符?
最佳答案
根据需要设置代码格式,使用 eslint
不使用 --fix
option ,并且它应该报告所有有问题的语法并提及相应的规则。
我的猜测(我没有尝试)是 function-paren-newline
, curly
, object-curly-newline
和 object-property-newline
.
关于javascript - 不确定要关闭哪些 ESLint 规则,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52898317/