2017-03-24 18 views
0

Coffeelint告訴我,我有隱含的parens。我試圖找出造成這個錯誤的原因。Coffeelint說我有隱含的parens?

#309: Implicit parens are forbidden. 

這裏是我的代碼:

((factory) -> 
    if typeof module == 'object' and module.exports 
    module.exports = factory 
    else 
    factory(Highcharts) 
    return 
)(Highcharts) -> 
... 
    if seriesTypes.map 
    seriesTypes.map::exportKey = 'name' 
    if seriesTypes.mapbubble 
    seriesTypes.mapbubble::exportKey = 'name' 
    if seriesTypes.treemap 
    seriesTypes.treemap::exportKey = 'name' 
    return 
###The entire block over code is one function. 

任何這給一次機會嗎?

+0

請將您的代碼本身發佈在問題中,而不僅僅是鏈接。你可以[編輯]你的帖子。 – Bergi

+0

什麼問題?我用coffeelint檢查了你的代碼,它說:「你的代碼是免費的!」 –

+0

Coffeelint被設置爲捕捉隱式parens。我不能忽視這些測試,因爲這是針對具有自己標準的應用程序。 @SergeyMetlov –

回答

0

我認爲你的代碼存在問題。看看JS產生:

(function(factory) { 
    if (typeof module === 'object' && module.exports) { 
    module.exports = factory; 
    } else { 
    factory(Highcharts); 
    } 
})(Highcharts)(function() { 
    ... 
}); 

作爲第一函數返回undefined有試圖調用undefined作爲函數的錯誤。

其實no_implicit_parens是:

# This rule prohibits implicit parens on function calls. 

# Some folks don't like this style of coding. 
myFunction a, b, c 

# And would rather it always be written like this: 
myFunction(a, b, c) 

隨着對,你必須將所有的函數調用的任何參數列表括號此選項。
爲了讓你的代碼工作,你可以做到以下幾點:

((factory) -> 
    ... 
)(Highcharts(-> 
    ... 
)) 

周圍的回調函數,這些支架做的伎倆。但正如我所說的,我確信你的代碼存在問題,修復對我來說實際上毫無意義:)

+0

該代碼正在爲我工​​作,但我無法通過coffeelint測試。在你回答之前,我想了一會兒。感謝您的幫助,您的解決方案是正確的。 –