如何使用ESlint修复Node.js语法?

问题描述 投票:0回答:1

我添加了几行代码来检查我的REST API(POST方法)中的错误。第39-60行

app.post('/collections/:collectionName', (req, res, next) => {
    pino(req,res);
    req.log.info('pino output');
    try {
      req.collection.insert(req.body, {}, (e, results) => {
        if (e) return next(e)
        res.send(results.ops)     
    } catch (err) {
      if (err instanceof CustomError) {
        return res.status(err.status).send({
            error: err.code,
            description: err.message,
        }) else {
          console.error(err);
          return res.status(500).send({
            error: 'GENERIC',
            description: 'Something went wrong!!!',
        })
    }
  }
}   
})

我跑步时

eslint --fix index.js

/home/miki/restwitherrors/index.js
  46:7  error  Parsing error: Unexpected token catch

✖ 1 problem (1 error, 0 warnings)

如果我尝试使用VSCode ,Shift+ALt+.并选择Fix all detected spelling errors

输出是

<semantic> TypeScript Server Error (3.8.3)
Cannot read property 'groups' of null
TypeError: Cannot read property 'groups' of null
    at DiagnosticIDDecorator.UndecorateFix (/home/miki/.vscode/extensions/manuth.eslint-language-service-1.0.1/node_modules/typescript-eslint-plugin/lib/Diagnostics/DiagnosticIDDecorator.js:65:92)
    at DiagnosticIDDecorator.UndecorateCombinedFix (/home/miki/.vscode

/extensions/manuth.eslint-language-service-1.0.1/node_modules/typescript-eslint-plugin/lib/Diagnostics/DiagnosticIDDecorator.js:75:109)
    at /home/miki/.vscode/extensions/manuth.eslint-language-service-1.0.1/node_modules/typescript-eslint-plugin/lib/Plugin.js:397:45
    at Proxy.<anonymous> (/home/miki/.vscode/extensions/manuth.eslint-language-service-1.0.1/node_modules/typescript-eslint-plugin/lib/Interception/Interceptor.js:100:34)
    at IOSession.Session.getCombinedCodeFix (tsserver.js:145760:56)
    at Session.handlers.ts.createMapFromTemplate._a.<computed> (tsserver.js:144516:61)
    at tsserver.js:146003:88
    at IOSession.Session.executeWithRequestId (tsserver.js:145994:28)
    at IOSession.Session.executeCommand (tsserver.js:146003:33)
    at IOSession.Session.onMessage (tsserver.js:146027:35)
    at Interface.<anonymous> (tsserver.js:147342:27)
    at Interface.emit (events.js:203:13)
    at Interface._onLine (readline.js:316:10)
    at Interface._normalWrite (readline.js:461:12)
    at Socket.ondata (readline.js:172:10)
    at Socket.emit (events.js:203:13)
    at addChunk (_stream_readable.js:295:12)
    at readableAddChunk (_stream_readable.js:276:11)
    at Socket.Readable.push (_stream_readable.js:210:10)
    at Pipe.onStreamRead (internal/stream_base_commons.js:166:17)

如何获取更多信息?如何自动修复语法?

node.js eslint vscode-settings
1个回答
0
投票

我认为您应该先打开功能insert,然后再打开catch

© www.soinside.com 2019 - 2024. All rights reserved.