Search code examples
node.jsjslintjshintredisclient

JSHint gives Expected an identifier and instead saw a function


I have declared a function which queries Redis and if data is not found in redis then queries the SQL database. Following is my code, it gives an error in the first line itself. I am not sure why the function as an argument is causing the trouble.

function redusId(taskId, function (err, reply){
var status = taskId + ".status";
var response = taskId + ".response";
var jsonObject = {};

redisClient.get(status, function (error, reply) {
    if (error) {
        console.log("redis.status.ERROR: " + error);
        return;
    }

    if (!reply) {
        checkSQLdb(taskId, function (error, data) {
            if(error) {
                console.log("sql.ERROR", error);
            }

            if(!data) {
                console.log("sql.status.ERROR");
            }
            else {
                // data retrieval and posting in redis and calling redis client again
                var id = data[0].id;
                var status = data[0].status;
                var response = data[0].response;
                console.log(id, status, response);
                var requestid = id + ".status";
                redisClient.set(requestid, status);
                requestid = id + ".response";
                redisClient.set(requestid, response);
                redusId(id);
            }
        })
      }
    else {
        jsonObject."status" = reply;

        if (reply == 1) {
                //redis returns non one status no response is expected
                redisClient.get(response, function(error, reply) {
                    if (error) {
                        //redis has the status but not the response
                        console.log("redis.response.ERROR ", error);
                    }
                    else {
                        jsonObject."response" = response;
                        return jsonObject;
                    }
                });
             }
             else {
                console.log("status is not one ; no response is expected");
                return jsonObject;
             }
        }
    })
});

Solution

  • This was pointed out in the comments and no one posted is as an answer hence posting, now.

    The problem in the code snippet was I was trying to declaring the function and also passing it as an argument. In the given code snippet, the correct way to do

        function redusId(taskId,callback){...}
    

    and then call it as

        redusId(1, function(){...});