2016-05-17 45 views
1

我試圖升級到eslint 2.x和最新版本babel-eslint。我一直無法得到裝飾或類屬性正確的皮棉。我創建瞭如下圖所示的最小攝製:eslint 2.x和babel-eslint無法識別裝飾器

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 { 「分析器」:「巴BEL-eslint」, 「parserOptions」:{ 「sourceType的」: 「模塊」 }, 「規則」:{ 「嚴格」: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) 

看來,巴貝爾,eslint是貝ng用於解析文件,但不從.babelrc文件中獲取任何信息。

我該如何去啓用eslint和babel-eslint來成功解析然後將這個文件粘上去?

回答

2

這是庫中的一個錯誤。

建議降級到2.9版本。

GitHub issue

+1

謝謝!這工作! –

+2

無需降級,這已在2.10.2 AFAIK中修復。 – loganfsmyth