nodejs+sublime+sublimelinter+jshint+javascript代码检查

sublime 安装jslint代码检查插进步骤:


1、安装nodejs。下载地址:http://nodejs.org/download/
2、在控制台安装jshint:$ npm install jshint -g
3、在sublime安装sublimelinter
4、在sublime安装jshint
5、配置sublimelinter:preference-package setting-sublimelinter-user
{
  "sublimelinter": "save-only",
   "jshint_options":
    {
        // To fix column positions for JSHint errors you may want to add `"indent": 1` to your
        // **User** "jshint_options". This issue affects users with tabs for indentation.
        // This fix was reverted due to a conflict with using the `"white": true` option.
        // "indent": 1,
        // 设置 JS 执行环境为浏览器
        "browser": true,
         // 加载 jQuery 的全局变量(jQuery、$)
        "jquery": true,
        //禁止下划线的变量名
        "nomen":true,
         // 行尾不要分号,false表示强制需要分号结尾
        "asi": false,
        "white":true,
        // 其他全局变量,我用了 SeaJS
        "predef": [
             "define",
             "seajs",
             "console"
             ]
    },
    "sublimelinter_executable_map":
{
    "javascript":"C:/Program Files/nodejs/node.exe",
    "css":"C:/Program Files/nodejs/node.exe"
}
}





6、jsformat 和jslint的配合使用(主要使格式化操作复合jslint的要求)

preference-》package setting-》jsformat-》setting user添加一下配置,主要把jslint_happy改为true。


{
	// exposed jsbeautifier options
	"indent_with_tabs": false,
	"preserve_newlines": true,
	"max_preserve_newlines": 4,
	"space_in_paren": false,
	"jslint_happy": true,
	"brace_style": "collapse",
	"keep_array_indentation": false,
	"keep_function_indentation": false,
	"eval_code": false,
	"unescape_strings": false,
	"break_chained_methods": false,
	"e4x": false,
	"wrap_line_length": 0,

	// jsformat options
	"format_on_save": false,
	"format_selection": true,
	"jsbeautifyrc_files": false,
	"ignore_sublime_settings": true
}






这样每次保存js文件的时候便会主动检查js代码规范,其中 "white":true配置个人尤为喜欢,有惊喜。

你可能感兴趣的:(sublime,nodejs,JSHint,jslint,代码检查)