javascript - Eslint,如何在Javascript中接受const和箭头函数?

标签 javascript eslint

这可能就在附近,但我就是找不到答案。

下面是我的 eslint 配置文件,但它不接受 const 和箭头函数。如何更改这些设置以接受这些设置? eslint 的替代品也很受欢迎。

{
    "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 文档:

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 - enable arrow functions

binaryLiterals - enable binary literals

blockBindings - enable let and const (aka block bindings)

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

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

esLint有很多例子

希望对你有帮助

关于javascript - Eslint,如何在Javascript中接受const和箭头函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36450139/

相关文章:

atom-editor - Nuclide自动修复所有错误

javascript - 如何检测何时显示 div(图像 slider )中的第 n 个图像

javascript - Ramda.js:要列出的参数

php - 在表单验证期间设置选择元素值的替代方法?

javascript - 如何从 Cloud Firestore 获取查询结果作为对象?

javascript - 检查 undefined variable 与错误变量

javascript - .eslintrc.js 键带有 "-"(破折号)

typescript - 如何正确处理 Vuejs 中异步事件监听器中的拒绝错误?

javascript - 元素的绑定(bind)值

javascript - 当 "Unexpected tab character"规则设置为 "indent"时,ESLint "tab"