借助SublimeLinter编写高质量的JavaScript & CSS代码
SublimeLinter 是前端编码利器——Sublime Text 的一款插件,用于高亮提示用户编写的代码中存在的不规范和错误的写法,支持 JavaScript、CSS、HTML、Java、PHP、Python、Ruby 等十多种开发语言。这篇文章介绍如何在 Windows 中配置 SublimeLinter 进行 JS & CSS 校验。
准备工作 安装 Sublime Text 包管理工具:http://wbond.net/sublime_packages/package_control
使用 Sublime Text 包管理工具安装 SublimeLinter:https://github.com/SublimeLinter/SublimeLinter
安装 Node.js,建议安装 Windows Installer 版本:http://nodejs.org
参数配置 打开 SublimeLinter 的配置文件,Preferences->Package Settings->SublimeLinter->Settings - User,进行如下配置:
(1)运行模式
"sublimelinter": "save-only", SublimeLinter 的运行模式,总共有四种,含义分别如下:
true - 在用户输入时在后台进行即时校验;false - 只有在初始化的时候才进行校验;"load-save" - 当文件加载和保存的时候进行校验;"save-only" - 当文件被保存的时候进行校验; 推荐设置为 “save-only”,这样只在编写完代码,保存的时候才校验,Sublime Text 运行会更加流畅。
(2)校验引擎
"sublimelinter_executable_map":{ "javascript":"D:/nodejs/node.exe", "css":"D:/nodejs/node.exe"}
这里是配置 JavaScript 和 CSS 校验需要用到的 JS 引擎(这里用的是 Node.js)的安装路径。
(3)JSHint 选项
SublimeLinter 使用 JSHint 作为默认的 JavaScript 校验器,也可以配置为 jslint 和 gjslint(closure linter)。下面我使用的 jshint 校验选项,大家可以根据自己的编码风格自行配置,选项的含义可以参考这里:http://www.jshint.com/docs/#options
"jshint_options":{ "strict": true, "noarg": true, "noempty": true, "eqeqeq": true, "undef": true, "curly": true, "forin": true, "devel": true, "jquery": true, "browser": true, "wsh": true, "evil": true}
(4)CSSLint 选项
SublimeLinter 使用 CSSLint 作为 CSS 的校验器,下面是默认配置的校验选项,可以根据个人编码风格修改:
"csslint_options":{ "adjoining-classes": "warning", "box-model": true, "box-sizing": "warning", "compatible-vendor-prefixes": "warning", "display-property-grouping": true, "duplicate-background-images": "warning", "duplicate-properties": true, "empty-rules": true, "errors": true, "fallback-colors": "warning", "floats": "warning", "font-faces": "warning", "font-sizes": "warning", "gradients": "warning", "ids": "warning", "import": "warning", "important": "warning", "known-properties": true, "outline-none": "warning", "overqualified-elements": "warning", "qualified-headings": "warning", "regex-selectors": "warning", "rules-count": "warning", "shorthand": "warning", "star-property-hack": "warning", "text-indent": "warning", "underscore-property-hack": "warning", "unique-headings": "warning", "universal-selector": "warning", "vendor-prefix": true, "zero-units": "warning"}
准备工作 安装 Sublime Text 包管理工具:http://wbond.net/sublime_packages/package_control
使用 Sublime Text 包管理工具安装 SublimeLinter:https://github.com/SublimeLinter/SublimeLinter
安装 Node.js,建议安装 Windows Installer 版本:http://nodejs.org
参数配置 打开 SublimeLinter 的配置文件,Preferences->Package Settings->SublimeLinter->Settings - User,进行如下配置:
(1)运行模式
"sublimelinter": "save-only", SublimeLinter 的运行模式,总共有四种,含义分别如下:
true - 在用户输入时在后台进行即时校验;false - 只有在初始化的时候才进行校验;"load-save" - 当文件加载和保存的时候进行校验;"save-only" - 当文件被保存的时候进行校验; 推荐设置为 “save-only”,这样只在编写完代码,保存的时候才校验,Sublime Text 运行会更加流畅。
(2)校验引擎
"sublimelinter_executable_map":{ "javascript":"D:/nodejs/node.exe", "css":"D:/nodejs/node.exe"}
这里是配置 JavaScript 和 CSS 校验需要用到的 JS 引擎(这里用的是 Node.js)的安装路径。
(3)JSHint 选项
SublimeLinter 使用 JSHint 作为默认的 JavaScript 校验器,也可以配置为 jslint 和 gjslint(closure linter)。下面我使用的 jshint 校验选项,大家可以根据自己的编码风格自行配置,选项的含义可以参考这里:http://www.jshint.com/docs/#options
"jshint_options":{ "strict": true, "noarg": true, "noempty": true, "eqeqeq": true, "undef": true, "curly": true, "forin": true, "devel": true, "jquery": true, "browser": true, "wsh": true, "evil": true}
(4)CSSLint 选项
SublimeLinter 使用 CSSLint 作为 CSS 的校验器,下面是默认配置的校验选项,可以根据个人编码风格修改:
"csslint_options":{ "adjoining-classes": "warning", "box-model": true, "box-sizing": "warning", "compatible-vendor-prefixes": "warning", "display-property-grouping": true, "duplicate-background-images": "warning", "duplicate-properties": true, "empty-rules": true, "errors": true, "fallback-colors": "warning", "floats": "warning", "font-faces": "warning", "font-sizes": "warning", "gradients": "warning", "ids": "warning", "import": "warning", "important": "warning", "known-properties": true, "outline-none": "warning", "overqualified-elements": "warning", "qualified-headings": "warning", "regex-selectors": "warning", "rules-count": "warning", "shorthand": "warning", "star-property-hack": "warning", "text-indent": "warning", "underscore-property-hack": "warning", "unique-headings": "warning", "universal-selector": "warning", "vendor-prefix": true, "zero-units": "warning"}
【借助SublimeLinter编写高质量的JavaScript & CSS代码】相关文章
1. 借助SublimeLinter编写高质量的JavaScript & CSS代码
2. HTML Inspector:帮助你编写高质量的 HTML 代码
3. Web Inspector:在 Sublime Text 中调试 JavaScript 代码
7. JSHint 2.7.0 发布,JavaScript 代码质量检查
9. 编写高效的CSS选择器
10. JScrambler:保护你的JavaScript代码
本文来源:https://www.51html5.com/a3247.html
﹝借助SublimeLinter编写高质量的JavaScript & CSS代码﹞相关内容
- HTML5中对contenteditable属性的解释与规定
- 编写快速、高效的JavaScript代码
- 基于HTML5的播放器Sublimevideo走免费增值路线
- SonarQube 4.3 发布代码质量管理平台
- RubyJS:用JavaScript实现的Ruby核心库
- 1KB JavaScript代码编写的3D蜜蜂
- 如果让莎士比亚、海明威编写JavaScript代码
- 让网站变灰的css代码(支持IE、Firefox和Chrome)
- 不到30行JS代码实现的Excel表格
- Github项目中使用率最高的Java/Ruby/JS库