最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

Expression statement is not assignment or call warning in Javascript code - Stack Overflow

programmeradmin1浏览0评论

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: ''
        },
        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: '=' + 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
}

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./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./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?

Share Improve this question edited Jul 13, 2017 at 0:18 chuckieDub asked Jul 12, 2017 at 22:59 chuckieDubchuckieDub 1,8459 gold badges30 silver badges47 bronze badges 4
  • Can you show us the plete highlighted code, please? Especially beginning and end. The parts you've shown are assignments or calls. – Bergi Commented Jul 12, 2017 at 23:30
  • Are you sure there are no syntax errors? Maybe your editor is confused because of the omitted semicolons. – Bergi Commented Jul 12, 2017 at 23:31
  • @Bergi Actually that was the plete highlighted portion, but when I removed the only semicolon in the code, the highlighted section became much bigger. Will update now – chuckieDub Commented Jul 13, 2017 at 0:15
  • You should report it as a bug, the code is fine. My guess is it has to do with the call expression starting with a new. – Bergi Commented Jul 13, 2017 at 1:35
Add a ment  | 

1 Answer 1

Reset to default 3

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".

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

发布评论

评论列表(0)

  1. 暂无评论