2016-01-21 41 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