How can I disable lint rules on specific lines or for specific rules?

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?

The variable SITMember might possible be undefined if the query is unsuccessful. It’s best to set initialize SITMember to null before running the query. Then, if the query is unsuccessful, you avoid the possibility of accessing an undefined variable.

Note: Since you are handling the Promise returned by the query in the .then() function, it is incorrect to use the await keyword for the query. Just delete await from the line of code.

On further inspection, it appears that the “OTHER CODE BELOW”, is outside of the scope of the query’s .then() function. Therefore, SITMember is in fact undefined.

Furthermore, as I mentioned above, you need to delete the await keyword. That will result in the code at the end running before the code in the .then() function. Even if SITMember would be defined before the query. The “OTHER CODE BELOW” will run before SITMember is initialized with the result of the query.

It appears that what you need is to either: 1) delete the await keyword, and use the SITMember variable inside of the .then() function, or 2) use the await keyword, but don’t use the .then() .

For more information on Promises, see the following articles:

Yisreal -

Thanks for responding. I’m still confused by your response however:

Note: Since you are handling the Promise returned by the query in the .then() function, it is incorrect to use the await keyword for the query. Just delete await from the line of code

I do not understand why you are saying this is an incorrect use of await . Using the await keyword in this way is purposeful. At least, I am doing this on purpose based on reading the docs and reviewing examples by some of the posts by the moderators here to achieve my goals.

My goal is to publish a back-end function that can be called from my mobile app in order to validate a login against member data in my collection when the user is logging in to the app.

Therefore, the caller of this function blocks until either success or failure is returned. The use of await is to ensure that processing this function continues in a linear fashion so I know at all times whether the requester is a valid user or not and can return a failure or error condition if not.

That’s the whole purpose of using await - the query must complete fully with either an error ( breakNow is set TRUE), an empty query result ( breakNow is set TRUE) or a valid query response ( breakNow is left false and SITMember is initialized).

Therefore, when the promise is completed, it will either return from this function indicating an error in the body of the response, or it will continue on to the “OTHER CODE BELOW”, with a valid SITMember variable initialized.

According to what I read in the docs, and what I have witnessed in my testing, the “OTHER CODE BELOW” DOES NOT get executed prior to the promise being completed. Here is a screenshot for example (“login function continuing after breakNow test” occurs AFTER the query has completed):

Am I still missing something?

I do a lot of Android development and (for example) the lint mechanism within Android Studio is “smart enough” to catch this type of usage and would not flag it as an error. So it seems to me this is one of those times where it is valid to be able to suppress the lint check.

To handle a returned Promise, you either use await , which waits for the query to finish before proceeding; or you handle the returned Promise in the .then() function. It is incorrect to use both await and .then(). The articles I linked to explain in detail.

Stated another way - when you say this:

The variable SITMember might possible be undefined if the query is unsuccessful.

That is a true statement, but by using await and setting the variable breakNow to TRUE in the case of an unsuccessful query, then testing the value of that variable after the query has been completed assures that in either the case of a query error or an unsuccessful query response the function will return to the caller with a status of unsuccessful set in the response body and the code below using SITMember will never execute.

Only in the case of a successful query will the code continue to execute and at that point SITMember is initialized appropriately.

That is what this lint checker is apparently not able to surmise, which is why I want to be able to disable it.

Thanks I will review those articles.

Btw - I still don’t think you answered my original question - is it possible to disable lint checking for a function or line of code?

There’s no options to disable the lint checking. The errors and warnings are important as they point out issue with code which although it might work in Preview, it might not work in Live. The lint checking helps a lot.

The message that you are getting regarding the SITMember possibly being undefined is accurate - and it very might possibly be the case under certain circumstances.

Actually a better question would be “why is the code not flagged because it’s using both an await and .then()?” I’ll have to ask about that.

And make sure you read about await/async .

Ok - thanks for letting me know. I’m reviewing the articles you sent and will revise the code to something more like:

results = await wixData.query(SITMEMBERS_TABLE)
                .eq(EMAIL_ARG, username)
                .include(MEMBERDEVICES_FIELD)
                .find(options);
if (results.items.length === 0 ) {
 //console.log("Did not find member with email: " + username);
      response.body = {[RESULT_KEY]: false, [ERRORMSG_KEY]:USER_ERROR_USER_NOT_FOUND};
      return ok(response);
}
SITMember = results.items[0];
OTHER CODE GOES HERE

That’s more like what you would expect, correct?

For anyone reading this thread, my updated code (with lint being happy) looks like:

let results = null;
// First see if we even know about this member
try {
     results = await wixData.query(SITMEMBERS_TABLE)
                   .eq(EMAIL_ARG, username)
                   .include(MEMBERDEVICES_FIELD)
                   .find(options);
} catch (error) {
     response.body = {[RESULT_KEY]: false,[ERRORMSG_KEY] : error.message};
     return ok(response);
}
if (results.items.length === 0 ) {
    //console.log("Did not find member with email: " + username);
    response.body = {[RESULT_KEY]: false, 
           [ERRORMSG_KEY]:USER_ERROR_USER_NOT_FOUND};
    return ok(response);                        
} 
//console.log("Found member trying to log in with email: " + username);
// See if the user is suspended
if ( results.items[0].isSuspended) {
    //console.log("Found suspended member: " + memberEmail);
    response.body = {[RESULT_KEY]: false, 
        [ERRORMSG_KEY]:USER_ERROR_USER_IS_SUSPENDED};
    return ok(response);
} 
SITMember = results.items[0];
OTHER CODE REFERENCING SITMember HERE

Thanks for sharing and glad you got it worked out.

@yisrael-wix BTW I’m a huge fan of lint, it’s saved me many times for sure from committing silly errors, but I have definitely run into situations where it is helpful to suppress the warnings. I notice this is supported in other javascript lint tools (i.e. “// eslint-disable-line” is one example for eslint), which is why I asked.