如何为特定的包导入禁用 eslint 'no-undef'?
How to disable eslint 'no-undef' for a specific package import?
我正在使用一个框架 ('hardhat'),它自动需要一个包 ('ethers'),但 eslint 一直将其称为未定义。要求 'ethers' 不是解决方案,因为它只会破坏一切;但据我所知,向整个文档添加例外的一种方法是将覆盖放在整个文档上方的注释块中。
/*
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' 包。谁有解决办法?
更新:通过添加 const { ethers } = require("hardhat");
修复
看看ESLint globals。基本上,您可以在 ESLint 配置中声明一个全局值 ethers
,这将被视为在所有 linted 文件中定义。
对于 ESLint >= 7,如果您的配置文件是 .eslintrc,请添加如下条目:
{
"globals": {
"ethers": "readonly"
}
}
对于 ESLint < 7,请改用 "ethers": false
。
我正在使用一个框架 ('hardhat'),它自动需要一个包 ('ethers'),但 eslint 一直将其称为未定义。要求 'ethers' 不是解决方案,因为它只会破坏一切;但据我所知,向整个文档添加例外的一种方法是将覆盖放在整个文档上方的注释块中。
/*
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' 包。谁有解决办法?
更新:通过添加 const { ethers } = require("hardhat");
看看ESLint globals。基本上,您可以在 ESLint 配置中声明一个全局值 ethers
,这将被视为在所有 linted 文件中定义。
对于 ESLint >= 7,如果您的配置文件是 .eslintrc,请添加如下条目:
{
"globals": {
"ethers": "readonly"
}
}
对于 ESLint < 7,请改用 "ethers": false
。