2011-06-08 69 views
1

我想用jQuery Lint檢查可能的jQuery錯誤。jQuery Lint錯誤是相當不具描述性的

我想試用一個簡單的腳本,它的工作原理。我把jquery lint包括在內,把它設置爲2級,而BAM則有3個錯誤。

jQuery(.highlightimage) special check failed 

jquery.lint.js (line 100) 

More info: 

Selector: .highlightimage Selectors should be as specific as possible and should be "class only" 

Collection: [] 

Location: 

@http://localhost:53402/Resources/Scripts/jquery-1.6.1.min.js:16 

@http://localhost:53402/Resources/Scripts/highlights.js:15 

@http://localhost:53402/Resources/Scripts/jquery-1.6.1.min.js:16 

@http://localhost:53402/Resources/Scripts/jquery-1.6.1.min.js:16 

什麼?第15行是:

hl_elements = $(".highlightimage"); 

那個錯誤是什麼意思?選擇器包含5個元素,因此它是有效的。它儘可能具體。

它在$(document).ready(function(){/ 這裏是腳本 /});部分。

我的所有選擇器都是這樣失敗的。我究竟做錯了什麼?

我正在使用jquery 1.6.1,它可能還不支持,但在github上已經有jquery 1.6.1的測試用例,並且它們工作正常。

其他錯誤是:

trigger(ready) called incorrectly 
jquery.lint.js (line 100) 

More info: 
Collection: [Document localhost:53402] 

Location: 
@http://localhost:53402/Resources/Scripts/jquery-1.6.1.min.js:16 
jquery.lint.js (line 115) 
You passed: ["ready"] 

Available signatures include: 
trigger(eventType, extraParameters) 
trigger(event) 

我得到的頁面加載。

每當圖像被改變時,我都會得到另一個。

jQuery.removeData([object HTMLImageElement],fxqueue,true) called incorrectly 
jquery.lint.js (line 100) 

More info: 
Location: 
@http://localhost:53402/Resources/Scripts/jquery-1.6.1.min.js:16 
@http://localhost:53402/Resources/Scripts/jquery-1.6.1.min.js:18 
@http://localhost:53402/Resources/Scripts/jquery-1.6.1.min.js:18 
jquery.lint.js (line 115) 
You passed: [img.highlightimage /Documen..._293.png, "fxqueue", true] 

Available signatures include: 
jQuery.removeData(element, [name]) 

但是,如果我切換到jquery 1.4.4這最後一個不會發生。

+0

有時候立即上方或下方有一個錯誤,但我不能告訴你更多沒有一些代碼片段:) – 2011-06-08 08:46:36

+0

http://jsfiddle.net/SoonDead/fMcrb/這是我的代碼,我也使用jquery 1.6.1 – SoonDead 2011-06-08 12:35:35

回答

3

的源代碼在https://github.com/jamespadolsey/jQuery-Lint/blob/551c2106ac0daee95a670fb180610d09e58bb4cc/jquery.lint.js#L711說:

//查找類只選器(差 IE6-8性能)

所以我想這是對警告的原因。如果你想使用類選擇器,那麼我會認爲你可以忽略它。

(我假設的錯誤文本應該說「不應該‘類只’」)。

+0

這當然不容易解釋。也許通過「只有班級」,他們意味着你不應該做「div.whatever」(而不是「class」),而是「儘可能具體」,這意味着你應該做「#specificarea」。不管「以避免搜索整個文檔。 – 2011-06-08 09:16:50

+0

這實際上幫了很多!謝謝,但遺憾的是還有其他錯誤。我在上面的評論上發佈了jsfiddle。 – SoonDead 2011-06-08 12:44:00