我试图在我的 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/