![](/img/trans.png)
[英]eslint-plugin-security throws type error while linting Mongoose exec() method
[英]Is there a way to ignore test files for eslint-plugin-security?
對於 node.js 項目,我添加了 eslint-plugin-security 並且它在我的測試/規范文件(使用 mochajs)中為代碼提供了很多警告。 由於測試代碼不會在生產環境中運行,這些看起來不像在項目的實際代碼中那樣有用。 (很多通用對象注入接收器警告)
除了將/* eslint-disable */
放在每個規范文件的頂部之外,有沒有辦法讓安全插件忽略某些文件?
有三種方法可以忽略文件或文件夾:
.eslintignore
,其中包含您要忽略的內容: **/*.js
--ignore-path
指定另一個文件,您的忽略規則將位於其中eslint --ignore-path .jshintignore file.js
{
"name": "mypackage",
"version": "0.0.1",
"eslintConfig": {
"env": {
"browser": true,
"node": true
}
},
"eslintIgnore": ["*.spec.ts", "world.js"]
}
在我這邊,我遇到了 Intellij IDEA 的問題,其中 eslint 正在檢查一個專用於 Typescript (+tslint) 的文件夾中的文件,這很痛苦,所以我選擇了解決方案 3。
我發現處理此案的最佳方法是基於此答案。 您可以覆蓋子文件夾中的部分 eslint 文件。 就我而言,我從 e2e 測試文件夾中的 jest 插件中禁用了有問題的規則。 /e2e-tests/ 中的 .eslintrc.js 示例:
module.exports = {
overrides: [
{
files: ["*.spec.js"],
rules: {
"jest/valid-expect": 0
}
}
]
};
您可以將配置忽略.eslintrc中的特定文件
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.