How to appease Lint rules without breaking the code

Hi Everyone,

So I’m building an app for the community, and I’m using the recommended NC Lint rules, but I keep getting a “error Expected ‘===’ and instead saw ‘==’ eqeqeq”. When I appease Lint and change the equation to ‘===’ it brakes my code. Yes, I am aware that ‘===’ means compare type. The problem is that its comparing two string values but they types don’t match??

So the JavaScript line Lint does not like is, for the a function in the UserSettings gui script.

The “roid” is a 64+ character string value, that comes from the same page, from a NcActionRadio event, on this line,

The “this.establishedContactCorrelations” is a array with 6 fields, one of them being “roid”, a 64+ string character value, that is pulled from a PHP function here:

So how do I appease Lint and not break the code?

FYI, I am totally aware I am probably missing something basic and will look like a donkey after I read the answer. :joy: :man_facepalming:

If I am correct (just a quick glance over the code), this.establishedContactCorrelations is an object in JS with keys like ContactCorrelations. Is that correct and intended?

If yes, the findIndex is just wring: It is intended for use with arrays not objects AFAIK. You will have to use other means like iterating over the keys or entries.

Unfortunately, I will be out soon so I can only help tomorrow again.

Hi @christianlupus ,

Thank for the inspiration, your comment pointed me in the right direction. I completely, neglected the mechanics of data flow between the PHP and Javascript. Although the data is in a array in the PHP code it then gets converted to JSON, which is then converted to an Object in Javascript.

So the easiest solution was just to type cast the variables, which then let me use the ‘===’ type cast equals.

this.establishedContactCorrelations.findIndex(i => String(i.roid) === String(roid))

Thank you!

Have you verified that this.establishedContactCorrelations is an array? I would be surprised from the static code analysis and the linter will have no clue as it is unaware of the PHP part involved.