Source:  Twitter logo

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

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

/* eslint-disable */
26 users liked answer #0dislike answer #026
Ankit Kaushal profile pic
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

2 users liked answer #1dislike answer #12
Bhojendra Rauniyar profile pic
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 ).

1 users liked answer #2dislike answer #21
rishichawda profile pic
rishichawda

Copyright © 2022 QueryThreads

All content on Query Threads is licensed under the Creative Commons Attribution-ShareAlike 3.0 license (CC BY-SA 3.0).