用grunt搭建自動化的web前端開發環境(三)jshint配置參數 【轉載自博客園Tadini】



選項  內容  值 錯誤信息
bitwise  禁用位運算符(如^,&)   設置:true; 不設置:false  Unexpected use of '・・・'.(設置true時)
curly  if和while等語句中使用{}來明確代碼塊   設置:true; 不設置:false  Expected '{' and instead saw '・・・'.
eqeqeq  使用===和!==替代==和!=   設置:true; 不設置:false  Use '===' to compare with 'null'.
 forin

 在for in循環中使用Object.prototype.hasOwnProperty()來過濾原型鏈中的屬性

 

  設置:true; 不設置:false   The body of a for in should be wrapped in an if statement to filter unwanted properties from the prototype
 immed

匿名函數調用必須

(function() {
   // body 
}());

而不是

(function() {
   // body
})();
這是爲了表明,表達式的值是函數的結果,而不是函數本身。
設置:true; 不設置:false 
 
Move the invocation into the parens that contain the function. ・Wrap an immediate function invocation in parentheses to assist the reader in understanding that the expression is the result of a function, and not the function itself. 
 latedef  變量定義前禁止使用  設置:true; 不設置:false  ' ' was・・・used before it was defined .
 newcap  構造函數名首字母必須大寫  設置:true; 不設置:false  A constructor name should start with an uppercase letter.
 noarg  禁止使用arguments.callerarguments.callee  設置:true; 不設置:false  Avoid arguments.callee.
 noempty  禁止出現空的代碼塊  設置:true; 不設置:false  Empty block.
 nonew  禁止使用構造器  設置:true; 不設置:false  Do not use 'new' for side effects.
 plusplus  禁止使用++和--  設置:true; 不設置:false  Unexpected use of '++'.
 undef  禁止使用不在全局變量列表中的未定義的變量  設置:true; 不設置:false '・・・' is not defined.
 strict  強制使用ES5的嚴格模式   設置:true; 不設置:false  Missing "use strict" statement.
 freeze

 禁止複寫原生對象(如Array, Date)的原型

 

/* jshint freeze:true */
Array.prototype.count = function (value) { return 4; };
// -> Warning: Extending prototype of native object: 'Array'.

 

 設置:true; 不設置:false   Warning: Extending prototype of native object: 'Array'.
       
       
       
       
       
 asi  允許省略分號  允許:true; 不允許:false  Missing semicolon.
 boss  允許在if,for,while語句中使用賦值;在條件語句中使用賦值經常是筆誤if (a = 10) {}  允許:true; 不允許:false  Expected a conditional expression and instead saw an assignment.
 debug  允許debugger語句  允許:true; 不允許:false  All 'debugger' statements should be removed.
 eqnull

 允許==null

==null通常用來比較=== null;=== undefined

 允許:true; 不允許:false Use '===' to compare with '~'. 
 evil  允許使用eval  允許:true; 不允許:false  eval is evil.
 expr  允許應該出現賦值或函數調用的地方使用表達式  允許:true; 不允許:false  Expected an assignment or function call and instead saw an expression.
 iterator  允許__iterator__;不是所有的瀏覽器都支持__iterator__。  允許:true; 不允許:false  __iterator__' is only available in JavaScript 1.7.
 lastsemic

 允許單行控制塊省略分號

 

var name = (function() { return 'Anton' }());

 

 

 允許:true; 不允許:false Missing semicolon. 
 laxbreak  允許不安全的行中斷(與laxcomma配合使用)  允許:true; 不允許:false  Bad line breaking before '~'.
 laxcomma  允許逗號開頭的編碼樣式  允許:true; 不允許:false  Comma warnings can be turned off with 'laxcomma'.
 loopfunc  允許循環中定義函數  允許:true; 不允許:false  Don't make functions within a loop.
 onecase  允許只有一個case條件的switch語句嗎  允許:true; 不允許:false  This 'switch' should be an 'if'.
 proto  允許 proto(不是所有的瀏覽器都支持__proto__.)  允許:true; 不允許:false  The '__proto__' property is deprecated.(反對)
 regexdash

 待了解---》好像可以這麼理解:

在正則表達式的控制語句,連字符開頭或方括號的結束 - 容忍的存在。

 允許:true; 不允許:false  Unescaped '-'.
 scripturl    允許:true; 不允許:false  
 shadow

 允許變量shadow

 

function test() {
    var x = 10;

    if (true) {
        var x = 20;
    }

    return x;
}
基於“函數作用域”,多次定義變量和單次定義是沒有區別的,但是會造成閱讀障礙。

 

 允許:true; 不允許:false '・・・' is already defined. 
sub

 允許person[‘name’]

JSHint推薦使用person.name代替person[‘name’]

 允許:true; 不允許:false  ['・・・'] is better written in dot notation.
 supernew  允許new function() {…}和new Object;  允許:true; 不允許:false  Weird construction. Delete
 validthis  允許嚴格模式下在非構造函數中使用this  允許:true; 不允許:false  Possible strict violation.
       
