Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Expression statement is not assignment or call warning in Javascript code

Tags:

javascript

Switched from Atom code editor to PHP Storm, and a lot of my code is being highlighted when I use promises with the following message: Expression statement is not assignment or call

Here is an example of some highlighted code:

getTickers.bitfinex = function() {
  var counter = 0,
    promises = []

//highlighted code begins here
  new Promise(function(resolve, reject) {
      request.get({
          url: 'https://api.bitfinex.com/v1/symbols'
        },
        function(err, res, body) {
          if (err) {
            console.log(err, 'bitfinex api error')
            reject(err, 'bitfinex api error')
          }
          if (!err) {
            body = JSON.parse(body)
            var symbols = []

            body.forEach(function(symbol) {
              symbol = 't' + symbol.toUpperCase()
              symbols.push(symbol)
            })
            resolve(symbols)
          }
        })
    })
    .then((symbols) => {
      var symbolsStr = symbols.join()
      request.get({
          url: 'https://api.bitfinex.com/v2/tickers?symbols=' + symbolsStr
        },
        function(err, res, body) {
          body = JSON.parse(body)
          if (err) {
            console.log(err, 'bitfinex api error')
          }
          if (body[0] == 'error') {
            console.log(body, 'bitfinex api error')
          }
          if (body[0] !== 'error') {
            body.forEach(function(ticker) {
              var promise = new Promise(function(resolve, reject) {
                var currencyPair = ticker[0].replace("t", ""),
                  splitCurrencies = currencyPair.match(/[A-Z]{3}/g),
                  baseCurrency = splitCurrencies[0],
                  quoteCurrency = splitCurrencies[1]
                Ticker.create({
                  currency_pair: baseCurrency + '-' + quoteCurrency,
                  base_currency: baseCurrency,
                  quote_currency: quoteCurrency,
                  last: ticker[7],
                  volume: ticker[8],
                  native_currency_pair: ticker[0],
                  exchange: 'bitfinex',
                  time: new Date().getTime()
                }, function(err, document) {
                  if (err) {
                    reject(err)
                  }
                  if (document) {
                    counter++
                    resolve()
                  }
                })

              })
              promises.push(promise)
            })
            Promise.all(promises)
              .then(() => console.log(counter + ' bitfinex tickers updated'))
              .catch((err) => console.log(err, 'bitfinex update error'))
          }
        })
    })
    .catch((err) => console.log(err))
//highlight ends here
}

What can I add or change in the code to make this correct so the warning goes away?

like image 452
chuckieDub Avatar asked Sep 13 '26 09:09

chuckieDub


1 Answers

In order to disable this WebStorm-specific code inspection go to

WebStorm -> Preferences -> Editor -> Inspections

and uncheck the box under JavaScript -> JavaScript validity issues

that has the label, "expression statement which is not assignment or call".

enter image description here

If you would like to actually change your code to fix these errors, see this answer.

like image 117
Jim Avatar answered Sep 14 '26 21:09

Jim



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!