javascript - JS 装饰器的 ESLint 意外字符 '@'

标签 javascript eslint ecmascript-next

我试图在我的 JS 项目中使用装饰器,但是 ESLint 抛出一个错误,指出 @ 符号是一个意外的字符。

我的代码:

@observable items = [];

我的.eslintrc:

{
    "parserOptions": {
            "ecmaVersion": 6,
            "ecmaFeatures": {
                "jsx": true
            },
            "sourceType": "module"
    },
    "env": {
            "browser": true,
            "node": true,
            "es6": false
    },
    "ecmaFeatures": {
            "modules": true
    },
    "rules": {
        "strict": [
            2,
            "global"
        ],
        "quotes": [
            2,
            "single"
        ],
        "indent": [
            2,
            4
        ],
        "eqeqeq": [
            2,
            "smart"
        ],
        "semi": [
            2,
            "always"
        ],
        "max-depth": [
            2,
            4
        ],
        "max-statements": [
            2,
            15
        ],
        "complexity": [
            2,
            5
        ]
    }
}

最佳答案

您可能想使用 babel-eslint它使用 Babel 来解析 ESLint 尚未实现的东西(通常是像这样的实验性功能)。来自他们的自述文件:

At the moment, you'll need it if you use stuff like class properties, decorators, types.

您当前的 eslint 设置一起使用,您只需更新 .eslintrc

中的一些配置

关于javascript - JS 装饰器的 ESLint 意外字符 '@',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40678196/

相关文章:

javascript - 如何让 ESLint 对 VSCode 中的 HTML 文件进行 lint?

javascript - typescript |关于缺少函数返回类型的警告,ESLint

javascript - 从代码库中删除 TypeScript 类型注释和断言

javascript - Webpack 显示错误的 eslint linting 错误

javascript - ES6 类属性定义

javascript - TypeError : Object. 条目不是函数

javascript - 如何在javascript中提交查询请求并将其存储在变量中?

JavaScript,访问json属性

php - 新 jQuery 版本的 css + jQuery style.css 切换器

javascript - Service Worker 的范围是多少?