Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 654
Ankit Kaushal Avatar asked Mar 25 '19 06:03

Ankit Kaushal


3 Answers

The issue got solved by adding this to the top of the file:

/* eslint-disable */
like image 97
Ankit Kaushal Avatar answered Oct 18 '22 22:10

Ankit Kaushal


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

like image 32
Bhojendra Rauniyar Avatar answered Oct 18 '22 22:10

Bhojendra Rauniyar


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 ).

like image 27
rishichawda Avatar answered Oct 18 '22 20:10

rishichawda