学习使用sublime插件sublimeLinter

前言

干啥事情都得学会偷懒,code也是如此。尽管grunt工具提供了jshint对js代码作检查的插件,但是,这就有点后知后觉了。如何在你code时就将错误给锁定并消灭呢?

还好,使用submlime的童鞋就有福了。sublimeLinter就是这样一个提供代码检测的工具。

检测语言列表

支持的语言截图:
学习使用sublime插件sublimeLinter_第1张图片

安装sublimeLinter包

安装package我就不多说了了,用过sublime的筒子们都知道两种方法。使用sublime控制台装不了就从github上直接安装吧。地址是:https://github.com/SublimeLinter/SublimeLinter

安装好后,还要有node环境,这样才能检测。没安装node的就安装node吧。

javascript和css的检测分别使用的是jshint/jslint(视你node安装了哪个)csslint

从个人使用来看,检测只针对文件后缀来判定检测,所以,写在html中的js,css
就没法做检测了。这是唯一的缺点。所以,grunt的检测还是需要做最后一步把关的。

个性化配置

然后就是配置了。提供一份自己的配置。如下:

{
    "sublimelinter": "save-only",
    "sublimelinter_popup_errors_on_save": true,
    "sublimelinter_executable_map": {
        "javascript": "D:/Program Files/nodejs/node.exe",
        "css": "D:/Program Files/nodejs/node.exe"
    },
    "jshint_options": {
        "strict": false,
        "quotmark": "single", //只能使用单引号
        "noarg": true,
        "noempty": true, //不允许使用空语句块{}
        "eqeqeq": true, //!==和===检查
        "undef": true,
        "curly": true, //值为true时,不能省略循环和条件语句后的大括号
        "forin": true, //for in hasOwnPropery检查
        "devel": true,
        "jquery": true,
        "browser": true,
        "wsh": true,
        "evil": true,
        "unused": "vars", //形参和变量未使用检查
        "latedef": true, //先定义变量,后使用
        "globals": {
            "grunt": true,
            "module": true,
            "window": true,
            "jQuery": true,
            "$": true,
            "global": true,
            "document": true,
            "console": true,
            "setTimeout": true,
            "setInterval": true
        }
    },
    "csslint_options": {
        "adjoining-classes": false,
        "box-sizing": false,
        "box-model": false,
        "compatible-vendor-prefixes": false,
        "floats": false,
        "font-sizes": false,
        "gradients": false,
        "important": false,
        "known-properties": false,
        "outline-none": false,
        "qualified-headings": false,
        "regex-selectors": false,
        "shorthand": false,
        "text-indent": false,
        "unique-headings": false,
        "universal-selector": false,
        "unqualified-attributes": false
    }
}

考虑到csslint的检测比较坑爹,为了覆盖默认的设置(否则每次保存,将有错误和警告提示,其中属性值为true则是错误提示,为warning则是警告提示),我们必须在user setting中重新设置truefalse,这样就没有提示啦。这个设置参考了bootstrap.csslintrc文件配置。

sublime警告提示截图:

学习使用sublime插件sublimeLinter_第2张图片

其它参数说明,请参考官方文档。css,js检测参数,参考插件对应的官网说明。

html5 tidy 如何配置呢?我不知道,谁知道,请告知。

参考文档:http://www.cnblogs.com/lhb25/archive/2013/05/02/sublimelinter-for-js-css-coding.html

你可能感兴趣的:(sublimelinter,sublime-text)