简体   繁体   中英

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 . 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 } }

When I run eslint test.js I get the following:

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

✖ 1 problem (1 error, 0 warnings)

If I comment out line 3, then I get this:

  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.

How do I go about enabling eslint and babel-eslint to successfully parse and then lint this file?

This is a bug in the library.

It is recommended to downgrade to version 2.9 .

GitHub issue

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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