2014-03-04 40 views
22

我正在使用下劃線庫。與jshint一起使用下劃線

我跑jshint時,得到這樣的:

[L38:C38] W117: '_' is not defined. 
     var approvedAndRequstedCount = _.countBy(products, function(obj) { 

警告:任務 「jshint:所有」 失敗。使用--force繼續。

這是我的配置文件:

{ 
    "node": true, 
    "browser": true, 
    "esnext": true, 
    "bitwise": true, 
    "camelcase": false, 
    "curly": true, 
    "eqeqeq": true, 
    "immed": true, 
    "indent": 2, 
    "latedef": true, 
    "newcap": true, 
    "noarg": true, 
    "quotmark": "single", 
    "regexp": true, 
    "undef": true, 
    "unused": true, 
    "strict": true, 
    "trailing": true, 
    "smarttabs": true, 
    "globals": { 
    "angular": false 
    } 
} 

我想這件事情與全局選項?我試圖添加「_」:假但沒有運氣。有任何想法嗎?

+2

'「_」:false'適用於我(全局變量)。 –

+0

哦!是的,我在主配置對象上也有''-W117「:true'。 –

+0

W117:真正解決了這個問題!謝謝。如果您以簡短的解釋發佈答案,我會批准。 – Per

回答

44

我也有這個問題。

我安裝了下劃線:bower install -save underscore,它在代碼中工作正常。不幸的是,jshint沒有找到該參考。你必須告訴你的全局變量jshint配置文件like .jshintrc

{ 
    … 
    "globals": { 
    "angular": false, 
    "_": false 
    } 
} 

如果繼續有這樣的問題,您需要確保執行jshint時下劃線是包括在內。我會不是推薦設置-W117爲true。壓制這些錯誤可能會導致更多的錯誤。

+1

這也適用於使用lodash。它爲我工作。 –