简体   繁体   中英

React: expected an assignment or function call and instead saw an expression no-unused-expressions

I am using a 3rd party library 'FoamTree' in my react app to make tree visualization. When I import its file 'carrotsearch.foamtree.js' in my component it gives me this error in multiple lines:

Expected an assignment or function call and instead saw an expression  no-unused-expressions

It works fine in normal Javascript. It gives errors only when it is imported in react There are many lines in that file that give me this error. Few of them I am sharing:

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];
 };

Edit: When I change this block:

this.kc = function (a, b) {
    D.V(b) || (n[a] = b, m(a));
    return n[a];
};

to this:

  this.kc = function (a, b) {
      if( D.V(b) || (n[a] = b, m(a)) ){
          return n[a];
      }
  };

then the error is gone

通过将其添加到文件顶部解决了该问题:

/* eslint-disable */

Obviously the expression causing the issue. But looking at your expression, I think you want to do simply like:

a[m] = f || []

Instead of:

 var f = a[m];
      f || (f = [], a[m] = f);

Anyways, allowShortCircuit should solve your issue:

/*eslint no-unused-expressions: [
  "error", { 
    "allowShortCircuit": true
  }]*/

For further configuration, see:

no unused expression

That's just a lint error. You can ignore it. The error is on this line :

D.V(b) || (n[a] = b, m(a));

As you can see it is an expression ( || in the middle of two expressions ) and is not an assignment or a function call. You can simply ignore it or rewrite it to remove the expression as a statement and replace it with an if condition or something similar ( whatever serves the same purpose ).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM