簡體   English   中英

有沒有辦法忽略 eslint-plugin-security 的測試文件?

[英]Is there a way to ignore test files for eslint-plugin-security?

對於 node.js 項目,我添加了 eslint-plugin-security 並且它在我的測試/規范文件(使用 mochajs)中為代碼提供了很多警告。 由於測試代碼不會在生產環境中運行,這些看起來不像在項目的實際代碼中那樣有用。 (很多通用對象注入接收器警告)

除了將/* eslint-disable */放在每個規范文件的頂部之外,有沒有辦法讓安全插件忽略某些文件?

有三種方法可以忽略文件或文件夾:

1. 在您的項目根文件夾上創建一個.eslintignore ,其中包含您要忽略的內容:

**/*.js

2. 使用 eslint cli 和--ignore-path指定另一個文件,您的忽略規則將位於其中

eslint --ignore-path .jshintignore file.js

3. 使用你的 package.json

{
  "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中的特定文件

https://eslint.org/docs/user-guide/configuring

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM