为ES7指定env选项

时间:2018-05-28 07:19:26

标签: javascript eslint

要在环境中使用ES6,我必须将.eslintrc文件指定为:

"env": {
    "node": false,
    "browser": true,
    "amd": true,
    "mocha": true,
    "jasmine": false,
    "es6": true
} 

但是当我想使用ES7时,我可以这样做:

"env": {
    "node": false,
    "browser": true,
    "amd": true,
    "mocha": true,
    "jasmine": false,
    "es7": true
} 

有关信息,我查看https://eslint.org/docs/user-guide/configuring但未得到答案。

更新

我当前的文件eslint文件如下所示:

{
    "globals": {
        "com": true,
        "oData": false,
        "sakp": false,
        "fin": true,
        "cloud": true,
        "bsuite": false,
        "cordova": false,
        "ui": true,
        "webide": false,
        "asyncTest": false,
        "i2d": true,
        "gltrade": false,
        "drilldown": true,
        "opaTest": false,
        "ux": true,
        "test": false,
        "$": false,
        "module": false,
        "ai": false,
        "notEqual": false,
        "notDeepEqual": false,
        "throws": false,
        "ssuite": false,
        "deepEqual": false,
        "s2p": false,
        "Promise": false,
        "ehs": false,
        "sinon": false,
        "stop": false,
        "util": true,
        "slo": false,
        "mdm": false,
        "mytravelandexpense": false,
        "strictEqual": false,
        "cec": false,
        "cus": false,
        "notStrictEqual": false,
        "fscm": false,
        "fm": true,
        "nw": true,
        "shcm": false,
        "fcg": true,
        "URI": false,
        "fs": true,
        "retail": false,
        "d3": false,
        "hcm": false,
        "oil": true,
        "assert": false,
        "hpa": false,
        "ok": false,
        "sap": true,
        "QUnit": false,
        "cross": true,
        "srm": false,
        "equal": false,
        "expect": false,
        "jQuery": false,
        "publicservices": true,
        "uxcc": false,
        "equals": false,
        "tl": false,
        "travel": true
    },
    "env": {
        "node": false,
        "browser": true,
        "amd": true,
        "mocha": true,
        "jasmine": false,
        "es6": true
    }
}  

在哪里指定es7?

1 个答案:

答案 0 :(得分:1)

要控制允许哪种语法版本,您需要设置ecmaVersion under parserOptions

{
    "env": {
        "node": false,
        "browser": true,
        "amd": true,
        "mocha": true,
        "jasmine": false,
        "es6": true
    },
    "parserOptions": {
        "ecmaVersion": 2016
    }
}

该值可以是规范的年份或版本号(例如ECMAScript 20189版本具有相同的效果。)