javascript - Visual Studio 中的 EsLint - 无法在 javascript 文件上使用静态属性

标签 javascript ecmascript-6 babeljs eslint ecmascript-next

节点模块:

  • 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 以与命令行工具相同的方式运行的任何想法?

Visual Studio Linting Error

最佳答案

实际上在 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/

相关文章:

node.js - Heroku 找不到 `babel-core/register`

javascript - jQuery - 如何从 ajax 请求获取元素的类

javascript - 检验方程无理数

javascript - Relayjs 和 graphql 错误 : Error: "Node" expects field "id"

JavaScript - ES6 模块支持使用 babel

javascript - 如何正确配置 babel 以使用 lodash-es?

javascript - 动态具体化模态

javascript - Dojo.hitch() 范围问题

javascript - 将现有函数声明为异步?

javascript - es6类变量无法读取(无法读取未定义的属性 '...')