简体   繁体   English

如何使用eslint禁止使用“简明方法”

[英]How to disallow usage of 'concise methods' using eslint

Check this sample code below 请查看下面的示例代码

var Syntax = {

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

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

};
  • Have tried setting es6 environment to false & ecmaParser option to 5 in .eslintrc config. 尝试在.eslintrc配置es6环境设置为falseecmaParser选项为5 Still not throwing any errors 仍然没有抛出任何错误
  • Have went through all eslint rules available. 已经完成了所有可用的eslint规则。 None matching. 没有匹配。
  • I use babel-eslint as parser 我使用babel-eslint作为解析器

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

It seems to do what you said. 它似乎做你说的。 It claims to throw an error if you define: 如果您定义:它声称抛出错误:

{
    concise () { ... }
}

But will not throw an error if you did: 但如果你这样做,不会抛出错误:

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

To use it first install: 要先使用它安装:

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

and add: 并添加:

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

to your eslint file. 到你的eslint文件。

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

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