【发布时间】:2017-09-25 20:48:19
【问题描述】:
错误:
3:5 error 'global' is not defined no-undef
我当前的 ESLint 配置:
module.exports = {
parser: "babel-eslint",
env: {
browser: true,
es6: true,
"jest/globals": true,
jest: true
},
extends: ["eslint:recommended", "plugin:react/recommended", "prettier", "prettier/react"],
parserOptions: {
ecmaFeatures: {
experimentalObjectRestSpread: true,
jsx: true
},
sourceType: "module"
},
globals: {
testGlobal: true
},
plugins: ["react", "prettier", "jest"],
rules: {
"prettier/prettier": 1,
"no-console": 0
}
};
导致 ESLint 错误的简化示例测试文件:
describe("Jest global:", () => {
it("should not cause ESLint error", () => {
global.testGlobal = {
hasProp: true
};
});
});
我希望通过在 eslint 配置中添加 env: { jest: true } 来涵盖这个 Jest 功能。我当然可以禁用文件中的规则或行,但是每次使用global 时我都需要这样做。
【问题讨论】:
-
追踪到 ESLint 的全局依赖 github.com/sindresorhus/globals/blob/… 似乎它没有全局...我猜它应该。
-
向 globals 项目提交了问题:github.com/sindresorhus/globals/issues/118 之后我想向 ESLint 团队提交问题
标签: javascript node.js unit-testing jestjs eslint