[英]With ES lint error want to reolve without disabling it or changing rule
While working with the react I have this below error but I dont want to use es-lint-disable在使用 react 时出现以下错误,但我不想使用 es-lint-disable
With the below code I am getting the lint error of Do not nest ternary expressions.eslintno-nested-ternary
How to resolve this?使用下面的代码,我得到了
Do not nest ternary expressions.eslintno-nested-ternary
的 lint 错误如何解决这个问题?
getDaySuffix = day => (day === (1 || 21 || 31)? 'st': day === (2 || 22)? 'nd': day === (3 || 23)? 'rd': 'th');
getting this error when I try to do following Assignment to property of function parameter 'data'.eslintno-param-reassign
当我尝试执行以下
Assignment to property of function parameter 'data'.eslintno-param-reassign
时出现此错误
if (recurrence.month) { delete data.date; if (recurrence.month) { 删除数据.date; }
}
With below code I am getting an error Assignment to property of function parameter 'carry'.eslintno-param-reassign
使用下面的代码我得到一个错误
Assignment to property of function parameter 'carry'.eslintno-param-reassign
(carry, current) => { if (current.field === 'access_group_uuid') { carry[current.field] = (carry[current.field] || []).concat( current.value, ); } else { carry[current.field] = carry[current.field]? [carry[current.field], current.value]: current.value; } return carry; }, {}, );```
With below code I am getting error of Unexpected dangling '_' in '_id'.eslintno-underscore-dangle
.使用下面的代码,我得到了
Unexpected dangling '_' in '_id'.eslintno-underscore-dangle
错误。 here the data I am getting if from backend I cannot change it.这里是我从后端获取的数据,如果我无法更改它。 How can I resolve lint error?
如何解决 lint 错误?
const data = { _id: reporData._id, name: reporData.name }; const data = { _id: reporData._id, name: reporData.name, emails, recurrence: obj.recurrence, scheduled_report: true, // eslint-disable-next-line scheduled_report_id: obj._id, };```
Can anyone help me with this?谁能帮我这个? I trtied searching the error but I found
// eslint-disable-next-line
solution but I don't want that solution.我试图搜索错误,但我找到了
// eslint-disable-next-line
解决方案,但我不想要该解决方案。 Can please anyone help me with this?可以请任何人帮助我吗?
Thanks谢谢
const getDaySuffix = day => {
if (day === 1 || day === 21 || day === 31) return 'st'
if (day === 2 || day === 22) return 'nd'
if (day === 3 || day === 23) return 'rd'
return 'th'
}
This rule aims to prevent unintended behavior caused by modification or reassignment of function parameters.此规则旨在防止因修改或重新分配 function 参数而导致的意外行为。 https://eslint.org/docs/rules/no-param-reassign Clone data object and work with it.
https://eslint.org/docs/rules/no-param-reassign克隆数据 object 并使用它。
Same as #2.与#2 相同。 By updating
carry
you mutate this object in original structure.通过更新
carry
,您可以改变原始结构中的 object。 Create new object, update it and return.创建新的 object,更新它并返回。
(carry, current) => {
const carryClone = {...carry}
if (current.field === 'access_group_uuid') {
carryClone[current.field] = (carryClone[current.field] || []).concat(current.value)
} else {
carryClone[current.field] = carryClone[current.field] ? [carryClone[current.field], current.value] : current.value
}
return carryClone
}
Object key cannot be _id
. Object 密钥不能是
_id
。 Use id
only instead.仅使用
id
。
const data = { id: reporData._id, name: reporData.name };
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.