在Sublime3中使用ESLint

Sublime集成 ESLint 需要两个插件 SublimeLinter 和 SublimeLinter-contrib-eslint ;直接在Package Controll中安装就好
安装ESLint: npm i -g eslint
安装后修改SublimeLinter的配置文件,在Package Settings中打开其Setting-User,将下列代码复制进去:

setting-user

{
 "user": {
 "debug": false,
 "delay": 0.25,
 "error_color": "D02000",
 "gutter_theme": "Packages/SublimeLinter/gutter-themes/Default/Default.gutter-theme",
 "gutter_theme_excludes": [],
 "lint_mode": "save only",
 "linters": {
 // 新增的
 "eslint": {
 "@disable": false,
 "args": [],
 "excludes": []
 }
 },
 "mark_style": "outline",
 "no_column_highlights_line": false,
 "passive_warnings": false,
 "paths": {
 "linux": [],
 "osx": [],
 "windows": [
 // 这个是你全局安装eslint后eslint.cmd的所在目录
 "C:/Users/Lin/AppData/Roaming/npm/eslint.cmd"
 ]
 },
 "python_paths": {
 "linux": [],
 "osx": [],
 "windows": []
 },
 "rc_search_limit": 3,
 "shell_timeout": 10,
 "show_errors_on_save": false,
 "show_marks_in_minimap": true,
 "syntax_map": {
 "html (django)": "html",
 "html (rails)": "html",
 "html 5": "html",
 "javascript (babel)": "javascript",
 "magicpython": "python",
 "php": "html",
 "python django": "python"
 },
 "warning_color": "DDB700",
 "wrap_find": true
 }
}

关键的一步,配置eslint,最好把 http://eslint.org/docs/user-guide/configuring 看看,配置出适合自己编程习惯的配置文件再好不过了,我的配置文件内容如下:
.eslintrc.json

{
 "env": {
 "browser": true,
 "es6": true,
 "node": true
 },
 "parserOptions": {
 "sourceType": "module"
 },
 "rules": {
 "no-cond-assign": [2, "always"], //if, while等条件中不允许使用“=”
 "no-constant-condition": 2,
 "no-debugger": 2, // 程序中不能出现debugger
 "no-dupe-args": 2, // 函数的参数名称不能重复
 "no-dupe-keys": 2, // 对象的属性名称不能重复
 "no-duplicate-case": 2, // switch的case不能重复
 "no-func-assign": 2,
 "no-obj-calls": 2,
 "no-regex-spaces": 2,
 "no-sparse-arrays": 2,
 "no-unexpected-multiline": 2,
 "no-unreachable": 2,
 "use-isnan": 2,
 "valid-typeof": 2,
 "eqeqeq": [2, "always"],
 "no-caller": 2,
 "no-eval": 2,
 "no-redeclare": 2,
 "no-undef": 2,
 "no-unused-vars": 1,
 "no-use-before-define": 2,
 "comma-dangle": [1, "never"],
 "no-const-assign": 2,
 "no-dupe-class-members": 2
 }
}

最后,把配置好的文件放在你项目的根目录中就可以了,项目中所有的子文件也会自动使用该配置文件。
这只是入门级的介绍,ESLint还有很多其他的功能,对JSX也支持,想了解的同学不妨自己去官网学习一下。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值