jeudi 29 novembre 2018

Webstorm suggesting I flip if-else, what are the benefits of doing so?

I've seen this happen a few times in Webstorm. Here's an example of a time when it happens. I have a module for logging messages sent to a chatbot and the responses. The log() function looks like this:

log: function(senderID, type, event) {
    if (type === 1) {
        // Event
        logDate = datetime.parseUnixDBDate(event.timestamp);
        logTime = datetime.parseUnixTime(event.timestamp);
        logText = handleText(event.message.text);
        table = "interactions";
        columns = ["fbid", "date", "time", "event"];
        logType = "User input";
    } else {
        // Response
        logDate = datetime.getDBDate();
        logTime = datetime.getTime();
        logText = handleText(event);
        table = "interaction_responses";
        columns = ["fbid", "date", "time", "response"];
        logType = "Chatbot response";
    }
    values = [`'${senderID}'`, `'${logDate}'`, `'${logTime}'`, `'${logText}'`];
    logSQL = `INSERT INTO ${table} (${columns.toString()}) VALUES (${values.toString()})`;
    database.query(logSQL);
    console.log("%s '%s' logged at %s on %s.", logType, logText, logTime, logDate);
}

In Webstorm, I get a little lightbulb next to the if statement, and if I click the warning it suggests that I should "Flip if-else". If I do this, I then get the SAME warning suggesting I flip the if-else back. Warning looks like this:

Webstorm Warning Message

Is there a reason why this is happening? Should I flip my if-else statement?

Aucun commentaire:

Enregistrer un commentaire