[英]Mysterious ESLint Parsing Error
在以下代碼的第4行,ESLint給我一個解析錯誤說:
意外的令牌=
我想知道為什么會這樣? 代碼運行正常。 我究竟做錯了什么?
import { Component, PropTypes } from 'react';
export default class MainApp extends Component {
static propTypes = {
children: PropTypes.any.isRequired
}
componentWillMount() {
require('./styles/main.styl');
}
render() {
return (
<div>
{this.props.children}
</div>
);
}
}
我能夠解決這個問題:
$ npm i --save-dev babel-eslint
要么
$ yarn add babel-eslint --dev
只需在您的.eslintrc文件中添加"parser": "babel-eslint",
即可。
示例.eslintrc使用babel-eslint
和airbnb的配置以及一些自定義規則:
{
"parser": "babel-eslint",
"extends": "airbnb",
"rules": {
"arrow-body-style": "off",
"no-console": "off",
"no-continue": "off"
}
}
你不能在類中擁有屬性,只能有方法。
參考: http : //www.2ality.com/2015/02/es6-classes-final.html#inside_the_body_of_a_class_definition
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.