簡體   English   中英

如何為特定的 package 導入禁用 eslint 'no-undef'?

[英]How to disable eslint 'no-undef' for a specific package import?

我正在使用一個自動需要 package('ethers')的框架('hardhat'),但 eslint 一直將其稱為未定義。 要求“以太幣”不是解決方案,因為它只會破壞一切; 但據我所知,向整個文檔添加例外的一種方法是將覆蓋放在整個文檔上方的注釋塊中。

 /*
    eslint-disable jest/valid-expect
 */ 
const { expect } = require("chai");
const { txHist } = require("../scripts/utils.js");

describe("DStor", () => {
    let DStor;
    let deployer, user1, user2, user3, users; // eslint-disable-line no-unused-vars

    beforeEach(async () => {
        // Get ContractFactory and Signers
        const DStorFactory = await ethers.getContractFactory("DStor"); // 'ethers' is highlighted with no-undef
...

我懷疑解決方案是添加另一個 eslint-disable 規則,但我不知道如何使用它來定位“ethers”package。 任何人有任何解決方案?

更新:通過添加const { ethers } = require("hardhat");修復

看看ESLint globals 基本上,您可以在 ESLint 配置中聲明一個全局值ethers ,這將被視為在所有 linted 文件中定義。

對於 ESLint >= 7,如果您的配置文件是 .eslintrc,請添加如下條目:

{
    "globals": {
        "ethers": "readonly"
    }
}

對於 ESLint < 7,請改用"ethers": false

暫無
暫無

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

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