Something must have changed recently in the lint checker being used for the javascript code for back-end modules. Just today I went in to our http-functions.js file to make some edits, and all of a sudden I have yellow and red everywhere!
While some of the warnings are helpful, many are not. Here is an example. In this code:
response.body = {[RESULT_KEY]:true,[RESULT_DATA_KEY]:false};
breakNow = false;
await wixData.query(SITMEMBERS_TABLE)
.eq(EMAIL_ARG, username)
.include(MEMBERDEVICES_FIELD)
.find(options)
.then( (results) => {
if (results.items.length === 0 ) {
response.body = {[RESULT_KEY]: false, [ERRORMSG_KEY]:USER_ERROR_USER_NOT_FOUND};
breakNow = true;
} else {
if ( results.items[0].isSuspended) {
response.body = {[RESULT_KEY]: false, [ERRORMSG_KEY]:USER_ERROR_USER_IS_SUSPENDED};
breakNow = true;
} else {
SITMember = results.items[0];
userid = results.items[0]._id;
memberDevices = results.items[0].memberDevices;
if ( (typeof SITMember.hasAckedMediaCompliance === 'undefined')) {
response.body = {[RESULT_KEY]:true,[RESULT_DATA_KEY]:false};
} else {
response.body = {[RESULT_KEY]:true,[RESULT_DATA_KEY]:SITMember.hasAckedMediaCompliance};
}
}
}
})
.catch( (error) => {
console.log("Got error attempting to login user: " + username + " error was: " + error);
response.body = {[RESULT_KEY]: false,[ERRORMSG_KEY] : error.message};
breakNow = true;
});
if ( breakNow ) {
return ok(response);
}
...OTHER CODE BELOW TO PROCESS RESULTS NOW HELD IN VARIABLE "SITMember"...
The variable SITMember is initialized in a single spot, otherwise the variable ‘breakNow’ is set TRUE and this function would return. Later in the method it refers to SITMember (which by definition will always be initialized with the first item in the results of the query).
Every place below this block of code that SITMember is referenced, it now has a red squiggle and the lint tooltip states “Object is possibly undefined”.
It is NOT possibly undefined. If we pass through the if (breakNow) line, then it means SITMember is initialized.
How can I turn off the lint check for a particular rule? Or for a particular method? Or for a particular line within the method?