Sublime text3 jsx支持(react 语法检查)

对这篇博文 Lint Like It’s 2015 进行压缩。

原由:sublime text3 配置jsxhint不成功,然后在SublimeLinter-jsxhint找到

Use ESLint and SublimeLinter-ESLint instead, which gives better errors and has fewer problems with ES6.
JSXHint has been deprecated.

已经是不推荐使用 SublimeLinter-jsxhint,而是改成了 ESLint。

  1. Installing eslint and babel-eslint
    home目录(windows下即为:c:\usrs\用户名 )下新建 .eslintrc(如果是windows可以用 Cygwin 建立) ,这是eslint的配置文件,并添加以下内容:
{
  // I want to use babel-eslint for parsing!
  "parser": "babel-eslint",
  "env": {
    // I write for browser
    "browser": true,
    // in CommonJS
    "node": true
  },
  // To give you an idea how to override rule options:
  "rules": {
    "quotes": [2, "single"],
    "eol-last": [0],
    "no-mixed-requires": [0],
    "no-underscore-dangle": [0]
  }
}

在终端(terminal或是 cmd ,前提安装了node.js)中进行安装:

npm uninstall -g eslint #安装前把以前的eslint删除
npm install -g eslint@latest
npm install -g babel-eslint@latest

耐心等待完成,然后进行验证是否安装成功:

eslint -v

显示版本则为安装成功。

2.配置sublime text3

  • 安装插件 SublimeLinter(eslint的依赖插件)
  • 安装插件 SublimeLinter-contrib-eslint(这里建议把SublimeLinter-jshint 与 **SublimeLinter-jsxhint ** 删除)
  • 安装插件 babel-sublime,并设置打开默认为 “JavaScript (Babel)” , 这里 contrib-eslint 会进行识别
  • syntax_map,即 SublimeLinter Settings — User(如果没有这个文件,可以将defalut下的配置复制到user中)如下:
Sublime text3 jsx支持(react 语法检查)_第1张图片
Paste_Image.png
  • eslint-plugin-react,这个插件可以例ESLint识别 React JSX,在先前的 .eslintrc中添加
"plugins":[
"react"
]
  • (可选)**Choose Lint Mode **command
Sublime text3 jsx支持(react 语法检查)_第2张图片
Paste_Image.png

最终效果: oceanic-next-theme

Sublime text3 jsx支持(react 语法检查)_第3张图片
Paste_Image.png

如果配置完成但是提示,无法加载 eslint ,请配置 set default,设置它的path.

你可能感兴趣的:(Sublime text3 jsx支持(react 语法检查))