问题描述
在ESLint 1中,我可以使用 ecmaFeatures
选项来禁用或启用某些语言功能。例如
In ESLint 1, I can use the ecmaFeatures
option to disable or enable certain language features. E.g.
ecmaFeatures:
defaultParams: false
以上配置禁用 defaultParams
。
这非常有用因为在运行时像Node一样,并非所有功能都可用,我也不想使用转换器。
This is very useful because in runtime like Node, not all features are available, and I don't want to use a transpiler.
但是在ESLint 2中,它被删除了。你只有 ecmaVersion
,即使你给它一个 ecmaVersion
,它也不会提示使用ES2015功能我认为这是有道理的,因为JavaScript解释器会抱怨在解释时使用不支持的语法,但是为浏览器开发有什么不同的ES2015支持?适用于Chrome的语法不适用于IE9。
But in ESLint 2, that was removed. You only got ecmaVersion
, which doesn't alerting on usage of ES2015 features at all even if you give it a ecmaVersion
of 5. I guess this make sense since the JavaScript interpreter will complain about the usage of unsupported syntax at interpretation time, but what about developing for browsers have different level of ES2015 support? Syntax that works for Chrome won't work for IE9.
是否有任何方法可以使用语言功能,例如:禁用解构?
推荐答案
规则禁止使用特定语法。这种语法是指AST节点的类型。 AST的规格如下:
no-restricted-syntax rule disallows specific syntax. This "syntax" is meaning the types of AST nodes. The spec of AST is here: https://github.com/estree/estree
's no-unsupported-features规则不允许特定节点版本的不支持的ECMA功能。我不知道是否存在类似的浏览器规则。
eslint-plugin-node's no-unsupported-features rule disallows unsupported ECMA features by specific Node's version. I don't know whether a similar rule for browsers exists or not.
这篇关于如何禁用ESLint 2对某些ES2015功能的使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!