JS装饰器的ESLint意外字符'@' [英] ESLint unexpected character '@' for JS decorators

查看:712
本文介绍了JS装饰器的ESLint意外字符'@'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm trying to use decorators in my JS project, however ESLint is throwing an error stating that the @ symbol is a unexpected character.

我的代码:

@observable items = [];

我的.eslintrc:

My .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 hasn的内容还没有实现(通常是像这样的实验性功能)。从他们的自述文件中:

You probably want to use babel-eslint which uses Babel to parse things that ESLint hasn't implemented yet (usually experimental features like this). From their README:


目前,如果您使用类属性,装饰器,类型之类的东西,则将需要它。

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

它与您当前的eslint设置一起使用,您只需在 .eslintrc

It is used with your current eslint setup, you just have to update some configuration in your .eslintrc

这篇关于JS装饰器的ESLint意外字符'@'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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