我正在使用一个框架("hardhat"(,它自动需要一个包("others"(,但esint一直以未定义的方式调用它。要求"醚"并不是一个解决方案,因为它只会破坏一切;但据我所知,向整个文档添加异常的一种方法是在整个文档上方的注释块中放置覆盖。
/*
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
...
我怀疑解决方案是添加另一个esint禁用规则,但我不知道如何用它来针对"ethers"包。有人有解决方案吗?
更新:通过添加const { ethers } = require("hardhat");
修复
看看ESLint全局变量。基本上,您可以在ESLint配置中声明一个全局值ethers
,该值将被视为在所有linted文件中定义的值。
对于ESLint>=7,如果您的配置文件是.eslintrc,请添加一个条目,如:
{
"globals": {
"ethers": "readonly"
}
}
对于ESLint<7,请改用"ethers": false
。