![](/img/trans.png)
[英]getting an error of Expected an assignment or function call and instead saw an expression no-unused-expressions in react
[英]React: expected an assignment or function call and instead saw an expression no-unused-expressions
我在我的 React 应用程序中使用了一个 3rd 方库“FoamTree”来进行树可视化。 当我在我的组件中导入它的文件“carrotsearch.foamtree.js”时,它在多行中给我这个错误:
Expected an assignment or function call and instead saw an expression no-unused-expressions
它在普通 Javascript 中运行良好。 仅当它在 react 中导入时才会出错 该文件中有很多行给我这个错误。 我分享的很少:
this.j = function (m, k) {
var f = a[m];
f || (f = [], a[m] = f);
f.push(k);
};
function m(a) {
var d = a.O,
c = a.Sb[0].length - 1;
a.Ib[c] && (d.setLineDash(a.Ib[c]), d.Uj = a.Ld[c]);
d.miterLimit = a.Qd[c];
d.lineWidth = a.Md[c];
d.shadowBlur = a.ie[c];
d.shadowOffsetX = a.je[c];
d.shadowOffsetY = a.ke[c];
d.font = a.Nc[c].replace("#SIZE#", a.hc[c].toString());
}
for (e = 0; e < g; e++) {
h = c[e].kd, m[h.index] = !0, 0 > r * (h.x - k.x) + s * (h.y - k.y) + l * (h.z - k.z) && a.d(b, h);
}
this.kc = function (a, b) {
D.V(b) || (n[a] = b, m(a));
return n[a];
};
编辑:当我更改此块时:
this.kc = function (a, b) {
D.V(b) || (n[a] = b, m(a));
return n[a];
};
对此:
this.kc = function (a, b) {
if( D.V(b) || (n[a] = b, m(a)) ){
return n[a];
}
};
然后错误消失了
通过将其添加到文件顶部解决了该问题:
/* eslint-disable */
显然是导致问题的表达式。 但是看看你的表情,我想你想做的就是:
a[m] = f || []
代替:
var f = a[m];
f || (f = [], a[m] = f);
无论如何, allowShortCircuit
应该可以解决您的问题:
/*eslint no-unused-expressions: [
"error", {
"allowShortCircuit": true
}]*/
更多配置参见:
这只是一个 lint 错误。 你可以忽略它。 错误在这一行:
D.V(b) || (n[a] = b, m(a));
如您所见,它是一个表达式(两个表达式中间的||
),而不是赋值或函数调用。 您可以简单地忽略它或重写它以将表达式作为语句删除,并用 if 条件或类似的东西替换它(任何用于相同目的的东西)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.