Eslint,如何在Javascript中接受const和箭头函数? [英] Eslint, how to accept const and arrow function in Javascript?

查看:158
本文介绍了Eslint,如何在Javascript中接受const和箭头函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能在某处,但我找不到答案。

This is probably somewhere around, but I simply can not find the answer.

下面是我的eslint配置文件,但它不接受常量和箭头功能。如何更改这些设置以接受这些设置?也欢迎使用eslint的替代方案。

Below is my eslint config file, but it doesn't accept const and arrow functions. How to change these settings to accept those? An alternative to eslint is welcome too.

{
    "ecmaFeatures": {
        "jsx": true,
        "arrowFunctions": true,
        "blockBindings": true,
        "defaultParams": true,
        "destructuring": true,
        "forOf": true,
        "generators": true,
        "objectLiteralComputedProperties": true,
        "objectLiteralShorthandMethods": true,
        "objectLiteralShorthandProperties": true,
        "restParams": true,
        "spread": true,
        "templateStrings": true,
        "modules": true,
        "classes": true
    },
    "env": {
        "browser": true,
        "jasmine": true,
        "node": true
    },
    "rules": {
        "brace-style": 2,
        "camelcase": 2,
        "comma-dangle": [2, "never"],
        "comma-spacing": [2, {
            "before": false,
            "after": true
        }],
        "comma-style": [2, "last"],
        "complexity": [1, 8],
        "consistent-this": [2, "_this"],
        "curly": 2,
        "default-case": 2,
        "dot-notation": 2,
        "eol-last": 2,
        "eqeqeq": 2,
        "guard-for-in": 1,
        "indent": [2, 2, {
            "SwitchCase": 1
        }],
        "key-spacing": [2, {
            "beforeColon": false,
            "afterColon": true
        }],
        "new-cap": 2,
        "new-parens": 2,
        "no-caller": 2,
        "no-debugger": 1,
        "no-dupe-args": 2,
        "no-dupe-keys": 2,
        "no-duplicate-case": 2,
        "no-eq-null": 0,
        "no-eval": 2,
        "no-implied-eval": 2,
        "no-invalid-regexp": 2,
        "no-mixed-spaces-and-tabs": 2,
        "no-redeclare": 2,
        "quote-props": [2, "consistent-as-needed"],
        "no-self-compare": 1,
        "no-shadow-restricted-names": 2,
        "no-trailing-spaces": 2,
        "no-undef": 2,
        "no-undef-init": 2,
        "no-underscore-dangle": 0,
        "no-unreachable": 2,
        "no-unused-vars": 1,
        "no-use-before-define": 2,
        "no-with": 2,
        "one-var": [2, "never"],
        "operator-assignment": [2, "always"],
        "quotes": [2, "single"],
        "radix": 2,
        "semi": [2, "always"],
        "semi-spacing": [2, {
            "before": false,
            "after": true
        }],
        "sort-vars": [1, {
            "ignoreCase": true
        }],
        "space-after-keywords": [2, "always"],
        "space-before-function-paren": [2, {
            "anonymous": "always",
            "named": "never"
        }],
        "space-in-parens": [2, "never"],
        "space-infix-ops": 2,
        "space-unary-ops": [2, {
            "words": true,
            "nonwords": false
        }],
        "strict": [2, "global"],
        "use-isnan": 2,
        "valid-jsdoc": 1,
        "yoda": [2, "never", {
            "exceptRange": false
        }]
    }
}


推荐答案

来自eslint docs:

From eslint docs:


要解决的问题:如果您在
ecmaFeatures中使用任何ECMAScript 6功能标志,则需要使用ecmaVersion:6。
ECMAScript 6功能标志是:

To address: If you are using any ECMAScript 6 feature flags in ecmaFeatures, you’ll need to use ecmaVersion: 6 instead. The ECMAScript 6 feature flags are:

arrowFunctions - 启用箭头功能

arrowFunctions - enable arrow functions

binaryLiterals - 启用二进制literals

binaryLiterals - enable binary literals

blockBindings - 启用let和const(也就是块绑定)

blockBindings - enable let and const (aka block bindings)



// In your .eslintrc
{
    env: {
        es6: true
    }
}

// Or in a configuration comment
/*eslint-env es6*/

esLint 有很多例子

esLint there are a lot of examples

希望它能帮到你

这篇关于Eslint,如何在Javascript中接受const和箭头函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