简体   繁体   English

eslint 2.x和babel-eslint无法识别装饰器

[英]eslint 2.x and babel-eslint Doesn't Recognize Decorators

I'm trying to upgrade to eslint 2.x and the latest version of babel-eslint . 我正在尝试升级到eslint 2.x和最新版本的babel-eslint I've been unable to get decorators or class properties to properly lint. 我一直无法正确获得装饰器或类属性。 I've created a minimal repro shown below: 我创建了如下所示的最小再现:

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 { "parser": "babel-eslint", "parserOptions": { "sourceType": "module" }, "rules": { "strict": 0 } } .eslintrc.json {“ parser”:“ babel-eslint”,“ parserOptions”:{“ sourceType”:“ module”},“ rules”:{“ strict”:0}}

When I run eslint test.js I get the following: 当我运行eslint test.js我得到以下信息:

  3:1  error  Parsing error: Unexpected character '@'

✖ 1 problem (1 error, 0 warnings)

If I comment out line 3, then I get this: 如果我注释掉第3行,则会得到以下信息:

  5:16  error  Parsing error: Unexpected token =

✖ 1 problem (1 error, 0 warnings)

It seems that babel-eslint is being used to parse the file, but isn't picking up any information from the .babelrc file. 似乎正在使用babel-eslint来解析文件,但并未从.babelrc文件中获取任何信息。

How do I go about enabling eslint and babel-eslint to successfully parse and then lint this file? 如何使eslint和babel-eslint能够成功解析然后将这个文件抹平?

This is a bug in the library. 这是库中的错误。

It is recommended to downgrade to version 2.9 . 建议降级到2.9版。

GitHub issue GitHub问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM