如何禁止使用'简明方法'使用esint

How to disallow usage of 'concise methods' using eslint

本文关键字:方法 esint 使用 何禁止 禁止      更新时间:2023-09-26

检查下面的示例代码

var Syntax = {
  /* eslint should throw error for this */
  concise () {
    console.log("Concise syntax (es6). No 'function' keyword.");
  },
  normal: function () {
    console.log("Normal syntax.");
  }
};
  • 尝试将CCD_ 1环境设置为CCD_;在.eslintrc配置中将ecmaParser选项设置为5。仍然没有抛出任何错误
  • 已经浏览了所有可用的esint规则。无匹配
  • 我使用babel esint作为解析器

有一个esint插件: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"
],

到您的esint文件。