节点模块:
- EsLint 1.10.3
- Babel-EsLint 4.1.6
- Eslint-plugin-react 3.15.0
正在检查的示例文件:
class NotepadComponent extends React.Component {
static displayName = 'NotepadComponent'
static defaultProps = {
activeTab: 'type'
}
}
在命令行下,我可以毫无问题地使用 babel 进行 lint 和转译。问题是试图从 visual studio 进行 lint。我正在使用 Web Analyzer plugin内部使用 esLint。
这个 visual studio 模块在 C:\Users\My-Username
下定义了一个 .eslintrc
文件,我已经更新了这个文件和主文件夹对于使用此配置的 node_modules:
"parser": "babel-eslint",
"ecmaFeatures": {
"jsx": true,
"classes": true
},
"plugins": [
"react"
],
"env": {
"browser": true,
"node": true,
"es6": true,
"jquery": true
},
但我仍然得到“JSX Parser: Unexpected Token ="error:
关于让 Web Analyzer 以与命令行工具相同的方式运行的任何想法?
最佳答案
实际上在 Es6 中,对于 defaultProps,你必须在类之外设置它,例如:
class NotepadComponent extends React.Component {
constructor(props){
super(props);
}
}
NotepadComponent.defaultProps ={
activeTab:'type'
}
NotepadComponent.displayName = 'NotepadComponent'
我不确定是不是你要找的,但也许这对你有帮助
关于javascript - Visual Studio 中的 EsLint - 无法在 javascript 文件上使用静态属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34916112/