syntastic-react


Ⅰ. 插件描述

React.js JSX support for Syntastic

Ⅱ. 基本信息

创建日期:  2015-02-03
使用用户:  26
Github星:  96
插件作者:  Jonathan Warner

Ⅲ. 安装方法

使用Vundle管理器安装

在你的.vimrc下添加:
Plugin 'jaxbot/syntastic-react'
… 然后在Vim中运行以下命令:
:source %
:PluginInstall

对于Vundle版本 < 0.10.2,请用上面的Bundle替换Plugin。

使用NeoBundle管理器安装

在你的.vimrc下添加:
NeoBundle 'jaxbot/syntastic-react'
… 然后在Vim中运行以下命令:
:source %
:NeoBundleInstall

使用VimPlug管理器安装

在你的.vimrc下添加:
Plug 'jaxbot/syntastic-react'
… 然后在Vim中运行以下命令:
:source %
:PlugInstall

使用Pathogen管理器安装

在终端中运行以下命令:
cd ~/.vim/bundle
git clone https://github.com/jaxbot/syntastic-react

Ⅳ. 文档说明

# Syntastic Checker for React JSX files

New way using ESLint

This project has been deprecated in favor of using ESLint, which supports React, JSX, and new ES6 features, and is in very active development.

To use Syntastic with ESLint:

Install eslint, babel-eslint (for ES6 support), and eslint-plugin-react:

npm install -g eslint
npm install -g babel-eslint
npm install -g eslint-plugin-react

Create a config like this in your project's .eslintrc, or do so globally by placing it in ~/.eslintrc:

{
    "parser": "babel-eslint",
    "env": {
        "browser": true,
        "node": true
    },
    "settings": {
        "ecmascript": 6,
        "jsx": true
    },
    "plugins": [
        "react"
    ],
    "rules": {
        "strict": 0,
        "quotes": 0,
        "no-unused-vars": 0,
        "camelcase": 0,
        "no-underscore-dangle": 0
    }
}

Finally, configure Syntastic to use ESLint:

let g:syntastic_javascript_checkers = ['eslint']

You should be good to go! See this issue for more info.

Using this project and JSHint instead

This is a simple wrapper that:

  • Tries to compile as JSX
  • Checks if the JSX compiler throws errors, and sends them to Syntastic if so
  • Otherwise, passes JS to JSHint and outputs any errors found there

This gives you the power of syntax checking in Vim, without the annoyance of "unexpected regular expression". Awesome.

Syntastic working with JSHint issues

Syntastic working with JSX issues

Usage

npm install -g syntastic-react

If you don't have jshint or react-tools, install those too:

npm install -g jshint
npm install -g react-tools

Add these lines to your vimrc:

let g:syntastic_javascript_checkers = ['jsxhint']
let g:syntastic_javascript_jsxhint_exec = 'jsx-jshint-wrapper'

And, of course, install Syntastic.

More info

This is a part of a blog post on setting up Vim for React development.

Why? What about JSXHint?

JSXHint is being sunsetted and doesn't handle React errors correctly. This code is a simple wrapper that brings the best of both worlds, though this one is designed specifically for use with syntastic, and thus will not run the same way as the previous JSXHint wrapper.

JSON support

If you receive an Unexpected token error when editing JSON files, note that Vim defaults to json being ft=javascript. Two main options exist to remedy this:

  1. Use vim-json and get proper JSON highlighting and filetype support.
  2. Override the filetype manually in your vimrc, something like:
au BufRead,BufNewFile *.json set filetype=json
let g:syntastic_json_checkers=['jsonlint']

(Thanks, sharkinsspatial!)

About me

I'm Jonathan, I work on random Vim plugins, web development, Node.js, Android, and whatever else I feel like. Follow me if you're curious, or just want to make my day!

添加新评论