I'm attempting to use the ESLint linter with the Jest testing framework.
(我正在尝试将ESLint linter与Jest测试框架一起使用。)
Jest tests run with some globals like jest
, which I'll need to tell the linter about;
(玩笑测试与诸如jest
类的一些全局变量一起运行,我需要告诉短绒猫有关;)
but the tricky thing is the directory structure, with Jest the tests are embedded with the source code in __tests__
folders, so the directory structure looks something like:(但是棘手的是目录结构,使用Jest,测试将源代码嵌入到__tests__
文件夹中,因此目录结构类似于:)
src
foo
foo.js
__tests__
fooTest.js
bar
bar.js
__tests__
barTest.js
Normally, I'd have all my tests under a single dir, and I could just add an .eslintrc
file there to add the globals... but I certainly don't want to add a .eslintrc
file to every single __test__
dir.
(通常,我会将所有测试放在单个目录下,并且可以在其中添加.eslintrc
文件以添加全局变量...,但是我当然不想在每个__test__
目录中都添加.eslintrc
文件。)
For now, I've just added the test globals to the global .eslintrc
file, but since that means I could now reference jest
in non-testing code, that doesn't seem like the "right" solution.
(现在,我只是将测试全局变量添加到全局.eslintrc
文件中,但是由于这意味着我现在可以在非测试代码中引用jest
,因此,这似乎不是“正确的”解决方案。)
Is there a way to get eslint to apply rules based on some pattern based on the directory name, or something like that?
(有没有办法让eslint根据基于目录名称的某种模式来应用规则,或者类似的方法?)
ask by Retsam translate from so
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…