gpt4 book ai didi

javascript - 如何使用 eslint 禁止使用 'concise methods'

转载 作者:行者123 更新时间:2023-11-28 06:02:37 24 4
gpt4 key购买 nike

检查下面的示例代码

var Syntax = {

/* eslint should throw error for this */
concise () {
console.log("Concise syntax (es6). No 'function' keyword.");
},

normal: function () {
console.log("Normal syntax.");
}

};
  • 已尝试在 .eslintrc 配置中将 es6 环境设置为 false 并将 ecmaParser 选项设置为 5。仍然没有抛出任何错误
  • 已阅读所有可用的 eslint 规则。没有匹配的。
  • 我使用 babel-eslint 作为解析器

最佳答案

有这个eslint插件:https://www.npmjs.com/package/eslint-plugin-no-inferred-method-name

看来是按照你说的做的。如果您定义以下内容,它会抛出错误:

{
concise () { ... }
}

但如果您这样做,则不会抛出错误:

{
normal: function() { ... }
}

要首先安装使用它:

$ npm install -g eslint-plugin-no-inferred-method-name

并添加:

"plugins": [
"no-inferred-method-name"
],

到你的 eslint 文件。

关于javascript - 如何使用 eslint 禁止使用 'concise methods',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37156315/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com