首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何用ESlint修复我的Node.js语法?

如何用ESlint修复我的Node.js语法?
EN

Stack Overflow用户
提问于 2020-05-01 18:36:37
回答 1查看 82关注 0票数 0

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

代码语言:javascript
复制
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!!!',
        })
    }
  }
}   
})

当我跑的时候

代码语言:javascript
复制
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

输出为

代码语言:javascript
复制
<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)

如何获取更多信息?如何自动修复语法?我正在添加我的.eslinter.json

代码语言:javascript
复制
{
    "env": {
        "browser": true,
        "es6": true
    },
    "extends": [
        "plugin:react/recommended",
        "standard"
    ],
    "globals": {
        "Atomics": "readonly",
        "SharedArrayBuffer": "readonly"
    },
    "parserOptions": {
        "ecmaFeatures": {
            "jsx": true
        },
        "ecmaVersion": 2018,
        "sourceType": "module"
    },
    "plugins": [
        "react"
    ],
    "rules": {
    }
}
EN

回答 1

Stack Overflow用户

发布于 2020-05-01 18:44:17

我认为你应该在打开catch之前关闭你的insert函数

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61540841

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档