标签:person ado mapreduce work 配置 doc into nal 浏览器
官方网站这样介绍:
JSHint, A Static Code Analysis Tool for JavaScript;
This is JSHint, a tool that helps to detect errors and potential
problems in your JavaScript code.
由此可见JSHint是一个javascript代码分析检测工具,不仅可以帮助我们检测到js代码错误和潜在问题,也能帮助我们规范代码开发。
npm install jshint -g
这个设置允许您每个项目有不同的配置文件。把你的文件放到项目根目录,只要你运行JSHint从任何地方在你的项目目录树,将使用相同的配置文件。
{
"undef": true,
"unused": true,
"predef": [ "MY_GLOBAL" ]
}
/* jshint undef: true, unused: true */
/* globals MY_GLOBAL */
可以使用单行或者多行来配置JSHint,如果放在函数里面,则只影响该函数。
// Code here will be linted with JSHint.
/* jshint ignore:start */
// Code here will be ignored by JSHint.
/* jshint ignore:end */
在jshint ignore:start和 ignore:end之间的所有代码都将被JSHint忽略,所以你可以使用像Facebook React这样的扩展框架。 ignoreThis(); // jshint ignore:line
bitwise: true
camelcase:true/false
while (day)
shuffle();
然而,在某些情况下,它会导致错误(你可能会认为 sleep()是一个循环的一部分,而事实上它不是)
while (day)
shuffle();
sleep();
eqeqeq: true
for (key in obj) {
if (obj.hasOwnProperty(key)) {
// We are sure that obj[key] belongs to the object and was not inherited.
}
}
function test() {
if (true) {
var x = 0;
}
x += 1; // Default: ‘x‘ used out of scope.
// No warning when funcscope:true
}
(function(){}());
// jshint maxdepth:2
function main(meaning) {
var day = true;
if (meaning === 42) {
while (day) {
shuffle();
if (tired) {
// JSHint: Blocks are nested too deeply (3).
sleep();
}
}
}
}
maxparams
这个选项允许您设置每个函数的形参最大数量
// jshint maxparams:3
function login(request, onSuccess) {
// ...
}
// JSHint: Too many parameters per function (4).
function logout(request, isManual, whereAmI, onSuccess) {
// ...
}
function main() {
var i = 0;
var j = 0;
// Function declarations count as one statement. Their bodies
// don‘t get taken into account for the outer function.
function inner() {
var i2 = 1;
var j2 = 1;
return i2 + j2;
}
j = i + j;
return j; // JSHint: Too many statements per function. (5)
}
函数也算声明。new F()
形式。new MyConstructor();
// ‘fuction‘ instead of ‘function‘
if (typeof a == "fuction") { // Invalid typeof value ‘fuction‘
// ...
}
// jshint singleGroups: true
delete(obj.attr); // Warning: Unnecessary grouping operator.
// jshint undef:true
function test() {
var myVar = ‘Hello, World‘;
// Oops, typoed here. JSHint with undef will complain
console.log(myvar);
}
如果你的另一个文件中定义的变量,你可以使用 global指令告诉JSHint。
// jshint unused:true
function test(a, b) {
var c, d = 2;
return a + d;
}
test(1, 2);
// Line 3: ‘b‘ was defined but never used.
// Line 4: ‘c‘ was defined but never used
// jshint varstmt: true
var a; // Warning: `var` declarations are forbidden. Use `let` or `const` instead.
if (a = 10) {}
是一个错误,但他有可能这样用
for (var i = 0, person; person = people[i]; i++) {}
你可以禁止这个错误,比如
for (var i = 0, person; (person = people[i]); i++) {}
var name = (function() { return ‘Anton‘ }());
var obj = {
name: ‘Anton‘
, handle: ‘valueof‘
, role: ‘SW Engineer‘
};
var nums = [];
for (var i = 0; i < 10; i++) {
nums[i] = function (j) {
return i + j;
};
}
nums[0](2); // Prints 12 instead of 2
解决上面的代码,你需要复制的变量 i:
var nums = [];
for (var i = 0; i < 10; i++) {
(function (i) {
nums[i] = function (j) {
return i + j;
};
}(i));
}
// jshint multistr:true
var text = "Hello\World"; // All good.
text = "HelloWorld"; // Warning, no escape character.
text = "Hello\World"; // Warning, there is a space after \
__proto__
属性的警告javascript:...
person[‘name‘] vs.person.name.
new function () { ... }和 new Object;
var singleton = new function() {
var privateVar;
this.publicMethod = function () {}
this.publicMethod2 = function () {}
};
这些选项让JSHint知道一些预先定义的全局变量。
标签:person ado mapreduce work 配置 doc into nal 浏览器
原文地址:http://www.cnblogs.com/developer-ios/p/6262550.html