● Sublime集成 ESLint 需要两个插件 SublimeLinter 和 SublimeLinter-contrib-eslint ;直接在Package Controll中安装就好
● 局部安装ESLint: npm i eslint –save-dev
● 局部安装eslint-plugin-react: npm i eslint-plugin-react –save-dev
● 局部安装babel-eslint: npm i babel-eslint –save-dev
● 安装后修改SublimeLinter的配置文件,在Package Settings中打开其Setting-User,将下列代码复制进去:
setting-user配置
{
"user": {
"debug": true,
"delay": 0.25,
"error_color": "D02000",
"gutter_theme": "Packages/SublimeLinter/gutter-themes/Default/Default.gutter-theme",
"gutter_theme_excludes": [],
"lint_mode": "load/save",
"linters": {
"eslint": {
"@disable": false,
"args": [],
"excludes": []
},
"eslint_d": {
"@disable": false,
"args": [],
"excludes": []
}
},
"mark_style": "solid underline",
"no_column_highlights_line": false,
"passive_warnings": false,
"paths": {
"linux": [],
"osx": [],
"windows": []//此处不用写目录默认会找到
},
"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 eslint-plugin-react babel-eslint 全局安装
例如:
● 全局安装ESLint: npm i eslint -g
● 全局安装eslint-plugin-react: npm i eslint-plugin-react -g
● 全局安装babel-eslint: npm i babel-eslint -g
并修改paths下的winddows目录修改为全局安装的目录
例如:
"paths": {
"linux": [],
"osx": [],
"windows": [
/*目录根据eslint安装目录自己修改*/
"C:/Users/Administrator/AppData/Roaming/npm/eslint.cmd"
]
},
配置eslint规则,配置出适合自己编程习惯的配置文件:
.eslintrc.json
{
"plugins": [
"react"
],
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
}
},
"parser": "babel-eslint",
"env": {
"es6": true,
"browser": true,
"node": true,
"jquery": true,
"commonjs": true
},
"rules": {
"no-cond-assign": "error",
"no-console": "error",
"no-constant-condition": "error",
"no-debugger": "error",
"no-dupe-args": "error",
"no-dupe-keys": "error",
"no-duplicate-case": "error",
"no-empty-character-class": "error",
"no-empty": "error",
"no-ex-assign": "error",
"no-extra-boolean-cast": "error",
"no-extra-semi": "error",
"no-func-assign": "error",
"no-inner-declarations": "error",
"no-invalid-regexp": "error",
"no-irregular-whitespace": "error",
"no-func-assign": "error",
"no-obj-calls": "error",
"no-regex-spaces": "error",
"no-sparse-arrays": "error",
"no-unexpected-multiline": "error",
"no-unreachable": "error",
"no-unsafe-finally": "error",
"use-isnan": "error",
"valid-typeof": "error",
"accessor-pairs": "error",
"eqeqeq": "error",
"guard-for-in": "error",
"no-alert": "error",
"no-caller": "error",
"no-case-declarations": "error",
"no-else-return": "error",
"no-empty-function": "error",
"no-empty-pattern": "error",
"no-eval": "error",
"no-redeclare": "error",
"radix": "error",
"no-delete-var": "error",
"quotes": ["error", "single"],
"indent": ["error", 4],
"no-lonely-if": "error",
"no-self-assign": "error",
"no-self-assign": "error",
"no-self-assign": "error",
"no-self-assign": "error",
"react/no-array-index-key":"warn",
"react/no-deprecated":"error",
"react/no-find-dom-node":"error",
"react/no-is-mounted":"error",
"react/no-multi-comp":"error",
"react/no-string-refs":"error",
"react/no-unused-prop-types":"error",
"react/prefer-es6-class":"off",
"react/prop-types":"off"
}
}
最后,把配置好的文件放在你项目的根目录中就可以了,项目中所有的子文件也会自动使用该配置文件。