no-useless-computed-key (Rules) – Eslint 中文开发手册

[
  •   Eslint 中文开发手册

    no-useless-computed-key (Rules) - Eslint 中文开发手册

    在--fix命令行上的选项可以自动修复一些被这条规则反映的问题。

    没有必要使用带文字的计算属性,例如:

    var foo = {["a"]: "b"};

    该代码可以被重写为:

    var foo = {"a": "b"};

    规则细节

    此规则禁止不必要地使用计算属性键。

    例子

    此规则的错误代码示例:

    /*eslint no-useless-computed-key: "error"*/
    /*eslint-env es6*/
    
    var a = { ['0']: 0 };
    var a = { ['0+1,234']: 0 };
    var a = { [0]: 0 };
    var a = { ['x']: 0 };
    var a = { ['x']() {} };

    此规则的正确代码示例:

    /*eslint no-useless-computed-key: "error"*/
    
    var c = { 'a': 0 };
    var c = { 0: 0 };
    var a = { x() {} };
    var c = { a: 0 };
    var c = { '0+1,234': 0 };

    何时不使用它

    如果您不希望收到不必要的计算属性密钥的通知,则可以安全地禁用此规则。

    版本

    该规则在 ESLint 2.9.0中引入。

    资源

    Rule sourceDocumentation source

  •   Eslint 中文开发手册
    ]
    转载请保留页面地址:https://www.breakyizhan.com/javascript/34488.html
    原文地址:https://www.cnblogs.com/breakyizhan/p/13272149.html