简体   繁体   English

eslint-plugin-security 在 linting Mongoose exec() 方法时抛出类型错误

[英]eslint-plugin-security throws type error while linting Mongoose exec() method

I'm using Nodejs , Eslint ^7 and Mongoose ^5 .我正在使用NodejsEslint ^7Mongoose ^5 I have added eslint-plugin-security ^1 recommended rules to my .eslintrc.js as below :我已将eslint-plugin-security ^1推荐规则添加到我的.eslintrc.js 中,如下所示:

parserOptions: {
  ecmaVersion: 2021,
},

env: {
  commonjs: true,
  es6: true,
  browser: false,
  node: true,
},

plugins: ['security'],

extends: [
  'plugin:security/recommended',
],

When I run eslint, I get the below TypeError :当我运行 eslint 时,我得到以下 TypeError :

Oops! Something went wrong! :(

ESLint: 7.30.0

TypeError: Cannot read property 'type' of undefined
Occurred while linting /app/api/src/Repository/AppLog.js:38
    at MemberExpression (/app/api/node_modules/eslint-plugin-security/rules/detect-child-process.js:34:87)
    at /app/api/node_modules/eslint/lib/linter/safe-emitter.js:45:58
    at Array.forEach (<anonymous>)
    at Object.emit (/app/api/node_modules/eslint/lib/linter/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (/app/api/node_modules/eslint/lib/linter/node-event-generator.js:293:26)
    at NodeEventGenerator.applySelectors (/app/api/node_modules/eslint/lib/linter/node-event-generator.js:322:22)
    at NodeEventGenerator.enterNode (/app/api/node_modules/eslint/lib/linter/node-event-generator.js:336:14)
    at CodePathAnalyzer.enterNode (/app/api/node_modules/eslint/lib/linter/code-path-analysis/code-path-analyzer.js:711:23)
    at /app/api/node_modules/eslint/lib/linter/linter.js:960:32
    at Array.forEach (<anonymous>)

I checked the line that the error points to, But I didn't find any problem with that.我检查了错误指向的行,但我没有发现任何问题。

Here is my code on /app/api/src/Repository/AppLog.js:38 :这是我在/app/api/src/Repository/AppLog.js:38代码:

async list() {
  return this.LogModel.find().exec();
}

everything works fine when I remove the eslint-plugin-security plugin.当我删除eslint-plugin-security插件时,一切正常。 I guess there is a problem with the library itself.我猜图书馆本身有问题。

Any idea for solve this problem ?解决这个问题的任何想法?

It is my problem too.也是我的问题。 I have also created an issue for that on its repository,我还在存储库中为此创建了一个问题

The error occurs when eslint faces any Query.prototype.exec() in the code that is namesake with child_process.exec() method of Node.js.当 eslint 在与 Node.js 的child_process.exec()方法同名的代码中遇到任何Query.prototype.exec()时,就会发生错误。

There is a possible solution to this problem which I have described here , But it's still open and I have no other idea how to fix it another and/or better way.我在这里描述了这个问题的可能解决方案,但它仍然是开放的,我不知道如何以另一种和/或更好的方式解决它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM