在Sublime3中使用ESLint

来源:互联网 发布:江苏微盛网络孙 编辑:程序博客网 时间:2024/04/30 18:46

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 0
原创粉丝点击