我正在尝试升级到eslint
2.x和最新版本的babel-eslint
。我一直无法获得正确lint的装饰器或类属性。我创建了一个如下所示的最小重复:
test.js
import {decorator} from 'foo';
@decorator('test')
export class Test {
testProperty = 'a string';
}
package.json
{
"name": "test",
"version": "1.0.0",
"description": "",
"main": "test.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"devDependencies": {
"babel": "^6.5.2",
"babel-eslint": "^6.0.4",
"babel-plugin-transform-decorators-legacy": "^1.3.4",
"babel-preset-es2017": "^1.4.0",
"babel-preset-stage-1": "^6.5.0",
"eslint": "^2.10.1"
}
}
.babelrc
{
"presets": ["es2017", "stage-1"],
"plugins": ["transform-decorators-legacy"]
}
.eslintrc.json
{
“解析器”:“babel-eslint”,
“parserOptions”:{
“sourceType”:“module”
},
“规则”:{
“严格”:0
}
}
当我运行eslint test.js
时,我得到以下内容:
3:1 error Parsing error: Unexpected character '@'
✖ 1 problem (1 error, 0 warnings)
如果我评论第3行,那么我明白了:
5:16 error Parsing error: Unexpected token =
✖ 1 problem (1 error, 0 warnings)
似乎正在使用babel-eslint来解析文件,但是没有从.babelrc
文件中获取任何信息。
如何启用eslint和babel-eslint以成功解析然后lint此文件?