SublimeLinter

官方文档

github地址

sublimeLinter提供代码检测,支持的语言如下:

  1. C/C++ - lint via cppcheck
  2. CoffeeScript - lint via coffee -s -l
  3. CSS - lint via built-in csslint
  4. Git Commit Messages - lint via built-in module based on A Note About Git Commit Messages.
  5. Haml - syntax check via haml -c
  6. HTML - lint via tidy (actually tidy for HTML5)
  7. Java - lint via javac -Xlint
  8. JavaScript - lint via built in jshint, jslint, or the closure linter (gjslint) (if installed)
  9. Lua - syntax check via luac
  10. Objective-J - lint via built-in capp_lint
  11. Perl - lint via Perl::Critic or syntax+deprecation check via perl -c
  12. PHP - syntax check via php -l
  13. Puppet - syntax check via puppet parser validate or puppet-lint
  14. Python - native, moderately-complete lint
  15. Ruby - syntax check via ruby -wc
  16. Squirrel - syntax check via sq
  17. XML - lint via xmllint

SublimeLinter需要nodejs环境支持。

并且检测不同的代码需要下载对应的插件

检测代码 插件名称
javascript SublimeLinter-jshint
css SublimeLinter-csslint
html SublimeLinter-html-tidy

其他语言按照自己的开发需求下载

参数配置

打开 SublimeLinter 的配置文件,Preferences->Package Settings->SublimeLinter->Settings - User,进行如下配置:

运行模式 sublimelinter

表示检测的时机。默认为true。

  1. "sublimelinter": "save-only",

SublimeLinter 的运行模式,总共有四种,含义分别如下:

  • true - 在用户输入时在后台进行即时校验;
  • false - 只有在初始化的时候才进行校验;
  • “load-save” - 当文件加载和保存的时候进行校验;
  • “save-only” - 当文件被保存的时候进行校验;

校验引擎 sublimelinter_executable_map

这里是配置 JavaScript 和 CSS 校验需要用到的 JS 引擎(这里用的是 Node.js)的安装路径。

  • Mac下配置

    1. "sublimelinter_executable_map":
    2. {
    3. "html": "/usr/local/bin/tidy",
    4. "javascript": "/usr/local/bin/node",
    5. "ruby": "rvm-auto-ruby"
    6. },

    表示html用tidy进行检测,js用node检测。

  • windows下配置

    1. "sublimelinter_executable_map":
    2. {
    3. "javascript":"D:/nodejs/node.exe",
    4. "css":"D:/nodejs/node.exe"
    5. }

JSLint 选项

 SublimeLinter 使用 JSHint 作为默认的 JavaScript 校验器,也可以配置为 jslint 和 gjslint(closure linter)。大家可以根据自己的编码风格自行配置,选项的含义可以参考这里jshint配置

  1. "jslint_options":
  2. {
  3. "strict": true,
  4. "noarg": true,
  5. "noempty": true,
  6. "eqeqeq": true,
  7. "undef": true,
  8. "curly": true,
  9. "forin": true,
  10. "devel": true,
  11. "jquery": true,
  12. "browser": true,
  13. "wsh": true,
  14. "evil": true
  15. }

CSSLint 选项

 SublimeLinter 使用 CSSLint 作为 CSS 的校验器,,可以根据个人编码风格修改:

  1. "csslint_options":
  2. {
  3. "adjoining-classes": "warning",
  4. "box-model": true,
  5. "box-sizing": "warning",
  6. "compatible-vendor-prefixes": "warning",
  7. "display-property-grouping": true,
  8. "duplicate-background-images": "warning",
  9. "duplicate-properties": true,
  10. "empty-rules": true,
  11. "errors": true,
  12. "fallback-colors": "warning",
  13. "floats": "warning",
  14. "font-faces": "warning",
  15. "font-sizes": "warning",
  16. "gradients": "warning",
  17. "ids": "warning",
  18. "import": "warning",
  19. "important": "warning",
  20. "known-properties": true,
  21. "outline-none": "warning",
  22. "overqualified-elements": "warning",
  23. "qualified-headings": "warning",
  24. "regex-selectors": "warning",
  25. "rules-count": "warning",
  26. "shorthand": "warning",
  27. "star-property-hack": "warning",
  28. "text-indent": "warning",
  29. "underscore-property-hack": "warning",
  30. "unique-headings": "warning",
  31. "universal-selector": "warning",
  32. "vendor-prefix": true,
  33. "zero-units": "warning"
  34. }

我的配置文档

  1. {
  2. "sublimelinter": "save-only",
  3. "sublimelinter_popup_errors_on_save": true, //会在保存时弹出错误信息
  4. "sublimelinter_executable_map":
  5. {
  6. "html": "/usr/local/bin/tidy",
  7. "javascript": "/usr/local/bin/node"
  8. },
  9. "jsl int_options": {
  10. "strict": false,
  11. "quotmark": "single", //只能使用单引号
  12. "noarg": true,
  13. "noempty": true, //不允许使用空语句块{}
  14. "eqeqeq": true, //!==和===检查
  15. "undef": true,
  16. "curly": true, //值为true时,不能省略循环和条件语句后的大括号
  17. "forin": true, //for in hasOwnPropery检查
  18. "devel": true,
  19. "jquery": true,
  20. "browser": true,
  21. "wsh": true,
  22. "evil": true,
  23. "unused": "vars", //形参和变量未使用检查
  24. "latedef": true, //先定义变量,后使用
  25. "globals": {
  26. "grunt": true,
  27. "module": true,
  28. "window": true,
  29. "jQuery": true,
  30. "$": true,
  31. "global": true,
  32. "document": true,
  33. "console": true,
  34. "setTimeout": true,
  35. "setInterval": true
  36. }
  37. },
  38. "csslint_options": {
  39. "adjoining-classes": false,
  40. "box-sizing": false,
  41. "box-model": false,
  42. "compatible-vendor-prefixes": false,
  43. "floats": false,
  44. "font-sizes": false,
  45. "gradients": false,
  46. "important": false,
  47. "known-properties": false,
  48. "outline-none": false,
  49. "qualified-headings": false,
  50. "regex-selectors": false,
  51. "shorthand": false,
  52. "text-indent": false,
  53. "unique-headings": false,
  54. "universal-selector": false,
  55. "unqualified-attributes": false
  56. }
  57. }

效果如下:
SublimeLinter - 图1