项目经验引入jshintrc来统一校验
1. eclipse 的使用方法:
a. 在Eclipse主菜单,点击: Help > Install New Software…
b. 输入http://github.eclipsesource.com/jshint-eclipse/updates/,然后选择 JSHint Eclipse Integration,然后按确定
c. 选择要启用校验的项目右键->属性,选择JSHint 项,配置启用校验的文件和文件夹
d. 然后选择JSHint下的configuration,在右侧勾选enable project specific configuration 然后点improt 导入webapp下的.jshintrc文件
2. webstorm的使用方法
a. webstorm集成了jshint的插件,因此只需设置下
b. 在主菜单的file下的settings… 打开搜索jshint
c. 勾选Enable ,勾选user config files ,勾选custom configuration file 选择webapp下的.jshintrc文件
3. sublime3的使用方法
a.在sublime中按下Cmd+Shift+P打开命令查找窗口,输入pci找到packge control install回车
稍等等待弹出package查找窗口,输入Sublimelinter,按下回车安装,同样的方式安装SublimeLinter-jshint。
b.安装完后,注意其功能实现需要Node.js支持,所以去https://nodejs.org(node.js官网)单击install进行下载安装。
c.3.完成后,在控制台输入npm install -g jshint
d. 通过sublime打开webapp的目录,如果webapp有.jshintrc文件,就会自动启动规范检查,否则会用nodejs默认的jshint配置来检查。
jshint配置说明:
{
"boss": true, //设置为true允许JSHint会允许在if,for,while里面编写赋值语句
"eqeqeq": true, //值为true禁止使用"=="和"!=",而应该使用"==="和"!=="
"eqnull": true, //值为true允许你使用==来检查null undefined
"strict": false, //值为true时,该选项会要求所有函数在ECMAScript 5的严格模式中运行
"undef": true, //值为true时,禁止使用未定义的变量
"unused": true, //值为true,对于"已定义却未使用的变量"会给出警告
"latedef": true, //值为true时,禁止在变量定义之前使用它
"indent": 4, //该选项要求你的代码必须使用指定的tab缩进宽度为4个空格
"maxlen": 80, //该选项用于设定每行的最大字符长度
"maxerr": 500, //默认50个当前设置500个,
"camelcase": true, //值为true变量名必须使用驼峰风格
"loopfunc": false, //值为false不允许循环内嵌套 function
"multistr": true, //值为true允许多行字符
"sub": false, //值为false不允许person['name'] 只能写成 person.name
"lastsemic": true, //值为false检查一行代码最后声明后面的分号是否遗漏
"evil": false, //值为true允许使用eval
"curly": true, //值为true时,不能省略循环和条件语句后的大括号
"forin": true, //值为true 要使用obj.hasOwnProperty(key) hasOwnProperty过滤掉继承的方法
"freeze": true, //值为true禁止复写原生对象(如Array, Date)的原型
"quotmark": "single", //值为”single”该选项用于统一代码中的单引号风格
"supernew": false, //值为true允许new function 和 new Object
"funcscope": false, //设置true允许变量域的提升,但是会影响调试
"notypeof": true, //值为true警告使用无效的typeof
"futurehostile": true, //值为true警告提示未来的关键标识符
"nocomma": true, //值为true当滥用逗号操作符的时候会提示
"withstmt": true, //值为true当你使用with的时候会警告,
"browser": true, //值为true document 将不会提示not defined
"devel": true //值为true console, alert 将不会对这样的一些全局进行提示not defined
"globals": //配合undef使用的全局变量
}