JSLint:修订间差异
创建页面,内容为“== 作者 == [http://www.jslint.com/ JSLint] 是由 Douglas Crockford 开发的,可能是最早的 [https://github.com/douglascrockford/JSLint JavaScript Lint] 工…” |
|||
| (未显示同一用户的3个中间版本) | |||
| 第4行: | 第4行: | ||
== 特征 == | == 特征 == | ||
== 安装 == | == 安装 == | ||
{{shc|<syntaxhighlight lang="bash"> | |||
npm install jshint -g</syntaxhighlight>}} | |||
== 配置 == | == 配置 == | ||
== 插件 == | |||
{| class="wikitable" | |||
|- | |||
| SublimeText:[https://github.com/SublimeLinter/SublimeLinter SublimeLinter] || Vim:[https://github.com/Shutnik/jshint2.vim jshint2.vim] || Textmate:[https://github.com/bodnaristvan/JSHint.tmbundle JSHint.tmbundle] || Visual Studio:[https://github.com/jamietre/SharpLinter SharpLinter] | |||
|- | |||
| Brackets / Edge Code:[https://github.com/cfjedimaster/brackets-jshint/ Brackets JSHint] || Notepad++:[http://sourceforge.net/projects/jslintnpp/ jslintnpp] || gEdit:[https://github.com/Kilian/gedit-jshint gEdit JSHint] || | |||
|} | |||
== 规则 == | == 规则 == | ||
JSHint常见的设置选项 | |||
强制选项 | |||
禁用位运算符,位运算符在 JavaScript 中使用较少,经常是把 && 错输成 & | |||
bitwise: true | |||
循环或者条件语句必须使用花括号包围 | |||
curly: true | |||
强制使用三等号 | |||
eqeqeq: true | |||
兼容低级浏览器 IE 6/7/8/9 | |||
es3: true | |||
禁止重写原生对象的原型,比如 Array , Date | |||
freeze: true | |||
代码缩进 | |||
indent: true | |||
禁止定义之前使用变量,忽略 function 函数声明 | |||
latedef: "nofunc" | |||
构造器函数首字母大写 | |||
newcap: true | |||
禁止使用 arguments.caller 和 arguments.callee ,未来会被弃用, ECMAScript 5 禁止使用 arguments.callee | |||
noarg:true | |||
为 true 时,禁止单引号和双引号混用 | |||
"quotmark": false | |||
变量未定义 | |||
"undef": true | |||
变量未使用 | |||
"unused": true | |||
严格模式 | |||
strict:true | |||
最多参数个数 | |||
maxparams: 4 | |||
最大嵌套深度 | |||
maxdepth: 4 | |||
复杂度检测 | |||
maxcomplexity:true | |||
最大行数 | |||
maxlen: 600 | |||
宽松选项 | |||
控制“缺少分号”的警告 | |||
"asi": true | |||
"boss": true | |||
忽略 debugger | |||
"debug": true | |||
控制 eval 使用警告 | |||
"evil": true | |||
检查一行代码最后声明后面的分号是否遗漏 | |||
"lastsemic": true | |||
检查不安全的折行,忽略逗号在最前面的编程风格 | |||
"laxcomma": true | |||
检查循环内嵌套 function | |||
"loopfunc": true | |||
检查多行字符串 | |||
"multistr": true | |||
检查无效的 typeof 操作符值 | |||
"notypeof": true | |||
person['name'] vs. person.name | |||
"sub": true | |||
new function () { ... } 和 new Object ; | |||
"supernew": true | |||
在非构造器函数中使用 this | |||
"validthis": true | |||
环境 | |||
预定义全局变量 document , navigator , FileReader 等 | |||
"browser": true | |||
定义用于调试的全局变量: console , alert | |||
"devel": true | |||
定义全局变量 | |||
"jquery": true, | |||
"node": true | |||
== 示例 == | == 示例 == | ||
== 技巧 == | == 技巧 == | ||
== 备注 == | == 备注 == | ||
== 参考 == | |||
* http://www.jshint.com/docs/ | |||
* https://github.com/gruntjs/grunt-contrib-jshint | |||
2020年3月26日 (四) 10:17的最新版本
作者
JSLint 是由 Douglas Crockford 开发的,可能是最早的 JavaScript Lint 工具了吧,它的名字来源于著名的C语言工具Lint。
特征
安装
npm install jshint -g
配置
插件
| SublimeText:SublimeLinter | Vim:jshint2.vim | Textmate:JSHint.tmbundle | Visual Studio:SharpLinter |
| Brackets / Edge Code:Brackets JSHint | Notepad++:jslintnpp | gEdit:gEdit JSHint |
规则
JSHint常见的设置选项 强制选项
禁用位运算符,位运算符在 JavaScript 中使用较少,经常是把 && 错输成 & bitwise: true 循环或者条件语句必须使用花括号包围 curly: true 强制使用三等号 eqeqeq: true 兼容低级浏览器 IE 6/7/8/9 es3: true 禁止重写原生对象的原型,比如 Array , Date freeze: true 代码缩进 indent: true 禁止定义之前使用变量,忽略 function 函数声明 latedef: "nofunc" 构造器函数首字母大写 newcap: true 禁止使用 arguments.caller 和 arguments.callee ,未来会被弃用, ECMAScript 5 禁止使用 arguments.callee noarg:true 为 true 时,禁止单引号和双引号混用 "quotmark": false 变量未定义 "undef": true 变量未使用 "unused": true 严格模式 strict:true 最多参数个数 maxparams: 4 最大嵌套深度 maxdepth: 4 复杂度检测 maxcomplexity:true 最大行数 maxlen: 600 宽松选项
控制“缺少分号”的警告 "asi": true "boss": true 忽略 debugger "debug": true 控制 eval 使用警告 "evil": true 检查一行代码最后声明后面的分号是否遗漏 "lastsemic": true 检查不安全的折行,忽略逗号在最前面的编程风格 "laxcomma": true 检查循环内嵌套 function "loopfunc": true 检查多行字符串 "multistr": true 检查无效的 typeof 操作符值 "notypeof": true person['name'] vs. person.name "sub": true new function () { ... } 和 new Object ; "supernew": true 在非构造器函数中使用 this "validthis": true 环境
预定义全局变量 document , navigator , FileReader 等 "browser": true 定义用于调试的全局变量: console , alert "devel": true 定义全局变量
"jquery": true, "node": true
示例
技巧
备注
参考
No categories