表达式语句不是Javascript代码中的赋值或调用警告

时间:2017-07-12 22:59:30

标签: javascript

从Atom代码编辑器切换到PHP Storm,当我使用带有以下消息的promises时,我的很多代码都被突出显示:Expression statement is not assignment or call

以下是一些突出显示的代码示例:



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
}




我可以在代码中添加或更改哪些内容以使其正确,以便警告消失?

1 个答案:

答案 0 :(得分:2)

要禁用此特定于WebStorm的代码,请转至

WebStorm - > 偏好设置 - > 编辑 - >的检查

并取消选中 JavaScript - >下的框 JavaScript有效性问题

具有标签,“表达式语句,不是赋值或调用”。

enter image description here

如果您想实际更改代码以修复这些错误,请参阅this answer