2016-01-21 37 views
3

节点模块使用静态道具:EsLint - 无法在JavaScript文件

  • EsLint 1.10.3
  • 巴贝尔-EsLint 4.1.6
  • Eslint-插件反应的3.15.0

示例文件被LINTED:

class NotepadComponent extends React.Component { 
    static displayName = 'NotepadComponent' 

    static defaultProps = { 
     activeTab: 'type' 
    } 
} 

在命令行下,我可以使用babel进行lint和transpile,没有任何问题。问题是试图从视觉工作室绒毛。我正在使用内部使用esLint的Web Analyzer plugin

这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分析器:意外的令牌=“错误:

有关使Web Analyzer的行为与命令行工具相同的任何想法?

Visual Studio Linting Error

回答

0

其实在ES6你必须设置它的类,例如外defaultProps:

class NotepadComponent extends React.Component { 
    constructor(props){ 
    super(props); 
    } 
} 
NotepadComponent.defaultProps ={ 
           activeTab:'type' 
           } 
NotepadComponent.displayName = 'NotepadComponent' 

林不知道,如果它是你在找,但也许这可以帮助您

+0

static关键字是ecmascript 2015定义的一部分:https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Classes/static – amhed

0

我与TSLint和Web分析器结合使用时遇到了同样的问题。原来Web分析器在C:\ Users \ [User] \ AppData \ Local \ Temp \ WebAnalyzer1.7.75中使用自己的node_modules安装。您还可以找到一个nodeJS服务器(.js),它将lint结果传递给Visual Studio。我能够调整此服务器以在Visual Studio中获得更多错误反馈。这个反馈告诉我应该在C:\ Users \ [User] \ AppData \ Local \ Temp \ WebAnalyzer1.7.75中安装缺少的npm包。和C:\ Program Files(x86)\ Microsoft Visual Studio 14.0 \ Common7 \ IDE。也许你可以为ESLint做同样的事情。另请参阅WebEssentials tslint custom rules