選項  內容  值 錯誤信息
bitwise  禁用位運算符(如^,&)   設置:true; 不設置:false  Unexpected use of '・・・'.(設置true時)
curly  if和while等語句中使用{}來明確代碼塊   設置:true; 不設置:false  Expected '{' and instead saw '・・・'.
eqeqeq  使用===和!==替代==和!=   設置:true; 不設置:false  Use '===' to compare with 'null'.
 forin

 在for in循環中使用Object.prototype.hasOwnProperty()來過濾原型鏈中的屬性

 

  設置:true; 不設置:false   The body of a for in should be wrapped in an if statement to filter unwanted properties from the prototype
 immed

匿名函數調用必須

(function() {
   // body 
}());

而不是

(function() {
   // body
})();
這是爲了表明,表達式的值是函數的結果,而不是函數本身。
設置:true; 不設置:false 
 
Move the invocation into the parens that contain the function. ・Wrap an immediate function invocation in parentheses to assist the reader in understanding that the expression is the result of a function, and not the function itself. 
 latedef  變量定義前禁止使用  設置:true; 不設置:false  ' ' was・・・used before it was defined .
 newcap  構造函數名首字母必須大寫  設置:true; 不設置:false  A constructor name should start with an uppercase letter.
 noarg  禁止使用arguments.callerarguments.callee  設置:true; 不設置:false  Avoid arguments.callee.
 noempty  禁止出現空的代碼塊  設置:true; 不設置:false  Empty block.
 nonew  禁止使用構造器  設置:true; 不設置:false  Do not use 'new' for side effects.
 plusplus  禁止使用++和--  設置:true; 不設置:false  Unexpected use of '++'.
 undef  禁止使用不在全局變量列表中的未定義的變量  設置:true; 不設置:false '・・・' is not defined.
 strict  強制使用ES5的嚴格模式   設置:true; 不設置:false  Missing "use strict" statement.
 freeze

 禁止複寫原生對象(如Array, Date)的原型

 

/* jshint freeze:true */
Array.prototype.count = function (value) { return 4; };
// -> Warning: Extending prototype of native object: 'Array'.

 

 設置:true; 不設置:false   Warning: Extending prototype of native object: 'Array'.
       
       
       
       
       
 asi  允許省略分號  允許:true; 不允許:false  Missing semicolon.
 boss  允許在if,for,while語句中使用賦值;在條件語句中使用賦值經常是筆誤if (a = 10) {}  允許:true; 不允許:false  Expected a conditional expression and instead saw an assignment.
 debug  允許debugger語句  允許:true; 不允許:false  All 'debugger' statements should be removed.
 eqnull

 允許==null

==null通常用來比較=== null;=== undefined

 允許:true; 不允許:false Use '===' to compare with '~'. 
 evil  允許使用eval  允許:true; 不允許:false  eval is evil.
 expr  允許應該出現賦值或函數調用的地方使用表達式  允許:true; 不允許:false  Expected an assignment or function call and instead saw an expression.
 iterator  允許__iterator__;不是所有的瀏覽器都支持__iterator__。  允許:true; 不允許:false  __iterator__' is only available in JavaScript 1.7.
 lastsemic

 允許單行控制塊省略分號

 

var name = (function() { return 'Anton' }());

 

 

 允許:true; 不允許:false Missing semicolon. 
 laxbreak  允許不安全的行中斷(與laxcomma配合使用)  允許:true; 不允許:false  Bad line breaking before '~'.
 laxcomma  允許逗號開頭的編碼樣式  允許:true; 不允許:false  Comma warnings can be turned off with 'laxcomma'.
 loopfunc  允許循環中定義函數  允許:true; 不允許:false  Don't make functions within a loop.
 onecase  允許只有一個case條件的switch語句嗎  允許:true; 不允許:false  This 'switch' should be an 'if'.
 proto  允許 proto(不是所有的瀏覽器都支持__proto__.)  允許:true; 不允許:false  The '__proto__' property is deprecated.(反對)
 regexdash

 待了解---》好像可以這麼理解:

在正則表達式的控制語句,連字符開頭或方括號的結束 - 容忍的存在。

 允許:true; 不允許:false  Unescaped '-'.
 scripturl    允許:true; 不允許:false  
 shadow

 允許變量shadow

 

function test() {
    var x = 10;

    if (true) {
        var x = 20;
    }

    return x;
}
基於“函數作用域”,多次定義變量和單次定義是沒有區別的,但是會造成閱讀障礙。

 

 允許:true; 不允許:false '・・・' is already defined. 
sub

 允許person[‘name’]

JSHint推薦使用person.name代替person[‘name’]

 允許:true; 不允許:false  ['・・・'] is better written in dot notation.
 supernew  允許new function() {…}和new Object;  允許:true; 不允許:false  Weird construction. Delete
 validthis  允許嚴格模式下在非構造函數中使用this  允許:true; 不允許:false  Possible strict violation.
       
       
       
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章