简体   繁体   English

Eslint无法识别破坏

[英]Eslint not recognising destructing

My Eslint is not recognising that the below is valid code 我的Eslint无法识别以下有效代码

const chai, { expect } = require('chai');

Can you please help me figure out which rule I need to add? 您能帮我找出我需要添加的规则吗?

That's not an ESLint error, that's a pure syntax error. 这不是ESLint错误,而是纯语法错误。 What you have in your example translates to: 您的示例中的内容转换为:

const chai;
const { expect } = require('chai');

As you can see a bit more clearly, you're essentially defining an uninitialized constant that can never be reassigned. 正如您可以更清楚地看到的那样,您实际上是在定义一个永远不能重新分配的未初始化常量。 Even the Node REPL will throw an error on that. 甚至Node REPL也会对此抛出错误。 Try the following snippet to see the error in action: 尝试以下代码片段查看错误信息:

 const chai; 

If what you want is just the expect method from chai, then all you need is 如果你想要的仅仅expect从薛宝钗方法,那么你需要的是

const { expect } = require('chai');

If you need all of chai and expect an alternative is 如果您需要所有的柴,并且期望替代方案是

const chai = require('chai');
const { expect } = chai;

This would allow you to call expect(actual).to.be.an('object'); 这将使您可以调用expect(actual).to.be.an('object'); or chai.expect(actual).to.be.an('object'); chai.expect(actual).to.be.an('object');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM